bugfix: case exhaustiveness checking
This commit is contained in:
parent
b7d1901747
commit
02b1503e1f
5 changed files with 27 additions and 6 deletions
|
|
@ -156,6 +156,10 @@ proc skipConv*(n: PNode): PNode =
|
||||||
result = n.sons[1]
|
result = n.sons[1]
|
||||||
else: result = n
|
else: result = n
|
||||||
|
|
||||||
|
proc skipConvTakeType*(n: PNode): PNode =
|
||||||
|
result = n.skipConv
|
||||||
|
result.typ = n.typ
|
||||||
|
|
||||||
proc SameValue*(a, b: PNode): bool =
|
proc SameValue*(a, b: PNode): bool =
|
||||||
result = false
|
result = false
|
||||||
case a.kind
|
case a.kind
|
||||||
|
|
|
||||||
|
|
@ -44,9 +44,9 @@ proc inSet(s: PNode, elem: PNode): bool =
|
||||||
return true
|
return true
|
||||||
result = false
|
result = false
|
||||||
|
|
||||||
proc overlap(a, b: PNode): bool =
|
proc overlap(a, b: PNode): bool =
|
||||||
if a.kind == nkRange:
|
if a.kind == nkRange:
|
||||||
if b.kind == nkRange:
|
if b.kind == nkRange:
|
||||||
# X..Y and C..D overlap iff (X <= D and C <= Y)
|
# X..Y and C..D overlap iff (X <= D and C <= Y)
|
||||||
result = leValue(a.sons[0], b.sons[1]) and
|
result = leValue(a.sons[0], b.sons[1]) and
|
||||||
leValue(b.sons[0], a.sons[1])
|
leValue(b.sons[0], a.sons[1])
|
||||||
|
|
|
||||||
|
|
@ -323,8 +323,8 @@ proc semBranchRange(c: PContext, t, a, b: PNode, covered: var biggestInt): PNode
|
||||||
checkMinSonsLen(t, 1)
|
checkMinSonsLen(t, 1)
|
||||||
let ac = semConstExpr(c, a)
|
let ac = semConstExpr(c, a)
|
||||||
let bc = semConstExpr(c, b)
|
let bc = semConstExpr(c, b)
|
||||||
let at = fitNode(c, t.sons[0].typ, ac)
|
let at = fitNode(c, t.sons[0].typ, ac).skipConvTakeType
|
||||||
let bt = fitNode(c, t.sons[0].typ, bc)
|
let bt = fitNode(c, t.sons[0].typ, bc).skipConvTakeType
|
||||||
|
|
||||||
result = newNodeI(nkRange, a.info)
|
result = newNodeI(nkRange, a.info)
|
||||||
result.add(at)
|
result.add(at)
|
||||||
|
|
|
||||||
18
tests/reject/tcaseoverlaprange2.nim
Normal file
18
tests/reject/tcaseoverlaprange2.nim
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
discard """
|
||||||
|
line: 13
|
||||||
|
errormsg: "duplicate case label"
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
proc checkDuplicates(myval: int32): bool =
|
||||||
|
case myval
|
||||||
|
of 0x7B:
|
||||||
|
echo "this should not compile"
|
||||||
|
of 0x78 .. 0x7D:
|
||||||
|
result = true
|
||||||
|
else:
|
||||||
|
nil
|
||||||
|
|
||||||
|
echo checkDuplicates(0x7B)
|
||||||
1
todo.txt
1
todo.txt
|
|
@ -31,7 +31,6 @@ Bugs
|
||||||
- osproc execProcesses can deadlock if all processes fail (as experienced
|
- osproc execProcesses can deadlock if all processes fail (as experienced
|
||||||
in c++ mode)
|
in c++ mode)
|
||||||
- bootstrapping does not work in C++ mode
|
- bootstrapping does not work in C++ mode
|
||||||
- case statement exhaustiveness checking is still wrong
|
|
||||||
- the new m&s GC is still buggy
|
- the new m&s GC is still buggy
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue