compiler: make struct types more unique
There are a lot more fields that are important when comparing structs with each other. Take them into account when building the unique ID per struct type. Example code that differs between the compilers: https://play.golang.org/p/nDX4tSHOf_T
Этот коммит содержится в:
родитель
9979cf2bbd
коммит
f43d01bdc7
3 изменённых файлов: 22 добавлений и 1 удалений
|
@ -161,7 +161,14 @@ func getTypeCodeName(t types.Type) string {
|
|||
panic("cgo unions are not allowed in interfaces")
|
||||
}
|
||||
for i := 0; i < t.NumFields(); i++ {
|
||||
elems[i] = getTypeCodeName(t.Field(i).Type())
|
||||
embedded := ""
|
||||
if t.Field(i).Embedded() {
|
||||
embedded = "#"
|
||||
}
|
||||
elems[i] = embedded + t.Field(i).Name() + ":" + getTypeCodeName(t.Field(i).Type())
|
||||
if t.Tag(i) != "" {
|
||||
elems[i] += "`" + t.Tag(i) + "`"
|
||||
}
|
||||
}
|
||||
return "struct:" + "{" + strings.Join(elems, ",") + "}"
|
||||
default:
|
||||
|
|
12
testdata/interface.go
предоставленный
12
testdata/interface.go
предоставленный
|
@ -11,6 +11,10 @@ func main() {
|
|||
printItf(*thing)
|
||||
printItf(thing)
|
||||
printItf(Stringer(thing))
|
||||
printItf(struct{ n int }{})
|
||||
printItf(struct {
|
||||
n int `foo:"bar"`
|
||||
}{})
|
||||
printItf(Number(3))
|
||||
array := Array([4]uint32{1, 7, 11, 13})
|
||||
printItf(array)
|
||||
|
@ -47,6 +51,14 @@ func printItf(val interface{}) {
|
|||
println("is Thing:", val.String())
|
||||
case *Thing:
|
||||
println("is *Thing:", val.String())
|
||||
case struct{ i int }:
|
||||
println("is struct{i int}")
|
||||
case struct{ n int }:
|
||||
println("is struct{n int}")
|
||||
case struct {
|
||||
n int `foo:"bar"`
|
||||
}:
|
||||
println("is struct{n int `foo:\"bar\"`}")
|
||||
case Foo:
|
||||
println("is Foo:", val)
|
||||
default:
|
||||
|
|
2
testdata/interface.txt
предоставленный
2
testdata/interface.txt
предоставленный
|
@ -7,6 +7,8 @@ is Foo: 18
|
|||
is Thing: foo
|
||||
is *Thing: foo
|
||||
is *Thing: foo
|
||||
is struct{n int}
|
||||
is struct{n int `foo:"bar"`}
|
||||
is Doubler: 6
|
||||
is Tuple: 1 7 11 13
|
||||
Array len: 4
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче