fixes #24031; js codegen bug for case statement with just else branch (#24047)

fixes #24031
This commit is contained in:
ringabout
2024-09-03 00:10:01 +08:00
committed by GitHub
parent fc853cb726
commit 4789af71fe
2 changed files with 14 additions and 2 deletions

View File

@@ -1098,14 +1098,19 @@ proc genCaseJS(p: PProc, n: PNode, r: var TCompRes) =
lineF(p, "break;$n", [])
of nkElse:
if transferRange:
lineF(p, "else{$n", [])
if n.len == 2: # a dangling else for a case statement
transferRange = false
lineF(p, "switch ($1) {$n", [cond.rdLoc])
lineF(p, "default: $n", [])
else:
lineF(p, "else{$n", [])
else:
lineF(p, "default: $n", [])
p.nested:
gen(p, it[0], stmt)
moveInto(p, stmt, r)
if transferRange:
lineF(p, "}$n", [])
lineF(p, "}$n", [])
else:
lineF(p, "break;$n", [])
else: internalError(p.config, it.info, "jsgen.genCaseStmt")

View File

@@ -0,0 +1,7 @@
discard """
targets: "c js"
"""
block: # bug #24031
case 0
else: discard