From f1ff58d7324829c1b463e663af6fa664b1542a24 Mon Sep 17 00:00:00 2001 From: Daniel X Moore Date: Sat, 7 Dec 2024 08:16:00 -0800 Subject: [PATCH] Fix #1637: prevent parser crash on blocks inside switch --- source/parser/function.civet | 4 ++-- test/switch.civet | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/source/parser/function.civet b/source/parser/function.civet index 08369e28..0b6e50d6 100644 --- a/source/parser/function.civet +++ b/source/parser/function.civet @@ -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" @@ -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" diff --git a/test/switch.civet b/test/switch.civet index 16412dd2..099844c1 100644 --- a/test/switch.civet +++ b/test/switch.civet @@ -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 + """