Class AssertPanicExprGenerator

All Implemented Interfaces:
BiFunction<EK9Parser.AssertPanicExpressionContext, String, List<IRInstr>>

public final class AssertPanicExprGenerator extends AbstractAssertExprGenerator implements BiFunction<EK9Parser.AssertPanicExpressionContext, String, List<IRInstr>>
IR Generation for the assertPanic expression.

Generates the ASSERT_PANIC opcode for test assertions that expect an org.ek9.lang::Panic to fire. Reuses AssertThrowsInstr (which multiplexes the assert-family opcodes) via its assertPanic(...) factory - the catch target is fixed to org.ek9.lang::Panic, so unlike AssertThrowsExprGenerator there is no typeDef.

Grammar: assertPanicExpression: ASSERT_PANIC LPAREN expression RPAREN

Semantics:

  • Evaluates the expression within a try block
  • If a Panic is caught, stores it to the result variable (success)
  • If no panic thrown, throws AssertionError (failure)
  • If a non-Panic throwable escapes, rethrows it (test failure)

Used in two contexts:

  • Statement form: assertPanic(mustBePositive(-1))
  • Expression form: p <- assertPanic(Rating(11))