Skip to content

TP0229

Error: protocol used as a type

  • '<P>' is a protocol, so it can only be a type parameter bound, with help use a bounded type parameter, e.g. 'def f[T: <P>](x: T)' (M17)
  • '<P>' uses 'Self' in '<m>', so it can only be a type parameter bound, with M17’s help
  • '<P>' is a protocol, with help construct a class that satisfies it (a construction) or test for a class that satisfies it (isinstance, as, class patterns, except), replacing M17’s message for these (M40)

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

tp0229_alias.tpn
# An alias names a type, and a protocol isn't one (SPEC §3.11, §3.12).
type Ordered = Comparable
type Items = list[Comparable]

The compiler reports:

tp0229_alias.tpn:2:16: error TP0229: 'Comparable' uses 'Self' in '__lt__', so it can only be a type parameter bound
help: use a bounded type parameter, e.g. 'def f[T: Comparable](x: T)'
tp0229_alias.tpn:3:19: error TP0229: 'Comparable' uses 'Self' in '__lt__', so it can only be a type parameter bound
help: use a bounded type parameter, e.g. 'def f[T: Comparable](x: T)'

The specification lists every code.