Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parser crash on blocks inside switch #1640

Merged
merged 1 commit into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
"""
Loading