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, "undeclared name: %s (requires version go1.18 or later)", e.Value)
- } else if obj == universeAny {
+ check.errorf(e, "undeclared name: %s (requires version go1.18 or later)", e.Value)
+ 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, "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 syntax.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
F T
}
-type S = R
+// type S = R // disallowed for now
type Sint = R[int]
-type Simp = a.Rimp
+// type Simp = a.Rimp // disallowed for now
-type SimpString Simp[string]
+// type SimpString Simp[string] // disallowed for now
+type SimpString a.Rimp[string]
func main() {
- var s S[int]
+ // var s S[int] // disallowed for now
+ var s R[int]
if s.F != 0 {
panic(s.F)
}
if s2.F != 0 {
panic(s2.F)
}
- var s3 Simp[string]
+ // var s3 Simp[string] // disallowed for now
+ var s3 a.Rimp[string]
if s3.F != "" {
panic(s3.F)
}