Commit f8614a66 authored by Ian Lance Taylor's avatar Ian Lance Taylor

reflect: fix test of whether structs are identical

The old code worked with gc, I assume because the linker
unified identical strings, but it failed with gccgo.

R=rsc
CC=gobot, golang-dev
https://golang.org/cl/6826063
parent 768ba46c
......@@ -1257,8 +1257,19 @@ func haveIdenticalUnderlyingType(T, V *commonType) bool {
for i := range t.fields {
tf := &t.fields[i]
vf := &v.fields[i]
if tf.name != vf.name || tf.pkgPath != vf.pkgPath ||
tf.typ != vf.typ || tf.tag != vf.tag || tf.offset != vf.offset {
if tf.name != vf.name && (tf.name == nil || vf.name == nil || *tf.name != *vf.name) {
return false
}
if tf.pkgPath != vf.pkgPath && (tf.pkgPath == nil || vf.pkgPath == nil || *tf.pkgPath != *vf.pkgPath) {
return false
}
if tf.typ != vf.typ {
return false
}
if tf.tag != vf.tag && (tf.tag == nil || vf.tag == nil || *tf.tag != *vf.tag) {
return false
}
if tf.offset != vf.offset {
return false
}
}
......
// Copyright 2012 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 p1
type S struct { X, Y int }
// Copyright 2012 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"
"./p1"
)
func main() {
var v1 = p1.S{1, 2}
var v2 = struct { X, Y int }{1, 2}
v1 = v2
t1 := reflect.TypeOf(v1)
t2 := reflect.TypeOf(v2)
if !t1.AssignableTo(t2) {
panic(0)
}
if !t2.AssignableTo(t1) {
panic(1)
}
}
// rundir
// Copyright 2012 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.
// The reflect package was not correctly checking field names
// when checking for struct assignability.
package ignored
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment