Skip to content

Commit

Permalink
Fix #1637: prevent parser crash on blocks inside switch
Browse files Browse the repository at this point in the history
  • Loading branch information
STRd6 committed Dec 7, 2024
1 parent de02a17 commit f1ff58d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions source/parser/function.civet
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ function assignResults(node: StatementTuple[] | ASTNode, collect: (node: ASTNode
wrapIterationReturningResults exp, collect
return
when "BlockStatement"
return if node.expressions.some isExit
return if exp.expressions.some isExit
assignResults(exp.expressions[exp.expressions.length - 1], collect)
return
when "IfStatement"
Expand Down Expand Up @@ -603,7 +603,7 @@ function processBreakContinueWith(statement: IterationStatement | ForStatement):
.type is "BreakStatement" or .type is "ContinueStatement"
)
function controlName: string
switch control.type
switch control.type
when "BreakStatement"
"break"
when "ContinueStatement"
Expand Down
14 changes: 14 additions & 0 deletions test/switch.civet
Original file line number Diff line number Diff line change
Expand Up @@ -1714,3 +1714,17 @@ describe "switch", ->
---
ParseErrors: unknown:1:1 'continue switch' can only be used at end of 'when' clause
"""

testCase """
#1637
---
nextLocation := switch direction
when Direction.Up
{ location.y - 1 }
---
let ref;switch(direction) {
case Direction.Up: {
{ ref = location.y - 1 };break;
}
};const nextLocation =ref
"""

0 comments on commit f1ff58d

Please sign in to comment.