@@ -40,10 +40,15 @@ error[E1002]: Missing tokens. Expected an expression.
4040 if 0 == if x {1} else {2} {
4141 ^
4242
43- error[E1000 ]: Skipped tokens. Expected: '{'.
44- --> dummy_file.cairo:2:13
43+ error[E1001 ]: Missing token '{'.
44+ --> dummy_file.cairo:2:12
4545 if 0 == if x {1} else {2} {
46- ^^^^
46+ ^
47+
48+ error[E1001]: Missing token '}'.
49+ --> dummy_file.cairo:4:2
50+ }
51+ ^
4752
4853//! > ==========================================================================
4954
@@ -315,3 +320,57 @@ error[E1000]: Skipped tokens. Expected: statement.
315320 --> dummy_file.cairo:7:44
316321 if x += 3 && let x = 10 || false < > { += }
317322 ^^
323+
324+ //! > ==========================================================================
325+
326+ //! > Test broken if header does not swallow a following control-flow statement
327+
328+ //! > test_comments
329+ // Recovering the broken `if` block must stop at the following `while`, leaving it
330+ // as its own statement rather than consuming its `{ ... }` as the `if` body.
331+
332+ //! > test_runner_name
333+ get_diagnostics
334+
335+ //! > cairo_code
336+ fn f(a: felt252, b: bool) {
337+ if a ==
338+ while b { let _x = 1; }
339+ let _y = 2;
340+ }
341+
342+ //! > expected_diagnostics
343+ error[E1002]: Missing tokens. Expected an expression.
344+ --> dummy_file.cairo:2:12
345+ if a ==
346+ ^
347+
348+ error[E1001]: Missing token '{'.
349+ --> dummy_file.cairo:2:12
350+ if a ==
351+ ^
352+
353+ error[E1001]: Missing token '}'.
354+ --> dummy_file.cairo:5:2
355+ }
356+ ^
357+
358+ //! > ==========================================================================
359+
360+ //! > Test bad if condition with well-formed braces keeps the inner statement.
361+
362+ //! > test_runner_name
363+ get_diagnostics
364+
365+ //! > cairo_code
366+ fn f(b: bool) {
367+ if {
368+ while b {}
369+ }
370+ }
371+
372+ //! > expected_diagnostics
373+ error[E1002]: Missing tokens. Expected an expression.
374+ --> dummy_file.cairo:2:7
375+ if {
376+ ^
0 commit comments