mirror of
https://github.com/golang/go
synced 2024-11-18 15:04:44 -07:00
cabf622da8
The existing code used Type.String() to obtain the name of a type; specifically type reflect.Method in this case. However, Type.String() formatting is intended for error messages and uses the format pkgpath.name instead of pkgname.name if a package (in this case package reflect) is imported multiple times. As a result, the reflect.Method type detection failed under peculiar circumstances (see the included test case). Thanks to https://github.com/ericlagergren for tracking down an easy way to make the bug disappear (which in turn directly led to the underlying cause). Fixes #19028. Change-Id: I1b9c5dfd183260a9be74969fe916a94146fc36da Reviewed-on: https://go-review.googlesource.com/45777 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
27 lines
575 B
Go
27 lines
575 B
Go
// 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
|
|
}
|
|
}
|