Skip to content

TP0228

Error: incompatible override

  • '<m>' must take the same parameters as '<B>.<m>'
  • parameter '<p>' of '<m>' must have type <T>, as in '<B>.<m>'
  • parameter '<p>' of '<m>' needs a default, as in '<B>.<m>'
  • '<m>' must return <T>, as '<B>.<m>' does (or return nothing)
  • '<m>' is a <static method|class method|method|property> in '<B>'
  • '<p>' must have a setter, as '<B>.<p>' does
  • '<D>.<m>' must return <R>, since it can run in place of '<B>.<op>'
  • '<D>' must be constructed as '<C>' is, since '<C>.<m>' calls 'cls(…)' (M28)
  • '<B>.<m>' is final
  • '<m>' must return Self, as '<B>.<m>' does (M39)
  • '<m>' must be 'def <m>(self, <params>) -> <R>', as in '<I>.<m>' (implementing a .NET interface’s method, or overriding a .NET class’s) (M43)

From the golden case tests/cases/m39/tp0228_classes.tpn:

tp0228_classes.tpn
class Animal:
@final
def name(self) -> str:
return "animal"
def me(self) -> Self:
return self
class Dog(Animal):
@override
def name(self) -> str:
return "dog"
@override
def me(self) -> Dog:
return self

The compiler reports:

tp0228_classes.tpn:11:9: error TP0228: 'Animal.name' is final
tp0228_classes.tpn:15:21: error TP0228: 'me' must return Self, as 'Animal.me' does

The specification lists every code.