Skip to content

Commit

Permalink
fix #19678 Broken behavior with string ranges in case labels (#20475)
Browse files Browse the repository at this point in the history
* fix #19678 Broken behavior with string ranges in case labels

* Update compiler/semtypes.nim

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
  • Loading branch information
bung87 and Araq authored Oct 1, 2022
1 parent 8d47bf1 commit cbd9fee
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions compiler/semtypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,8 @@ proc semBranchRange(c: PContext, t, a, b: PNode, covered: var Int128): PNode =
checkMinSonsLen(t, 1, c.config)
let ac = semConstExpr(c, a)
let bc = semConstExpr(c, b)
if ac.kind in {nkStrLit..nkTripleStrLit} or bc.kind in {nkStrLit..nkTripleStrLit}:
localError(c.config, b.info, "range of string is invalid")
let at = fitNode(c, t[0].typ, ac, ac.info).skipConvTakeType
let bt = fitNode(c, t[0].typ, bc, bc.info).skipConvTakeType

Expand Down
17 changes: 17 additions & 0 deletions tests/range/t19678.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
discard """
cmd: "nim check --hints:off $file"
errormsg: ""
nimout: '''
t19678.nim(13, 13) Error: range of string is invalid
'''
"""

case "5":
of "0" .. "9":
discard
else:
discard

0 comments on commit cbd9fee

Please sign in to comment.