}
func (g *irgen) compLit(typ types2.Type, lit *syntax.CompositeLit) ir.Node {
- if ptr, ok := types2.StructuralType(typ).(*types2.Pointer); ok {
+ if ptr, ok := types2.CoreType(typ).(*types2.Pointer); ok {
n := ir.NewAddrExpr(g.pos(lit), g.compLit(ptr.Elem(), lit))
n.SetOp(ir.OPTRLIT)
return typed(g.typ(typ), n)
}
- _, isStruct := types2.StructuralType(typ).(*types2.Struct)
+ _, isStruct := types2.CoreType(typ).(*types2.Struct)
exprs := make([]ir.Node, len(lit.ElemList))
for i, elem := range lit.ElemList {
w.typ(tv.Type)
typ := tv.Type
- if ptr, ok := types2.StructuralType(typ).(*types2.Pointer); ok {
+ if ptr, ok := types2.CoreType(typ).(*types2.Pointer); ok {
typ = ptr.Elem()
}
- str, isStruct := types2.StructuralType(typ).(*types2.Struct)
+ str, isStruct := types2.CoreType(typ).(*types2.Struct)
w.len(len(lit.ElemList))
for i, elem := range lit.ElemList {
// of S and the respective parameter passing rules apply."
S := x.typ
var T Type
- if s, _ := structuralType(S).(*Slice); s != nil {
+ if s, _ := coreType(S).(*Slice); s != nil {
T = s.elem
} else {
var cause string
case x.isNil():
cause = "have untyped nil"
case isTypeParam(S):
- if u := structuralType(S); u != nil {
- cause = check.sprintf("%s has structural type %s", x, u)
+ if u := coreType(S); u != nil {
+ cause = check.sprintf("%s has core type %s", x, u)
} else {
- cause = check.sprintf("%s has no structural type", x)
+ cause = check.sprintf("%s has no core type", x)
}
default:
cause = check.sprintf("have %s", x)
if x.mode == invalid {
return
}
- if t := structuralString(x.typ); t != nil && isString(t) {
+ if t := coreString(x.typ); t != nil && isString(t) {
if check.Types != nil {
sig := makeSig(S, S, x.typ)
sig.variadic = true
case _Copy:
// copy(x, y []T) int
- dst, _ := structuralType(x.typ).(*Slice)
+ dst, _ := coreType(x.typ).(*Slice)
var y operand
arg(&y, 1)
if y.mode == invalid {
return
}
- src0 := structuralString(y.typ)
+ src0 := coreString(y.typ)
if src0 != nil && isString(src0) {
src0 = NewSlice(universeByte)
}
}
var min int // minimum number of arguments
- switch structuralType(T).(type) {
+ switch coreType(T).(type) {
case *Slice:
min = 2
case *Map, *Chan:
min = 1
case nil:
- check.errorf(arg0, invalidArg+"cannot make %s: no structural type", arg0)
+ check.errorf(arg0, invalidArg+"cannot make %s: no core type", arg0)
return
default:
check.errorf(arg0, invalidArg+"cannot make %s; type must be slice, map, or channel", arg0)
cgocall := x.mode == cgofunc
// a type parameter may be "called" if all types have the same signature
- sig, _ := structuralType(x.typ).(*Signature)
+ sig, _ := coreType(x.typ).(*Signature)
if sig == nil {
check.errorf(x, invalidOp+"cannot call non-function %s", x)
x.mode = invalid
return u
}
-// If typ is a type parameter, structuralType returns the single underlying
+// If typ is a type parameter, CoreType returns the single underlying
// type of all types in the corresponding type constraint if it exists, or
// nil otherwise. If the type set contains only unrestricted and restricted
// channel types (with identical element types), the single underlying type
// is the restricted channel type if the restrictions are always the same.
-// If typ is not a type parameter, structuralType returns the underlying type.
-func StructuralType(t Type) Type {
- return structuralType(t)
+// If typ is not a type parameter, CoreType returns the underlying type.
+func CoreType(t Type) Type {
+ return coreType(t)
}
return
case syntax.Recv:
- u := structuralType(x.typ)
+ u := coreType(x.typ)
if u == nil {
- check.errorf(x, invalidOp+"cannot receive from %s: no structural type", x)
+ check.errorf(x, invalidOp+"cannot receive from %s: no core type", x)
x.mode = invalid
return
}
case hint != nil:
// no composite literal type present - use hint (element type of enclosing type)
typ = hint
- base, _ = deref(structuralType(typ)) // *T implies &T{}
+ base, _ = deref(coreType(typ)) // *T implies &T{}
default:
// TODO(gri) provide better error messages depending on context
goto Error
}
- switch utyp := structuralType(base).(type) {
+ switch utyp := coreType(base).(type) {
case *Struct:
// Prevent crash if the struct referred to is not yet set up.
// See analogous comment for *Array.
valid := false
length := int64(-1) // valid if >= 0
- switch u := structuralString(x.typ).(type) {
+ switch u := coreString(x.typ).(type) {
case nil:
- check.errorf(x, invalidOp+"cannot slice %s: %s has no structural type", x, x.typ)
+ check.errorf(x, invalidOp+"cannot slice %s: %s has no core type", x, x.typ)
x.mode = invalid
return
}
}
- // If a constraint has a structural type, unify the corresponding type parameter with it.
+ // If a constraint has a core type, unify the corresponding type parameter with it.
for _, tpar := range tparams {
- sbound := structuralType(tpar)
+ sbound := coreType(tpar)
if sbound != nil {
- // If the structural type is the underlying type of a single
+ // If the core type is the underlying type of a single
// defined type in the constraint, use that defined type instead.
if named, _ := tpar.singleType().(*Named); named != nil {
sbound = named
}
// u.x.types() now contains the incoming type arguments plus any additional type
- // arguments which were inferred from structural types. The newly inferred non-
+ // arguments which were inferred from core types. The newly inferred non-
// nil entries may still contain references to other type parameters.
// For instance, for [A any, B interface{ []C }, C interface{ *A }], if A == int
// was given, unification produced the type list [int, []C, *A]. We eliminate the
}
// Once nothing changes anymore, we may still have type parameters left;
- // e.g., a structural constraint *P may match a type parameter Q but we
- // don't have any type arguments to fill in for *P or Q (issue #45548).
+ // e.g., a constraint with core type *P may match a type parameter Q but
+ // we don't have any type arguments to fill in for *P or Q (issue #45548).
// Don't let such inferences escape, instead nil them out.
for i, typ := range types {
if typ != nil && isParameterized(tparams, typ) {
obj, index, indirect = lookupFieldOrMethod(T, addressable, pkg, name, false)
- // If we didn't find anything and if we have a type parameter with a structural constraint,
- // see if there is a matching field (but not a method, those need to be declared explicitly
- // in the constraint). If the structural constraint is a named pointer type (see above), we
- // are ok here because only fields are accepted as results.
+ // If we didn't find anything and if we have a type parameter with a core type,
+ // see if there is a matching field (but not a method, those need to be declared
+ // explicitly in the constraint). If the constraint is a named pointer type (see
+ // above), we are ok here because only fields are accepted as results.
if obj == nil && isTypeParam(T) {
- if t := structuralType(T); t != nil {
+ if t := coreType(T); t != nil {
obj, index, indirect = lookupFieldOrMethod(t, addressable, pkg, name, false)
if _, ok := obj.(*Var); !ok {
obj, index, indirect = nil, nil, false // accept fields (variables) only
// The allX predicates below report whether t is an X.
// If t is a type parameter the result is true if isX is true
// for all specified types of the type parameter's type set.
-// allX is an optimized version of isX(structuralType(t)) (which
+// allX is an optimized version of isX(coreType(t)) (which
// is the same as underIs(t, isX)).
func allBoolean(t Type) bool { return allBasic(t, IsBoolean) }
// allBasic reports whether under(t) is a basic type with the specified info.
// If t is a type parameter, the result is true if isBasic(t, info) is true
// for all specific types of the type parameter's type set.
-// allBasic(t, info) is an optimized version of isBasic(structuralType(t), info).
+// allBasic(t, info) is an optimized version of isBasic(coreType(t), info).
func allBasic(t Type, info BasicInfo) bool {
if tpar, _ := t.(*TypeParam); tpar != nil {
return tpar.is(func(t *term) bool { return t != nil && isBasic(t.typ, info) })
if ch.mode == invalid || val.mode == invalid {
return
}
- u := structuralType(ch.typ)
+ u := coreType(ch.typ)
if u == nil {
- check.errorf(s, invalidOp+"cannot send to %s: no structural type", &ch)
+ check.errorf(s, invalidOp+"cannot send to %s: no core type", &ch)
return
}
uch, _ := u.(*Chan)
// determine key/value types
var key, val Type
if x.mode != invalid {
- // Ranging over a type parameter is permitted if it has a structural type.
+ // Ranging over a type parameter is permitted if it has a core type.
var cause string
- u := structuralType(x.typ)
+ u := coreType(x.typ)
if t, _ := u.(*Chan); t != nil {
if sValue != nil {
check.softErrorf(sValue, "range over %s permits only one iteration variable", &x)
// ok to continue
}
if u == nil {
- cause = check.sprintf("%s has no structural type", x.typ)
+ cause = check.sprintf("%s has no core type", x.typ)
}
}
key, val = rangeKeyVal(u)
_ = make /* ERROR expects 2 or 3 arguments */ (S1)
_ = make(S1, 10, 20)
_ = make /* ERROR expects 2 or 3 arguments */ (S1, 10, 20, 30)
- _ = make(S2 /* ERROR cannot make S2: no structural type */ , 10)
+ _ = make(S2 /* ERROR cannot make S2: no core type */ , 10)
type M0 map[string]int
_ = make(map[string]int)
_ = make(M1)
_ = make(M1, 10)
_ = make/* ERROR expects 1 or 2 arguments */(M1, 10, 20)
- _ = make(M2 /* ERROR cannot make M2: no structural type */ )
+ _ = make(M2 /* ERROR cannot make M2: no core type */ )
type C0 chan int
_ = make(chan int)
_ = make(C1)
_ = make(C1, 10)
_ = make/* ERROR expects 1 or 2 arguments */(C1, 10, 20)
- _ = make(C2 /* ERROR cannot make C2: no structural type */ )
+ _ = make(C2 /* ERROR cannot make C2: no core type */ )
_ = make(C3)
}
type myByte1 []byte
type myByte2 []byte
func _[T interface{ []byte | myByte1 | myByte2 }] (x T, i, j, k int) { var _ T = x[i:j:k] }
-func _[T interface{ []byte | myByte1 | []int }] (x T, i, j, k int) { var _ T = x[ /* ERROR no structural type */ i:j:k] }
+func _[T interface{ []byte | myByte1 | []int }] (x T, i, j, k int) { var _ T = x[ /* ERROR no core type */ i:j:k] }
func _[T interface{ []byte | myByte1 | myByte2 | string }] (x T, i, j, k int) { var _ T = x[i:j] }
func _[T interface{ []byte | myByte1 | myByte2 | string }] (x T, i, j, k int) { var _ T = x[i:j:k /* ERROR 3-index slice of string */ ] }
-func _[T interface{ []byte | myByte1 | []int | string }] (x T, i, j, k int) { var _ T = x[ /* ERROR no structural type */ i:j] }
+func _[T interface{ []byte | myByte1 | []int | string }] (x T, i, j, k int) { var _ T = x[ /* ERROR no core type */ i:j] }
// len/cap built-ins
for _, _ = range s1 {}
var s2 S2
- for range s2 /* ERROR cannot range over s2.*no structural type */ {}
+ for range s2 /* ERROR cannot range over s2.*no core type */ {}
var a0 []int
for range a0 {}
for _, _ = range a1 {}
var a2 A2
- for range a2 /* ERROR cannot range over a2.*no structural type */ {}
+ for range a2 /* ERROR cannot range over a2.*no core type */ {}
var p0 *[10]int
for range p0 {}
for _, _ = range p1 {}
var p2 P2
- for range p2 /* ERROR cannot range over p2.*no structural type */ {}
+ for range p2 /* ERROR cannot range over p2.*no core type */ {}
var m0 map[string]int
for range m0 {}
for _, _ = range m1 {}
var m2 M2
- for range m2 /* ERROR cannot range over m2.*no structural type */ {}
+ for range m2 /* ERROR cannot range over m2.*no core type */ {}
}
// type inference checks
// from the first one through constraint type inference.
related3[int]()
- // The inferred type is the structural type of the Slice
+ // The inferred type is the core type of the Slice
// type parameter.
var _ []int = related3[int]()
// It is possible to create composite literals of type parameter
// type as long as it's possible to create a composite literal
-// of the structural type of the type parameter's constraint.
+// of the core type of the type parameter's constraint.
func _[P interface{ ~[]int }]() P {
return P{}
return P{1, 2, 3}
}
// This is a degenerate case with a singleton type set, but we can create
-// composite literals even if the structural type is a defined type.
+// composite literals even if the core type is a defined type.
type MyInts []int
func _[P MyInts]() P {
type C5[T any] interface{ ~chan T | <-chan T }
func _[T any](ch T) {
- <-ch // ERROR cannot receive from ch .* no structural type
+ <-ch // ERROR cannot receive from ch .* no core type
}
func _[T C0](ch T) {
}
func _[T C3](ch T) {
- <-ch // ERROR cannot receive from ch .* no structural type
+ <-ch // ERROR cannot receive from ch .* no core type
}
func _[T C4](ch T) {
type C5[T any] interface{ ~chan T | chan<- T }
func _[T any](ch T) {
- ch /* ERROR cannot send to ch .* no structural type */ <- 0
+ ch /* ERROR cannot send to ch .* no core type */ <- 0
}
func _[T C0](ch T) {
}
func _[T C3](ch T) {
- ch /* ERROR cannot send to ch .* no structural type */ <- 0
+ ch /* ERROR cannot send to ch .* no core type */ <- 0
}
func _[T C4](ch T) {
func _[P1 any, P2 ~byte](s1 P1, s2 P2) {
_ = append(nil /* ERROR first argument to append must be a slice; have untyped nil */ , 0)
- _ = append(s1 /* ERROR s1 .* has no structural type */ , 0)
- _ = append(s2 /* ERROR s2 .* has structural type byte */ , 0)
+ _ = append(s1 /* ERROR s1 .* has no core type */ , 0)
+ _ = append(s2 /* ERROR s2 .* has core type byte */ , 0)
}
var _ = f2[Sfm]
-// special case: structural type is a named pointer type
+// special case: core type is a named pointer type
type PSfm *Sfm
return t.Underlying()
}
-// If t is not a type parameter, structuralType returns the underlying type.
-// If t is a type parameter, structuralType returns the single underlying
+// If t is not a type parameter, coreType returns the underlying type.
+// If t is a type parameter, coreType returns the single underlying
// type of all types in its type set if it exists, or nil otherwise. If the
// type set contains only unrestricted and restricted channel types (with
// identical element types), the single underlying type is the restricted
// channel type if the restrictions are always the same, or nil otherwise.
-func structuralType(t Type) Type {
+func coreType(t Type) Type {
tpar, _ := t.(*TypeParam)
if tpar == nil {
return under(t)
return nil
}
-// structuralString is like structuralType but also considers []byte
+// coreString is like coreType but also considers []byte
// and strings as identical. In this case, if successful and we saw
// a string, the result is of type (possibly untyped) string.
-func structuralString(t Type) Type {
+func coreString(t Type) Type {
tpar, _ := t.(*TypeParam)
if tpar == nil {
return under(t) // string or untyped string
// of S and the respective parameter passing rules apply."
S := x.typ
var T Type
- if s, _ := structuralType(S).(*Slice); s != nil {
+ if s, _ := coreType(S).(*Slice); s != nil {
T = s.elem
} else {
var cause string
case x.isNil():
cause = "have untyped nil"
case isTypeParam(S):
- if u := structuralType(S); u != nil {
- cause = check.sprintf("%s has structural type %s", x, u)
+ if u := coreType(S); u != nil {
+ cause = check.sprintf("%s has core type %s", x, u)
} else {
- cause = check.sprintf("%s has no structural type", x)
+ cause = check.sprintf("%s has no core type", x)
}
default:
cause = check.sprintf("have %s", x)
if x.mode == invalid {
return
}
- if t := structuralString(x.typ); t != nil && isString(t) {
+ if t := coreString(x.typ); t != nil && isString(t) {
if check.Types != nil {
sig := makeSig(S, S, x.typ)
sig.variadic = true
case _Copy:
// copy(x, y []T) int
- dst, _ := structuralType(x.typ).(*Slice)
+ dst, _ := coreType(x.typ).(*Slice)
var y operand
arg(&y, 1)
if y.mode == invalid {
return
}
- src0 := structuralString(y.typ)
+ src0 := coreString(y.typ)
if src0 != nil && isString(src0) {
src0 = NewSlice(universeByte)
}
}
var min int // minimum number of arguments
- switch structuralType(T).(type) {
+ switch coreType(T).(type) {
case *Slice:
min = 2
case *Map, *Chan:
min = 1
case nil:
- check.errorf(arg0, _InvalidMake, "cannot make %s: no structural type", arg0)
+ check.errorf(arg0, _InvalidMake, "cannot make %s: no core type", arg0)
return
default:
check.invalidArg(arg0, _InvalidMake, "cannot make %s; type must be slice, map, or channel", arg0)
cgocall := x.mode == cgofunc
// a type parameter may be "called" if all types have the same signature
- sig, _ := structuralType(x.typ).(*Signature)
+ sig, _ := coreType(x.typ).(*Signature)
if sig == nil {
check.invalidOp(x, _InvalidCall, "cannot call non-function %s", x)
x.mode = invalid
return
case token.ARROW:
- u := structuralType(x.typ)
+ u := coreType(x.typ)
if u == nil {
- check.invalidOp(x, _InvalidReceive, "cannot receive from %s: no structural type", x)
+ check.invalidOp(x, _InvalidReceive, "cannot receive from %s: no core type", x)
x.mode = invalid
return
}
case hint != nil:
// no composite literal type present - use hint (element type of enclosing type)
typ = hint
- base, _ = deref(structuralType(typ)) // *T implies &T{}
+ base, _ = deref(coreType(typ)) // *T implies &T{}
default:
// TODO(gri) provide better error messages depending on context
goto Error
}
- switch utyp := structuralType(base).(type) {
+ switch utyp := coreType(base).(type) {
case *Struct:
// Prevent crash if the struct referred to is not yet set up.
// See analogous comment for *Array.
valid := false
length := int64(-1) // valid if >= 0
- switch u := structuralString(x.typ).(type) {
+ switch u := coreString(x.typ).(type) {
case nil:
- check.invalidOp(x, _NonSliceableOperand, "cannot slice %s: %s has no structural type", x, x.typ)
+ check.invalidOp(x, _NonSliceableOperand, "cannot slice %s: %s has no core type", x, x.typ)
x.mode = invalid
return
}
}
- // If a constraint has a structural type, unify the corresponding type parameter with it.
+ // If a constraint has a core type, unify the corresponding type parameter with it.
for _, tpar := range tparams {
- sbound := structuralType(tpar)
+ sbound := coreType(tpar)
if sbound != nil {
- // If the structural type is the underlying type of a single
+ // If the core type is the underlying type of a single
// defined type in the constraint, use that defined type instead.
if named, _ := tpar.singleType().(*Named); named != nil {
sbound = named
}
// u.x.types() now contains the incoming type arguments plus any additional type
- // arguments which were inferred from structural types. The newly inferred non-
+ // arguments which were inferred from core types. The newly inferred non-
// nil entries may still contain references to other type parameters.
// For instance, for [A any, B interface{ []C }, C interface{ *A }], if A == int
// was given, unification produced the type list [int, []C, *A]. We eliminate the
}
// Once nothing changes anymore, we may still have type parameters left;
- // e.g., a structural constraint *P may match a type parameter Q but we
- // don't have any type arguments to fill in for *P or Q (issue #45548).
+ // e.g., a constraint with core type *P may match a type parameter Q but
+ // we don't have any type arguments to fill in for *P or Q (issue #45548).
// Don't let such inferences escape, instead nil them out.
for i, typ := range types {
if typ != nil && isParameterized(tparams, typ) {
obj, index, indirect = lookupFieldOrMethod(T, addressable, pkg, name, false)
- // If we didn't find anything and if we have a type parameter with a structural constraint,
- // see if there is a matching field (but not a method, those need to be declared explicitly
- // in the constraint). If the structural constraint is a named pointer type (see above), we
- // are ok here because only fields are accepted as results.
+ // If we didn't find anything and if we have a type parameter with a core type,
+ // see if there is a matching field (but not a method, those need to be declared
+ // explicitly in the constraint). If the constraint is a named pointer type (see
+ // above), we are ok here because only fields are accepted as results.
if obj == nil && isTypeParam(T) {
- if t := structuralType(T); t != nil {
+ if t := coreType(T); t != nil {
obj, index, indirect = lookupFieldOrMethod(t, addressable, pkg, name, false)
if _, ok := obj.(*Var); !ok {
obj, index, indirect = nil, nil, false // accept fields (variables) only
// The allX predicates below report whether t is an X.
// If t is a type parameter the result is true if isX is true
// for all specified types of the type parameter's type set.
-// allX is an optimized version of isX(structuralType(t)) (which
+// allX is an optimized version of isX(coreType(t)) (which
// is the same as underIs(t, isX)).
func allBoolean(typ Type) bool { return allBasic(typ, IsBoolean) }
// allBasic reports whether under(t) is a basic type with the specified info.
// If t is a type parameter, the result is true if isBasic(t, info) is true
// for all specific types of the type parameter's type set.
-// allBasic(t, info) is an optimized version of isBasic(structuralType(t), info).
+// allBasic(t, info) is an optimized version of isBasic(coreType(t), info).
func allBasic(t Type, info BasicInfo) bool {
if tpar, _ := t.(*TypeParam); tpar != nil {
return tpar.is(func(t *term) bool { return t != nil && isBasic(t.typ, info) })
if ch.mode == invalid || val.mode == invalid {
return
}
- u := structuralType(ch.typ)
+ u := coreType(ch.typ)
if u == nil {
- check.invalidOp(inNode(s, s.Arrow), _InvalidSend, "cannot send to %s: no structural type", &ch)
+ check.invalidOp(inNode(s, s.Arrow), _InvalidSend, "cannot send to %s: no core type", &ch)
return
}
uch, _ := u.(*Chan)
// determine key/value types
var key, val Type
if x.mode != invalid {
- // Ranging over a type parameter is permitted if it has a structural type.
+ // Ranging over a type parameter is permitted if it has a core type.
var cause string
- u := structuralType(x.typ)
+ u := coreType(x.typ)
switch t := u.(type) {
case nil:
- cause = check.sprintf("%s has no structural type", x.typ)
+ cause = check.sprintf("%s has no core type", x.typ)
case *Chan:
if s.Value != nil {
check.softErrorf(s.Value, _InvalidIterVar, "range over %s permits only one iteration variable", &x)
_ = make /* ERROR expects 2 or 3 arguments */ (S1)
_ = make(S1, 10, 20)
_ = make /* ERROR expects 2 or 3 arguments */ (S1, 10, 20, 30)
- _ = make(S2 /* ERROR cannot make S2: no structural type */ , 10)
+ _ = make(S2 /* ERROR cannot make S2: no core type */ , 10)
type M0 map[string]int
_ = make(map[string]int)
_ = make(M1)
_ = make(M1, 10)
_ = make/* ERROR expects 1 or 2 arguments */(M1, 10, 20)
- _ = make(M2 /* ERROR cannot make M2: no structural type */ )
+ _ = make(M2 /* ERROR cannot make M2: no core type */ )
type C0 chan int
_ = make(chan int)
_ = make(C1)
_ = make(C1, 10)
_ = make/* ERROR expects 1 or 2 arguments */(C1, 10, 20)
- _ = make(C2 /* ERROR cannot make C2: no structural type */ )
+ _ = make(C2 /* ERROR cannot make C2: no core type */ )
_ = make(C3)
}
type myByte1 []byte
type myByte2 []byte
func _[T interface{ []byte | myByte1 | myByte2 }] (x T, i, j, k int) { var _ T = x[i:j:k] }
-func _[T interface{ []byte | myByte1 | []int }] (x T, i, j, k int) { var _ T = x /* ERROR no structural type */ [i:j:k] }
+func _[T interface{ []byte | myByte1 | []int }] (x T, i, j, k int) { var _ T = x /* ERROR no core type */ [i:j:k] }
func _[T interface{ []byte | myByte1 | myByte2 | string }] (x T, i, j, k int) { var _ T = x[i:j] }
func _[T interface{ []byte | myByte1 | myByte2 | string }] (x T, i, j, k int) { var _ T = x[i:j:k /* ERROR 3-index slice of string */ ] }
-func _[T interface{ []byte | myByte1 | []int | string }] (x T, i, j, k int) { var _ T = x /* ERROR no structural type */ [i:j] }
+func _[T interface{ []byte | myByte1 | []int | string }] (x T, i, j, k int) { var _ T = x /* ERROR no core type */ [i:j] }
// len/cap built-ins
for _, _ = range s1 {}
var s2 S2
- for range s2 /* ERROR cannot range over s2.*no structural type */ {}
+ for range s2 /* ERROR cannot range over s2.*no core type */ {}
var a0 []int
for range a0 {}
for _, _ = range a1 {}
var a2 A2
- for range a2 /* ERROR cannot range over a2.*no structural type */ {}
+ for range a2 /* ERROR cannot range over a2.*no core type */ {}
var p0 *[10]int
for range p0 {}
for _, _ = range p1 {}
var p2 P2
- for range p2 /* ERROR cannot range over p2.*no structural type */ {}
+ for range p2 /* ERROR cannot range over p2.*no core type */ {}
var m0 map[string]int
for range m0 {}
for _, _ = range m1 {}
var m2 M2
- for range m2 /* ERROR cannot range over m2.*no structural type */ {}
+ for range m2 /* ERROR cannot range over m2.*no core type */ {}
}
// type inference checks
// from the first one through constraint type inference.
related3[int]()
- // The inferred type is the structural type of the Slice
+ // The inferred type is the core type of the Slice
// type parameter.
var _ []int = related3[int]()
// It is possible to create composite literals of type parameter
// type as long as it's possible to create a composite literal
-// of the structural type of the type parameter's constraint.
+// of the core type of the type parameter's constraint.
func _[P interface{ ~[]int }]() P {
return P{}
return P{1, 2, 3}
}
// This is a degenerate case with a singleton type set, but we can create
-// composite literals even if the structural type is a defined type.
+// composite literals even if the core type is a defined type.
type MyInts []int
func _[P MyInts]() P {
type C5[T any] interface{ ~chan T | <-chan T }
func _[T any](ch T) {
- <-ch // ERROR cannot receive from ch .* no structural type
+ <-ch // ERROR cannot receive from ch .* no core type
}
func _[T C0](ch T) {
}
func _[T C3](ch T) {
- <-ch // ERROR cannot receive from ch .* no structural type
+ <-ch // ERROR cannot receive from ch .* no core type
}
func _[T C4](ch T) {
type C5[T any] interface{ ~chan T | chan<- T }
func _[T any](ch T) {
- ch <- /* ERROR cannot send to ch .* no structural type */ 0
+ ch <- /* ERROR cannot send to ch .* no core type */ 0
}
func _[T C0](ch T) {
}
func _[T C3](ch T) {
- ch <- /* ERROR cannot send to ch .* no structural type */ 0
+ ch <- /* ERROR cannot send to ch .* no core type */ 0
}
func _[T C4](ch T) {
func _[P1 any, P2 ~byte](s1 P1, s2 P2) {
_ = append(nil /* ERROR first argument to append must be a slice; have untyped nil */ , 0)
- _ = append(s1 /* ERROR s1 .* has no structural type */ , 0)
- _ = append(s2 /* ERROR s2 .* has structural type byte */ , 0)
+ _ = append(s1 /* ERROR s1 .* has no core type */ , 0)
+ _ = append(s2 /* ERROR s2 .* has core type byte */ , 0)
}
var _ = f2[Sfm]
-// special case: structural type is a named pointer type
+// special case: core type is a named pointer type
type PSfm *Sfm
return t.Underlying()
}
-// If t is not a type parameter, structuralType returns the underlying type.
-// If t is a type parameter, structuralType returns the single underlying
+// If t is not a type parameter, coreType returns the underlying type.
+// If t is a type parameter, coreType returns the single underlying
// type of all types in its type set if it exists, or nil otherwise. If the
// type set contains only unrestricted and restricted channel types (with
// identical element types), the single underlying type is the restricted
// channel type if the restrictions are always the same, or nil otherwise.
-func structuralType(t Type) Type {
+func coreType(t Type) Type {
tpar, _ := t.(*TypeParam)
if tpar == nil {
return under(t)
return nil
}
-// structuralString is like structuralType but also considers []byte
+// coreString is like coreType but also considers []byte
// and strings as identical. In this case, if successful and we saw
// a string, the result is of type (possibly untyped) string.
-func structuralString(t Type) Type {
+func coreString(t Type) Type {
tpar, _ := t.(*TypeParam)
if tpar == nil {
return under(t) // string or untyped string
var _ = f2[Sfm]
-// special case: structural type is a named pointer type
+// special case: core type is a named pointer type
type PSfm *Sfm
var _ = f3[PSfm]
-// special case: structural type is an unnamed pointer type
+// special case: core type is an unnamed pointer type
func f4[P interface{ *Sfm }](p P) {
_ = p.f
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// This file tests type lists & structural constraints.
+// This file tests type lists & constraints with core types.
// Note: This test has been adjusted to use the new
// type set notation rather than type lists.
var _ T = 42
var _ T = T(myint(42))
}
+
// TODO: put this type declaration back inside the above function when issue 47631 is fixed.
type myint int
-// Indexing a generic type which has a structural contraints to be an array.
+// Indexing a generic type which has a an array as core type.
func _[T interface{ ~[10]int }](x T) {
_ = x[9] // ok
}
-// Dereference of a generic type which has a structural contraint to be a pointer.
+// Dereference of a generic type which has a pointer as core type.
func _[T interface{ ~*int }](p T) int {
return *p
}
-// Channel send and receive on a generic type which has a structural constraint to
-// be a channel.
+// Channel send and receive on a generic type which has a channel as core type.
func _[T interface{ ~chan int }](ch T) int {
// This would deadlock if executed (but ok for a compile test)
ch <- 0
return <-ch
}
-// Calling of a generic type which has a structural constraint to be a function.
+// Calling of a generic type which has a function as core type.
func _[T interface{ ~func() }](f T) {
f()
go f()
return f("hello")
}
-// Map access of a generic type which has a structural constraint to be a map.
+// Map access of a generic type which has a map as core type.
func _[V any, T interface{ ~map[string]V }](p T) V {
return p["test"]
}
b B
c C
}
-}, B any, C interface{ ~*B }](x B) A { panic(0) }
+}, B any, C interface{ ~*B }](x B) A {
+ panic(0)
+}
func f5x() {
x := f5(1.2)
var _ float64 = x.b