return false
}
-// usemethod check interface method calls for uses of reflect.Type.Method.
+// usemethod checks interface method calls for uses of reflect.Type.Method.
func usemethod(n *Node) {
t := n.Left.Type
return
}
}
- if res0.Type.String() != "reflect.Method" {
- return
- }
- Curfn.Func.SetReflectMethod(true)
+ // Note: Don't rely on res0.Type.String() since its formatting depends on multiple factors
+ // (including global variables such as numImports - was issue #19028).
+ if s := res0.Type.Sym; s != nil && s.Name == "Method" && s.Pkg != nil && s.Pkg.Path == "reflect" {
+ Curfn.Func.SetReflectMethod(true)
+ }
}
func usefield(n *Node) {
--- /dev/null
+// Copyright 2017 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package reflect
+
+import "reflect"
+
+type Type reflect.Type
--- /dev/null
+// Copyright 2017 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+import (
+ "reflect"
+ fake "./reflect" // 2nd package with name "reflect"
+)
+
+type T struct {
+ _ fake.Type
+}
+
+func (T) f() {}
+func (T) G() (_ int) { return }
+func (T) H() (_, _ int) { return }
+
+func main() {
+ var x T
+ typ := reflect.TypeOf(x)
+ for i := 0; i < typ.NumMethod(); i++ {
+ _ = typ.Method(i) // must not crash
+ }
+}
--- /dev/null
+// rundir
+
+// Copyright 2017 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// This test failed when the compiler didn't use the
+// correct code to identify the type reflect.Method.
+// The failing code relied on Type.String() which had
+// formatting that depended on whether a package (in
+// this case "reflect") was imported more than once.
+
+package ignored