Skip to content

Commit 4729810

Browse files
committed
Show better errors for loops/procs.
1 parent 2367bf4 commit 4729810

4 files changed

Lines changed: 8 additions & 5 deletions

File tree

src/compiler/parser-actions.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ static bool SMB_E_POP_LOOP(parse &s)
310310
s.debug("E_POP_LOOP");
311311
auto l = s.pop_loop(LT_DO_LOOP);
312312
if(l.empty())
313-
return false;
313+
return s.loop_error("loop start missing");
314314
s.emit_word(l);
315315
s.emit_label(l + "_x");
316316
return true;
@@ -371,6 +371,8 @@ static bool SMB_E_EXIT_LOOP(parse &s)
371371
if(type == LT_ELIF || type == LT_IF || type == LT_ELSE || type == LT_FOR_2 ||
372372
type == LT_WHILE_2)
373373
continue;
374+
else if(type <= LT_EXIT)
375+
return s.loop_error("invalid EXIT");
374376
break;
375377
}
376378
s.emit_word(s.jumps[last].label + "_x");
@@ -584,7 +586,7 @@ static bool SMB_E_LABEL_DEF(parse &s)
584586
auto &v = s.labels;
585587
auto name = s.last_label;
586588
if(v[name].is_defined())
587-
return false;
589+
return s.loop_error("new label, got label already defined '" + name + "'");
588590
s.current_params = 0;
589591
s.emit_label(s.label_prefix + name);
590592
return true;
@@ -629,7 +631,7 @@ static bool SMB_E_LABEL_CREATE(parse &s)
629631
auto &v = s.labels[name];
630632
// Check type
631633
if(!v.is_proc())
632-
return s.error("new label, got label already defined '" + name + "'");
634+
return s.loop_error("new label, got label already defined '" + name + "'");
633635
// Store variable name
634636
s.add_text(name);
635637
s.last_label = name;

src/compiler/parser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ class parse
270270
// Loop error takes precedence over all other errors
271271
saved_errors.clear();
272272
saved_errors.emplace(lvl, str);
273+
max_pos = pos;
273274
debug("Set loop error='" + str + "'");
274275
return false;
275276
}

testsuite/tests/err-loop-4.chk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Name: Check detection of loop errors
22
Test: compile-error
33
Error: bad loop at line 3 column 1
4-
Error-pos: 4:5
4+
Error-pos: 3:4

testsuite/tests/procerr2.chk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Name: Check detection of already defined PROC
22
Test: compile-error
33
Error: parse error at line 6 column 10
4-
Error-pos: 6:5
4+
Error-pos: 6:10

0 commit comments

Comments
 (0)