Skip to content

TP0219

Error: generic instantiation too deep (polymorphic recursion)

  • instantiating '<f>' needs '<f>[<T>]', which is too deep, at the call that starts the chain

From the golden case tests/cases/m8/tp0219_polymorphic.tpn:

tp0219_polymorphic.tpn
def grow[T](x: T, n: int) -> int:
if n == 0:
return 0
return grow([x], n - 1)
print(grow(1, 3))

The compiler reports:

tp0219_polymorphic.tpn:6:1: error TP0219: instantiating 'grow' needs 'grow[list[list[list[...]]]]', which is too deep

The specification lists every code.