mirror of https://github.com/golang/go.git
cmd/compile/internal/types2: fix TypeName.IsAlias for type parameter names
This is a port of CL 359656 from go/types to types2. For #49213. Change-Id: Ib98f9a344c1397af92e061cafd519ea374fd60bc Reviewed-on: https://go-review.googlesource.com/c/go/+/360294 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
parent
e2e910ef30
commit
0ae4c7ff4a
|
|
@ -315,6 +315,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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,8 @@ func TestIsAlias(t *testing.T) {
|
|||
pkg := NewPackage("p", "p")
|
||||
t1 := NewTypeName(nopos, pkg, "t1", nil)
|
||||
n1 := NewNamed(t1, new(Struct), nil)
|
||||
t5 := NewTypeName(nopos, pkg, "t5", nil)
|
||||
NewTypeParam(t5, nil)
|
||||
for _, test := range []struct {
|
||||
name *TypeName
|
||||
alias bool
|
||||
|
|
@ -46,6 +48,7 @@ func TestIsAlias(t *testing.T) {
|
|||
{NewTypeName(nopos, nil, "int32", Typ[Int32]), false}, // type name refers to basic type with same name
|
||||
{NewTypeName(nopos, pkg, "int32", Typ[Int32]), true}, // type name is declared in user-defined package (outside Universe)
|
||||
{NewTypeName(nopos, 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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
package issue45985
|
||||
|
||||
// TODO(gri): 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)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue