Commit d513f65
fix: IfExpr parser double-consumes RBrace; add test_if_expr.omc
parse_block() already consumes the closing `}`, so the IfExpr handler
in parse_primary was calling expect(RBrace) a second time, leaving
Token::Else as the current token and producing "Expected RBrace, got
Else" on any `if cond { val } else { val }` in expression position
(e.g. as a function argument like `str_concat("x=", if b { "y" } else
{ "z" })`).
Fix: remove the redundant expect(RBrace) calls in both the then-branch
and else-branch paths of the IfExpr parser arm. Mirrors parse_if_stmt
which has the same contract.
Add examples/tests/test_if_expr.omc (6 tests) covering:
- basic true/false branch selection
- if-expr as function argument (regression test for the double-consume bug)
- no-else returns null on false path
- chained else-if
- single-expression lambda `fn(p) expr`
- dict bare-ident keys `{name: val}`
Suite: 1132/1132 passing (77 files).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>1 parent c88cdde commit d513f65
2 files changed
Lines changed: 56 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1899 | 1899 | | |
1900 | 1900 | | |
1901 | 1901 | | |
| 1902 | + | |
1902 | 1903 | | |
1903 | | - | |
1904 | 1904 | | |
1905 | 1905 | | |
1906 | 1906 | | |
| |||
1909 | 1909 | | |
1910 | 1910 | | |
1911 | 1911 | | |
1912 | | - | |
1913 | | - | |
1914 | | - | |
| 1912 | + | |
1915 | 1913 | | |
1916 | 1914 | | |
1917 | 1915 | | |
| |||
0 commit comments