Skip to content

Commit

Permalink
Merge pull request #146 from Vardan2009/master
Browse files Browse the repository at this point in the history
Fix `Runtime Error: No cases matched` issue.
  • Loading branch information
Almas-Ali authored May 28, 2024
2 parents c24d8de + 0a7a713 commit f9e6bd8
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 11 deletions.
3 changes: 2 additions & 1 deletion core/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,8 @@ def visit_SwitchNode(self, node: SwitchNode, context: Context) -> RTResult[Value
if res.should_return():
return res
return res.success(Null.null())
return res.failure(RTError(node.pos_start, node.subject_node.pos_end, "No cases matched", context))

return res.success(Null.null())

def visit_FallthroughNode(self, node: FallthroughNode, context: Context) -> RTResult[Value]:
return RTResult[Value]().success(Null.null()).fallthrough()
Expand Down
1 change: 1 addition & 0 deletions tests/modules2.rn.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"code": 0, "stdout": "A\nr\nr\na\ny\n", "stderr": ""}
12 changes: 3 additions & 9 deletions tests/switch-case.rn
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,9 @@ test(5)
test(4)

print("---------------")
try {
switch 69 {
case 1 {
print("unreachable")
}
}
print("unreachable")
} catch as e {
print(e)
switch 69 {
case 1 -> print("unreachable")
default -> print("no cases matched")
}
print("---------------")

Expand Down
2 changes: 1 addition & 1 deletion tests/switch-case.rn.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"code": 0, "stdout": "It's a five!\nIt's a one!\nIt's a two!\nhaha funi\nI don't know what 42 is\nIt's a five!\nIt's a four!\n---------------\nRuntimeError: No cases matched\n---------------\ndefault: 1\nA two or a three\nA two or a three\ndefault: 4\n---------------\n0 1\none\n1 2\nfirst two\n2 3\nthree or second two\n3 2\nthree or second two\n4 5\ndefault\n", "stderr": ""}
{"code": 0, "stdout": "It's a five!\nIt's a one!\nIt's a two!\nhaha funi\nI don't know what 42 is\nIt's a five!\nIt's a four!\n---------------\nno cases matched\n---------------\ndefault: 1\nA two or a three\nA two or a three\ndefault: 4\n---------------\n0 1\none\n1 2\nfirst two\n2 3\nthree or second two\n3 2\nthree or second two\n4 5\ndefault\n", "stderr": ""}

0 comments on commit f9e6bd8

Please sign in to comment.