Skip to content

TP0220

Error: invalid type parameter constraint or bound

  • a bound can't use type parameters (M40)
  • a constraint needs at least two types
  • '<T>' is listed twice in the constraint
  • a constraint cannot be optional or generic
  • constraints are only supported on functions
  • '<T>' is not a protocol (with help class bounds are not supported, for a class)
  • bounds are only supported on functions (M17)

From the golden case tests/cases/m18/tp0220_alias.tpn:

tp0220_alias.tpn
# An alias's type parameters take no constraints or bounds (SPEC §3.12).
type Numbers[N: (int, float)] = list[N]
type Sorted[T: Comparable] = list[T]

The compiler reports:

tp0220_alias.tpn:2:18: error TP0220: constraints are only supported on functions
tp0220_alias.tpn:3:16: error TP0220: bounds are only supported on functions

The specification lists every code.