Skip to content

Commit

Permalink
fix #8821 (#15809)
Browse files Browse the repository at this point in the history
  • Loading branch information
ringabout authored Nov 2, 2020
1 parent 00b495d commit 544cb10
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions compiler/jsgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,7 @@ proc genRaiseStmt(p: PProc, n: PNode) =
proc genCaseJS(p: PProc, n: PNode, r: var TCompRes) =
var
cond, stmt: TCompRes
totalRange = 0
genLineDir(p, n)
gen(p, n[0], cond)
let stringSwitch = skipTypes(n[0].typ, abstractVar).kind == tyString
Expand All @@ -884,6 +885,10 @@ proc genCaseJS(p: PProc, n: PNode, r: var TCompRes) =
let e = it[j]
if e.kind == nkRange:
var v = copyNode(e[0])
inc(totalRange, int(e[1].intVal - v.intVal))
if totalRange > 65535:
localError(p.config, n.info,
"Your case statement contains too many branches, consider using if/else instead!")
while v.intVal <= e[1].intVal:
gen(p, v, cond)
lineF(p, "case $1:$n", [cond.rdLoc])
Expand Down
12 changes: 12 additions & 0 deletions tests/js/t8821.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
discard """
errormsg: "Your case statement contains too many branches, consider using if/else instead!"
"""

proc isInt32(i: int): bool =
case i
of 1 .. 70000:
return true
else:
return false

discard isInt32(1)

0 comments on commit 544cb10

Please sign in to comment.