embeddedPos := pos
check.later(func() {
t, isPtr := deref(embeddedTyp)
- switch t := optype(t).(type) {
+ switch t := under(t).(type) {
case *Basic:
if t == Typ[Invalid] {
// error was reported before
}
case *Pointer:
check.error(embeddedPos, "embedded field type cannot be a pointer")
+ case *TypeParam:
+ check.error(embeddedPos, "embedded field type cannot be a (pointer to a) type parameter")
case *Interface:
if isPtr {
check.error(embeddedPos, "embedded field type cannot be a pointer to an interface")
func _[T any](map[T /* ERROR invalid map key type T \(missing comparable constraint\) */]int) // w/o constraint we don't know if T is comparable
-func f1[T1 any](struct{T1}) int
+func f1[T1 any](struct{T1 /* ERROR cannot be a .* type parameter */ }) int
var _ = f1[int](struct{T1}{})
type T1 = int
-func f2[t1 any](struct{t1; x float32}) int
+func f2[t1 any](struct{t1 /* ERROR cannot be a .* type parameter */ ; x float32}) int
var _ = f2[t1](struct{t1; x float32}{})
type t1 = int
type E0[P any] P
type E1[P any] *P
-type E2[P any] struct{ P }
-type E3[P any] struct{ *P }
+type E2[P any] struct{ _ P }
+type E3[P any] struct{ _ *P }
type T0 /* ERROR illegal cycle */ struct {
_ E0[T0]
type I interface{}
type _S[T any] struct {
- *T
+ x *T
}
// F is a non-generic function, but has a type _S[I] which is instantiated from a
// generic type. Test that _S[I] is successfully exported.
func F() {
v := _S[I]{}
- if v.T != nil {
+ if v.x != nil {
panic(v)
}
}
}
func F2() {
- _F1(&S1{})
- _F1(S2{})
- _F1(&S2{})
+ _F1(&S1{})
+ _F1(S2{})
+ _F1(&S2{})
}
func main() {
// A Lockable is a value that may be safely simultaneously accessed
// from multiple goroutines via the Get and Set methods.
type Lockable[T any] struct {
- T
+ x T
mu sync.Mutex
}
func (l *Lockable[T]) get() T {
l.mu.Lock()
defer l.mu.Unlock()
- return l.T
+ return l.x
}
// set sets the value in a Lockable.
func (l *Lockable[T]) set(v T) {
l.mu.Lock()
defer l.mu.Unlock()
- l.T = v
+ l.x = v
}
func main() {
- sl := Lockable[string]{T: "a"}
+ sl := Lockable[string]{x: "a"}
if got := sl.get(); got != "a" {
panic(got)
}
panic(got)
}
- il := Lockable[int]{T: 1}
+ il := Lockable[int]{x: 1}
if got := il.get(); got != 1 {
panic(got)
}