type List[P any] []P
-// Alias type declarations cannot have type parameters. Syntax error.
+// Alias type declarations cannot have type parameters.
+// Issue #46477 proposses to change that.
type A1[P any] = /* ERROR cannot be alias */ P
-// But an alias may refer to a generic, uninstantiated type.
-type A2 = List
+// Pending clarification of #46477 we disallow aliases
+// of generic types.
+type A2 = List // ERROR cannot use generic type
var _ A2[int]
-var _ A2 /* ERROR without instantiation */
+var _ A2
type A3 = List[int]
var _ A3
}
return
case universeAny, universeComparable:
- // complain if necessary but keep going
+ // complain if necessary
if !check.allowVersion(check.pkg, 1, 18) {
- check.softErrorf(e, _UndeclaredName, "undeclared name: %s (requires version go1.18 or later)", e.Name)
- } else if obj == universeAny {
+ check.errorf(e, _UndeclaredName, "undeclared name: %s (requires version go1.18 or later)", e.Name)
+ return // avoid follow-on errors
+ }
+ if obj == universeAny {
// If we allow "any" for general use, this if-statement can be removed (issue #33232).
check.softErrorf(e, _Todo, "cannot use any outside constraint position")
+ // ok to continue
}
}
check.recordUse(e, obj)
return typ
}
-// anyType type-checks the type expression e and returns its type, or Typ[Invalid].
-// The type may be generic or instantiated.
-func (check *Checker) anyType(e ast.Expr) Type {
- typ := check.typInternal(e, nil)
- assert(isTyped(typ))
- check.recordTypeAndValue(e, typexpr, typ, nil)
- return typ
-}
-
// definedType is like typ but also accepts a type name def.
// If def != nil, e is the type specification for the defined type def, declared
// in a type declaration, and def.underlying will be set to the type of e before