Class AssertThrowsInstr
java.lang.Object
org.ek9lang.compiler.ir.instructions.IRInstr
org.ek9lang.compiler.ir.instructions.AssertThrowsInstr
- All Implemented Interfaces:
INode
IR instruction for test-only assertion constructs that wrap expressions in try-catch.
Handles two opcodes:
- ASSERT_THROWS - Expects a specific exception type; returns caught exception
- ASSERT_DOES_NOT_THROW - Expects no exception; returns Void
These instructions are test-only constructs that throw non-catchable AssertionError when the assertion fails. The test runner detects program failure.
Memory management:
- Expression body instructions are evaluated within a try block
- For ASSERT_THROWS: caught exception is stored to result variable
- Scope management is handled by the contained instructions
-
Method Summary
Modifier and TypeMethodDescriptionstatic AssertThrowsInstrassertDoesNotThrow(List<IRInstr> bodyInstructions, String message, String scopeId, DebugInfo debugInfo) Create ASSERT_DOES_NOT_THROW instruction.static AssertThrowsInstrassertThrows(String result, String expectedType, List<IRInstr> bodyInstructions, String message, String scopeId, DebugInfo debugInfo) Create ASSERT_THROWS instruction.Get the expected exception type (for ASSERT_THROWS).Get the expression body instructions to evaluate within the try block.Get the error message for assertion failure.Get the scope ID for memory management.booleanCheck if this is an ASSERT_DOES_NOT_THROW instruction.booleanCheck if this is an ASSERT_THROWS instruction.toString()Methods inherited from class IRInstr
accept, addOperand, addOperands, equals, getDebugInfo, getEscapeMetaData, getOpcode, getOperands, getResult, hasEscapeMetaData, hashCode, hasResult, isControlFlow, isLabel, isMemoryManagement, isMethodCall, setEscapeMetaData
-
Method Details
-
assertThrows
public static AssertThrowsInstr assertThrows(String result, String expectedType, List<IRInstr> bodyInstructions, String message, String scopeId, DebugInfo debugInfo) Create ASSERT_THROWS instruction.When the expression throws the expected exception type, the exception is caught and stored to the result variable. If no exception or wrong type, throws AssertionError.
- Parameters:
result- Variable to store caught exception (can be null if not used)expectedType- Fully qualified name of expected exception typebodyInstructions- Instructions to evaluate within try blockmessage- Error message for assertion failurescopeId- Scope ID for memory managementdebugInfo- Debug info with source location
-
assertDoesNotThrow
public static AssertThrowsInstr assertDoesNotThrow(List<IRInstr> bodyInstructions, String message, String scopeId, DebugInfo debugInfo) Create ASSERT_DOES_NOT_THROW instruction.When the expression throws any exception, throws AssertionError with details. When no exception, the assertion passes (returns Void).
- Parameters:
bodyInstructions- Instructions to evaluate within try blockmessage- Error message prefix for assertion failurescopeId- Scope ID for memory managementdebugInfo- Debug info with source location
-
getExpectedExceptionType
Get the expected exception type (for ASSERT_THROWS).- Returns:
- Fully qualified exception type name, or null for ASSERT_DOES_NOT_THROW
-
getExpressionBodyInstructions
-
getMessage
Get the error message for assertion failure. -
getScopeId
Get the scope ID for memory management. -
isAssertThrows
public boolean isAssertThrows()Check if this is an ASSERT_THROWS instruction. -
isAssertDoesNotThrow
public boolean isAssertDoesNotThrow()Check if this is an ASSERT_DOES_NOT_THROW instruction. -
toString
-