ReviewOS

home-lang/home

fix(parser): parse assert! arguments instead of negating a tuple

#831
Closed glennmichael123 opened this 9 days ago ·
9 days ago

Problem

At statement position, the lexer tokenizes assert as the Assert keyword. The statement parser consumes it before the generic built-in macro parser can see assert!. The existing assertStatement then begins parsing at !, so assert!(b != 0, "message") becomes logical-not applied to the parenthesized argument tuple instead of an assertion whose condition is b != 0. Type checking consequently reports Logical not requires boolean or optional operand.

This is the last failing example in the current home check examples/ baseline.

Scope

  • Recognize the built-in macro spelling in assertStatement.
  • Preserve the comparison as the assertion condition and the optional message as a separate expression.
  • Retain the existing keyword spelling (assert condition, message).
  • Cover parser shape and checker behavior.

Acceptance criteria

  • assert!(b != 0, "division by zero") parses to AssertStmt with a NotEqual condition.
  • The valid macro form passes type checking.
  • A non-boolean macro condition is still rejected.
  • Parser and assertion checker tests pass.
  • home check examples/ reaches 39/39.

Part of #779 and #66.

9 days ago

Fixed on main by 4bf5d67.

Verified:

  • parser suite: 150/150
  • assertion checker suite: passing
  • fresh no-JSC debug build: passing, 2,825 MB guarded peak
  • examples acceptance: 39/39, 190 MB guarded peak

The parser now recognizes assert! before treating ! as unary negation, preserves the comparison and optional message as separate AssertStmt fields, retains keyword-form assert, and continues rejecting non-boolean conditions.

Sign in to comment on this issue.