Skip to content

Assertions

assert is a statement that checks a Boolean condition at runtime. If the condition is true, execution continues silently. If it is false, the program panics immediately with a descriptive failure message.

let x = 42
assert x > 0 // passes. Silent
assert x == 42 // passes. Silent
assert <expr>

The expression must be of type Bool. The checker rejects any other type at compile time (error E100).

assert true // ok
assert 1 == 1 // ok
assert "hello" // E100: type mismatch. Expected Bool, found String

When an assertion fails, Vertex prints a rich message that includes:

  • The source location (file, line, column).
  • The rendered source of the condition.
  • For comparison operators (==, !=, <, >, <=, >=): the actual values of the left-hand and right-hand sides.

Comparison failure example:

assertion failed at examples/jit/lang/assertions.vtx:7:1
source: x == 42
left: 5
right: 42

Non-comparison failure example:

assertion failed at examples/jit/lang/assertions.vtx:11:1
source: list.contains(target)

These are two distinct constructs that share the assert keyword:

assertlet assert
PurposeCheck a Bool invariantDestructure a value that must match a pattern
Formassert exprlet assert Pat = expr
Failure messageassertion failed: …let assert pattern did not match: …

Both cause a panic on failure and are appropriate during development and in tests.

assert expr compiles to System.Assert.isTrue(expr, 'assertion failed at …'). The message is a compile-time string. No runtime decomposition occurs on the Apex side. Assertions are never stripped from emitted Apex; there is no release-build mode that removes them.