• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// run
2
3// Copyright 2020 The Go Authors. All rights reserved.
4// Use of this source code is governed by a BSD-style
5// license that can be found in the LICENSE file.
6
7// Similar to reflectmethod5.go, but for reflect.Type.MethodByName.
8
9package main
10
11import "reflect"
12
13var called bool
14
15type foo struct{}
16
17func (foo) X() { called = true }
18
19var h = reflect.Type.MethodByName
20
21func main() {
22	v := reflect.ValueOf(foo{})
23	m, ok := h(v.Type(), "X")
24	if !ok {
25		panic("FAIL")
26	}
27	f := m.Func.Interface().(func(foo))
28	f(foo{})
29	if !called {
30		panic("FAIL")
31	}
32}
33