summaryrefslogtreecommitdiff
path: root/libgo/go/reflect
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2018-06-06 14:50:16 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2018-06-06 14:50:16 +0000
commit1d6ccc5f2984952ee71b0bea511cffcd5a30725d (patch)
treecffc231c7ade9a8ba7e8070fec2ec552b4775e96 /libgo/go/reflect
parent1336795a5669b19722fdbc256a3bfe801b54eea7 (diff)
reflect: fix StructOf hash and string
Adjust the hash and string fields computed by StructOf to match the values that the compiler computes for a struct type with the same field names and types. This makes the reflect code match the compiler's Type::hash_for_method and Type::reflection methods. Fixes golang/go#25284 Reviewed-on: https://go-review.googlesource.com/116515 From-SVN: r261235
Diffstat (limited to 'libgo/go/reflect')
-rw-r--r--libgo/go/reflect/all_test.go11
-rw-r--r--libgo/go/reflect/type.go4
2 files changed, 13 insertions, 2 deletions
diff --git a/libgo/go/reflect/all_test.go b/libgo/go/reflect/all_test.go
index 3378640e7e9..96b57ef2cda 100644
--- a/libgo/go/reflect/all_test.go
+++ b/libgo/go/reflect/all_test.go
@@ -4411,6 +4411,17 @@ func TestStructOf(t *testing.T) {
})
// check that type already in binary is found
checkSameType(t, StructOf(fields[2:3]), struct{ Y uint64 }{})
+
+ // gccgo used to fail this test.
+ type structFieldType interface{}
+ checkSameType(t,
+ StructOf([]StructField{
+ StructField{
+ Name: "F",
+ Type: TypeOf((*structFieldType)(nil)).Elem(),
+ },
+ }),
+ struct{ F structFieldType }{})
}
func TestStructOfExportRules(t *testing.T) {
diff --git a/libgo/go/reflect/type.go b/libgo/go/reflect/type.go
index 458c45638f8..07fe4d001c0 100644
--- a/libgo/go/reflect/type.go
+++ b/libgo/go/reflect/type.go
@@ -1912,7 +1912,7 @@ func isValidFieldName(fieldName string) bool {
// This limitation may be lifted in a future version.
func StructOf(fields []StructField) Type {
var (
- hash = uint32(0)
+ hash = uint32(12)
size uintptr
typalign int8
comparable = true
@@ -1997,7 +1997,7 @@ func StructOf(fields []StructField) Type {
}
fset[name] = struct{}{}
- repr = append(repr, (" " + ft.String())...)
+ repr = append(repr, (" " + *ft.string)...)
if f.tag != nil {
repr = append(repr, (" " + strconv.Quote(*f.tag))...)
}