From cb7d43b2ea7ddbc80eb74716cb12da3c13971257 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Wed, 27 May 2020 20:46:21 -0700 Subject: [PATCH] cmd/compile/internal/syntax: actually collect type list types (fix bug) The existing code collected empty fields. Collect the actual field and added type string test. (This was not found before because the generic tests are still disabled in this port because of different position information.) Change-Id: I959711892aac3c8f7587a4025c4b32f1598f5df3 Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/756088 Reviewed-by: Robert Griesemer --- src/cmd/compile/internal/syntax/parser.go | 4 ++-- .../compile/internal/types2/testdata/tmp.go2 | 24 +------------------ .../internal/types2/typestring_test.go | 3 +-- 3 files changed, 4 insertions(+), 27 deletions(-) diff --git a/src/cmd/compile/internal/syntax/parser.go b/src/cmd/compile/internal/syntax/parser.go index ee63a751c8..13df653106 100644 --- a/src/cmd/compile/internal/syntax/parser.go +++ b/src/cmd/compile/internal/syntax/parser.go @@ -1370,13 +1370,13 @@ func (p *parser) interfaceType() *InterfaceType { f.pos = p.pos() f.Name = type_ f.Type = p.type_(true) - typ.MethodList = append(typ.MethodList, &Field{}) + typ.MethodList = append(typ.MethodList, f) for p.got(_Comma) { f := new(Field) f.pos = p.pos() f.Name = type_ f.Type = p.type_(true) - typ.MethodList = append(typ.MethodList, &Field{}) + typ.MethodList = append(typ.MethodList, f) } } diff --git a/src/cmd/compile/internal/types2/testdata/tmp.go2 b/src/cmd/compile/internal/types2/testdata/tmp.go2 index 4873be104d..74088705dd 100644 --- a/src/cmd/compile/internal/types2/testdata/tmp.go2 +++ b/src/cmd/compile/internal/types2/testdata/tmp.go2 @@ -1,25 +1,3 @@ package p -type B(type P) interface{} - -func _f(type P B)() {} - -// These are only ok if AcceptContracts = false. -// (The comparable contract cannot be embedded in Bound.) -/* -func _(type T comparable)(x, y T) bool { - return x == y || x != y -} - -type Bound interface { - comparable -} - -func _(type T Bound)(x, y T) bool { - return x == y || x != y -} - -func _(type A, B Bound)(a1, a2 A, b1, b2 B) bool { - return a1 == a2 || b1 != b2 -} -*/ +type T interface{type int} \ No newline at end of file diff --git a/src/cmd/compile/internal/types2/typestring_test.go b/src/cmd/compile/internal/types2/typestring_test.go index 04b05543f7..5514426371 100644 --- a/src/cmd/compile/internal/types2/typestring_test.go +++ b/src/cmd/compile/internal/types2/typestring_test.go @@ -15,7 +15,6 @@ import ( const filename = "" func makePkg(src string) (*Package, error) { - //file, err := parser.ParseFile(fset, filename, src, parser.DeclarationErrors) file, err := parseSrc(filename, src) if err != nil { return nil, err @@ -92,7 +91,7 @@ var independentTestTypes = []testEntry{ dup("interface{}"), dup("interface{m()}"), dup(`interface{String() string; m(int) float32}`), - // dup(`interface{type int, float32, complex128}`), // TODO(gri) fix this + dup(`interface{type int, float32, complex128}`), // maps dup("map[string]int"),