Skip to content

TP0215

Error: break/continue outside loop, return outside function, a bare raise outside except, return/break/continue in finally, or a misplaced yield or await

  • 'yield from' can't be in an async generator
  • 'async for' outside an async function (and 'async with') (M42; 'yield' can't be inside a 'with', 'yield' in an async function and 'yield' can't be inside a 'try' with 'except', or in 'finally' are gone)
  • 'yield' can't be inside a 'with' (M37)
  • 'await' can't be inside a comprehension (M36)
  • 'await' outside an async function
  • 'yield' in an async function (M33)
  • 'yield' outside a function
  • 'yield' can't be inside a 'try' with 'except', or in 'finally' (M31)
  • '<k>' can't leave a 'match' expression, with help use a 'match' statement (M29)
  • 'break' outside a loop
  • 'continue' outside a loop
  • 'return' outside a function
  • 'raise' without an exception outside an except block
  • 'return' cannot be used in a finally block (and 'break', 'continue') (M16)

From the golden case tests/cases/m11/tp0215_nested.tpn:

tp0215_nested.tpn
for i in range(3):
def stop():
break
stop()

The compiler reports:

tp0215_nested.tpn:3:9: error TP0215: 'break' outside a loop

The specification lists every code.