terms = tset.terms
case *TypeParam:
// Embedding stand-alone type parameters is not permitted.
- // This case is handled during union parsing.
- unreachable()
+ // Union parsing reports a (delayed) error, so we can ignore this entry.
+ continue
default:
if typ == Typ[Invalid] {
continue
terms = computeInterfaceTypeSet(check, pos, u).terms
case *TypeParam:
// A stand-alone type parameters is not permitted as union term.
- // This case is handled during union parsing.
- unreachable()
+ // Union parsing reports a (delayed) error, so we can ignore this entry.
+ continue
default:
if t.typ == Typ[Invalid] {
continue
for _, x := range tlist {
tilde, typ := parseTilde(check, x)
if len(tlist) == 1 && !tilde {
- return typ // single type (optimization)
+ // Single type. Ok to return early because all relevant
+ // checks have been performed in parseTilde (no need to
+ // run through term validity check below).
+ return typ
}
if len(terms) >= maxTermCount {
check.errorf(x, _Todo, "cannot handle more than %d union terms (implementation limitation)", maxTermCount)
tilde = true
}
typ = check.typ(x)
- // embedding stand-alone type parameters is not permitted (issue #47127).
- if _, ok := under(typ).(*TypeParam); ok {
- check.error(x, _Todo, "cannot embed a type parameter")
- typ = Typ[Invalid]
- }
+ // Embedding stand-alone type parameters is not permitted (issue #47127).
+ // Do this check later because it requires computation of the underlying type (see also issue #46461).
+ // Note: If an underlying type cannot be a type parameter, the call to
+ // under() will not be needed and then we don't need to delay this
+ // check to later and could return Typ[Invalid] instead.
+ check.later(func() {
+ if _, ok := under(typ).(*TypeParam); ok {
+ check.error(x, _Todo, "cannot embed a type parameter")
+ }
+ })
return
}