mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[dev.typeparams] cmd/compile/internal/types2: make predeclared "any" alias for interface{}
If we ever decide to permit the use of the predeclared identifier
"any" in lieu of interface{}, it must be an alias for interface{}.
Change-Id: Ic751d7f9b61133fb57625f56ce95d99f034b32c5
Reviewed-on: https://go-review.googlesource.com/c/go/+/285132
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
This commit is contained in:
parent
0f054c5be0
commit
f03f934ede
2 changed files with 7 additions and 10 deletions
|
|
@ -323,14 +323,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
|
||||||
{`package p0; func f[T any](T); var _ = f[int]`, `f`, `func[T₁ any](T₁)`},
|
{`package p0; func f[T any](T); var _ = f[int]`, `f`, `func[T₁ interface{}](T₁)`},
|
||||||
{`package p1; func f[T any](T); var _ = f[int]`, `f[int]`, `func(int)`},
|
{`package p1; func f[T any](T); var _ = f[int]`, `f[int]`, `func(int)`},
|
||||||
{`package p2; func f[T any](T); func _() { f(42) }`, `f`, `func[T₁ any](T₁)`},
|
{`package p2; func f[T any](T); func _() { f(42) }`, `f`, `func[T₁ interface{}](T₁)`},
|
||||||
{`package p3; func f[T any](T); func _() { f(42) }`, `f(42)`, `()`},
|
{`package p3; func f[T any](T); func _() { f(42) }`, `f(42)`, `()`},
|
||||||
|
|
||||||
// type parameters
|
// type parameters
|
||||||
{`package t0; type t[] int; var _ t`, `t`, `t0.t`}, // t[] is a syntax error that is ignored in this test in favor of t
|
{`package t0; type t[] int; var _ t`, `t`, `t0.t`}, // t[] is a syntax error that is ignored in this test in favor of t
|
||||||
{`package t1; type t[P any] int; var _ t[int]`, `t`, `t1.t[P₁ any]`},
|
{`package t1; type t[P any] int; var _ t[int]`, `t`, `t1.t[P₁ interface{}]`},
|
||||||
{`package t2; type t[P interface{}] int; var _ t[int]`, `t`, `t2.t[P₁ interface{}]`},
|
{`package t2; type t[P interface{}] int; var _ t[int]`, `t`, `t2.t[P₁ interface{}]`},
|
||||||
{`package t3; type t[P, Q interface{}] int; var _ t[int, int]`, `t`, `t3.t[P₁, Q₂ interface{}]`},
|
{`package t3; type t[P, Q interface{}] int; var _ t[int, int]`, `t`, `t3.t[P₁, Q₂ interface{}]`},
|
||||||
{broken + `t4; type t[P, Q interface{ m() }] int; var _ t[int, int]`, `t`, `broken_t4.t[P₁, Q₂ interface{m()}]`},
|
{broken + `t4; type t[P, Q interface{ m() }] int; var _ t[int, int]`, `t`, `broken_t4.t[P₁, Q₂ interface{m()}]`},
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -34,7 +34,7 @@ var (
|
||||||
// The *Basic type for Typ[Byte] will have the name "uint8".
|
// The *Basic type for Typ[Byte] will have the name "uint8".
|
||||||
// Use Universe.Lookup("byte").Type() to obtain the specific
|
// Use Universe.Lookup("byte").Type() to obtain the specific
|
||||||
// alias basic type named "byte" (and analogous for "rune").
|
// alias basic type named "byte" (and analogous for "rune").
|
||||||
var Typ = []*Basic{
|
var Typ = [...]*Basic{
|
||||||
Invalid: {Invalid, 0, "invalid type", aType{}},
|
Invalid: {Invalid, 0, "invalid type", aType{}},
|
||||||
|
|
||||||
Bool: {Bool, IsBoolean, "bool", aType{}},
|
Bool: {Bool, IsBoolean, "bool", aType{}},
|
||||||
|
|
@ -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(nopos, nil, "any", &emptyInterface))
|
||||||
typ := &Named{underlying: &emptyInterface}
|
|
||||||
def(NewTypeName(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…
Add table
Add a link
Reference in a new issue