mirror of
https://github.com/golang/go
synced 2024-11-19 06:54:39 -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:
parent
58758e0a21
commit
0f43973b4b
@ -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`},
|
{broken + `x5; func _() { var x map[string][...]int; x = map[string][...]int{"": {1,2,3}} }`, `x`, `map[string][-1]int`},
|
||||||
|
|
||||||
// parameterized functions
|
// 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 + `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)`, `()`},
|
{genericPkg + `p3; func f[T any](T); func _() { f(42) }`, `f(42)`, `()`},
|
||||||
|
|
||||||
// type parameters
|
// 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 + `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 + `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{}]`},
|
{genericPkg + `t3; type t[P, Q interface{}] int; var _ t[int, int]`, `t`, `generic_t3.t[P₁, Q₂ interface{}]`},
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ var (
|
|||||||
universeIota *Const
|
universeIota *Const
|
||||||
universeByte *Basic // uint8 alias, but has name "byte"
|
universeByte *Basic // uint8 alias, but has name "byte"
|
||||||
universeRune *Basic // int32 alias, but has name "rune"
|
universeRune *Basic // int32 alias, but has name "rune"
|
||||||
universeAny *Named
|
universeAny *Interface
|
||||||
universeError *Named
|
universeError *Named
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -82,10 +82,7 @@ func defPredeclaredTypes() {
|
|||||||
// (Predeclared and entered into universe scope so we do all the
|
// (Predeclared and entered into universe scope so we do all the
|
||||||
// usual checks; but removed again from scope later since it's
|
// usual checks; but removed again from scope later since it's
|
||||||
// only visible as constraint in a type parameter list.)
|
// only visible as constraint in a type parameter list.)
|
||||||
{
|
def(NewTypeName(token.NoPos, nil, "any", &emptyInterface))
|
||||||
typ := &Named{underlying: &emptyInterface}
|
|
||||||
def(NewTypeName(token.NoPos, nil, "any", typ))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Error has a nil package in its qualified name since it is in no package
|
// 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)
|
universeIota = Universe.Lookup("iota").(*Const)
|
||||||
universeByte = Universe.Lookup("byte").(*TypeName).typ.(*Basic)
|
universeByte = Universe.Lookup("byte").(*TypeName).typ.(*Basic)
|
||||||
universeRune = Universe.Lookup("rune").(*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)
|
universeError = Universe.Lookup("error").(*TypeName).typ.(*Named)
|
||||||
|
|
||||||
// "any" is only visible as constraint in a type parameter list
|
// "any" is only visible as constraint in a type parameter list
|
||||||
|
Loading…
Reference in New Issue
Block a user