Skip to content

Commit

Permalink
[parser] catch duplicate #else
Browse files Browse the repository at this point in the history
closes #11208
  • Loading branch information
Simn committed Nov 7, 2023
1 parent bc4bd28 commit 7a4054f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/syntax/parserEntry.ml
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,18 @@ class condition_handler = object(self)

method private cond_if' (e : expr) =
conditional_expressions <- e :: conditional_expressions;
conditional_stack <- e :: conditional_stack
conditional_stack <- (e,false) :: conditional_stack

method cond_if (e : expr) =
self#cond_if' e;
depths <- 1 :: depths

method cond_else (p : pos) =
match conditional_stack with
| e :: el ->
conditional_stack <- (self#negate e) :: el
| (_,true) :: _ ->
error (Preprocessor_error InvalidElse) p
| (e,false) :: el ->
conditional_stack <- (self#negate e,true) :: el
| [] ->
error (Preprocessor_error InvalidElse) p

Expand All @@ -178,8 +180,8 @@ class condition_handler = object(self)
depths <- depths'

method get_current_condition = match conditional_stack with
| e :: el ->
List.fold_left self#conjoin e el
| (e,_) :: el ->
List.fold_left self#conjoin e (List.map fst el)
| [] ->
(EConst (Ident "true"),null_pos)

Expand Down
9 changes: 9 additions & 0 deletions tests/misc/projects/Issue11208/Main.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function main() {
#if false
trace("?");
#else
trace("!");
#else
trace("...");
#end
}
1 change: 1 addition & 0 deletions tests/misc/projects/Issue11208/compile-fail.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--main Main
1 change: 1 addition & 0 deletions tests/misc/projects/Issue11208/compile-fail.hxml.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Main.hx:6: characters 2-7 : Invalid #else

0 comments on commit 7a4054f

Please sign in to comment.