1
0
mirror of https://github.com/golang/go synced 2024-11-19 07:54:43 -07:00

[dev.typeparams] go/types: make predeclared "any" alias for interface{}

This is a direct port of CL 285132 to go/types.

Change-Id: I35486d8ea1fa6c0c6a32ece199a6ccfd55d44d29
Reviewed-on: https://go-review.googlesource.com/c/go/+/291322
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
Rob Findley 2021-02-11 11:50:31 -05:00 committed by Robert Findley
parent 58758e0a21
commit 0f43973b4b
2 changed files with 6 additions and 9 deletions

View File

@ -325,14 +325,14 @@ func TestTypesInfo(t *testing.T) {
{broken + `x5; func _() { var x map[string][...]int; x = map[string][...]int{"": {1,2,3}} }`, `x`, `map[string][-1]int`},
// parameterized functions
{genericPkg + `p0; func f[T any](T); var _ = f(int)`, `f`, `func[T₁ any](T₁)`},
{genericPkg + `p0; func f[T any](T); var _ = f(int)`, `f`, `func[T₁ interface{}](T₁)`},
{genericPkg + `p1; func f[T any](T); var _ = f(int)`, `f(int)`, `func(int)`},
{genericPkg + `p2; func f[T any](T); func _() { f(42) }`, `f`, `func[T₁ any](T₁)`},
{genericPkg + `p2; func f[T any](T); func _() { f(42) }`, `f`, `func[T₁ interface{}](T₁)`},
{genericPkg + `p3; func f[T any](T); func _() { f(42) }`, `f(42)`, `()`},
// type parameters
{genericPkg + `t0; type t[] int; var _ t`, `t`, `generic_t0.t`}, // t[] is a syntax error that is ignored in this test in favor of t
{genericPkg + `t1; type t[P any] int; var _ t[int]`, `t`, `generic_t1.t[P₁ any]`},
{genericPkg + `t1; type t[P any] int; var _ t[int]`, `t`, `generic_t1.t[P₁ interface{}]`},
{genericPkg + `t2; type t[P interface{}] int; var _ t[int]`, `t`, `generic_t2.t[P₁ interface{}]`},
{genericPkg + `t3; type t[P, Q interface{}] int; var _ t[int, int]`, `t`, `generic_t3.t[P₁, Q₂ interface{}]`},

View File

@ -24,7 +24,7 @@ var (
universeIota *Const
universeByte *Basic // uint8 alias, but has name "byte"
universeRune *Basic // int32 alias, but has name "rune"
universeAny *Named
universeAny *Interface
universeError *Named
)
@ -82,10 +82,7 @@ func defPredeclaredTypes() {
// (Predeclared and entered into universe scope so we do all the
// usual checks; but removed again from scope later since it's
// only visible as constraint in a type parameter list.)
{
typ := &Named{underlying: &emptyInterface}
def(NewTypeName(token.NoPos, nil, "any", typ))
}
def(NewTypeName(token.NoPos, nil, "any", &emptyInterface))
// Error has a nil package in its qualified name since it is in no package
{
@ -241,7 +238,7 @@ func init() {
universeIota = Universe.Lookup("iota").(*Const)
universeByte = Universe.Lookup("byte").(*TypeName).typ.(*Basic)
universeRune = Universe.Lookup("rune").(*TypeName).typ.(*Basic)
universeAny = Universe.Lookup("any").(*TypeName).typ.(*Named)
universeAny = Universe.Lookup("any").(*TypeName).typ.(*Interface)
universeError = Universe.Lookup("error").(*TypeName).typ.(*Named)
// "any" is only visible as constraint in a type parameter list