From: zhouguangyuan Date: Fri, 29 Oct 2021 07:24:28 +0000 (+0800) Subject: go/types: fix TypeName.IsAlias for type parameter names X-Git-Tag: go1.18beta1~643 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=80bedb848092c993182f79a946d54776dc251549;p=gostls13.git go/types: fix TypeName.IsAlias for type parameter names Fixes #49213 Change-Id: I2bfc151b74b0d14efbd00e5d28584f4180126c5d Reviewed-on: https://go-review.googlesource.com/c/go/+/359656 Trust: Robert Griesemer Trust: Robert Findley Run-TryBot: Robert Griesemer Reviewed-by: Robert Griesemer TryBot-Result: Go Bot --- diff --git a/src/go/types/object.go b/src/go/types/object.go index 18015fc967..a8bd62a04e 100644 --- a/src/go/types/object.go +++ b/src/go/types/object.go @@ -269,6 +269,8 @@ func (obj *TypeName) IsAlias() bool { return obj.pkg != nil || t.name != obj.name || t == universeByte || t == universeRune case *Named: return obj != t.obj + case *TypeParam: + return obj != t.obj default: return true } diff --git a/src/go/types/object_test.go b/src/go/types/object_test.go index 0ff8fdd6fa..c12af64df7 100644 --- a/src/go/types/object_test.go +++ b/src/go/types/object_test.go @@ -30,6 +30,8 @@ func TestIsAlias(t *testing.T) { pkg := NewPackage("p", "p") t1 := NewTypeName(0, pkg, "t1", nil) n1 := NewNamed(t1, new(Struct), nil) + t5 := NewTypeName(0, pkg, "t5", nil) + NewTypeParam(t5, nil) for _, test := range []struct { name *TypeName alias bool @@ -43,6 +45,7 @@ func TestIsAlias(t *testing.T) { {NewTypeName(0, nil, "int32", Typ[Int32]), false}, // type name refers to basic type with same name {NewTypeName(0, pkg, "int32", Typ[Int32]), true}, // type name is declared in user-defined package (outside Universe) {NewTypeName(0, nil, "rune", Typ[Rune]), true}, // type name refers to basic type rune which is an alias already + {t5, false}, // type name refers to type parameter and vice versa } { check(test.name, test.alias) } diff --git a/src/go/types/testdata/fixedbugs/issue45985.go2 b/src/go/types/testdata/fixedbugs/issue45985.go2 index 6e42dbb633..07395911cd 100644 --- a/src/go/types/testdata/fixedbugs/issue45985.go2 +++ b/src/go/types/testdata/fixedbugs/issue45985.go2 @@ -5,7 +5,7 @@ package issue45985 // TODO(rFindley): this error should be on app[int] below. -func app[S /* ERROR "type S = S does not match" */ interface{ ~[]T }, T any](s S, e T) S { +func app[S /* ERROR "type S S does not match" */ interface{ ~[]T }, T any](s S, e T) S { return append(s, e) }