bugfix: wrong error: not all cases covered with enums with holes
This commit is contained in:
parent
fe4cc78294
commit
7dff3e64bb
3 changed files with 25 additions and 3 deletions
|
|
@ -136,6 +136,13 @@ proc semWhile(c: PContext, n: PNode): PNode =
|
||||||
dec(c.p.nestedLoopCounter)
|
dec(c.p.nestedLoopCounter)
|
||||||
closeScope(c.tab)
|
closeScope(c.tab)
|
||||||
|
|
||||||
|
proc toCover(t: PType): biggestInt =
|
||||||
|
var t2 = skipTypes(t, abstractVarRange)
|
||||||
|
if t2.kind == tyEnum and enumHasWholes(t2):
|
||||||
|
result = sonsLen(t2.n)
|
||||||
|
else:
|
||||||
|
result = lengthOrd(skipTypes(t, abstractVar))
|
||||||
|
|
||||||
proc semCase(c: PContext, n: PNode): PNode =
|
proc semCase(c: PContext, n: PNode): PNode =
|
||||||
# check selector:
|
# check selector:
|
||||||
result = n
|
result = n
|
||||||
|
|
@ -169,7 +176,7 @@ proc semCase(c: PContext, n: PNode): PNode =
|
||||||
checkSonsLen(x, 1)
|
checkSonsLen(x, 1)
|
||||||
x.sons[0] = semStmtScope(c, x.sons[0])
|
x.sons[0] = semStmtScope(c, x.sons[0])
|
||||||
else: illFormedAst(x)
|
else: illFormedAst(x)
|
||||||
if chckCovered and (covered != lengthOrd(n.sons[0].typ)):
|
if chckCovered and (covered != toCover(n.sons[0].typ)):
|
||||||
liMessage(n.info, errNotAllCasesCovered)
|
liMessage(n.info, errNotAllCasesCovered)
|
||||||
closeScope(c.tab)
|
closeScope(c.tab)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -275,9 +275,8 @@ proc semBranchExpr(c: PContext, t: PNode, ex: var PNode) =
|
||||||
|
|
||||||
proc SemCaseBranch(c: PContext, t, branch: PNode, branchIndex: int,
|
proc SemCaseBranch(c: PContext, t, branch: PNode, branchIndex: int,
|
||||||
covered: var biggestInt) =
|
covered: var biggestInt) =
|
||||||
var b: PNode
|
|
||||||
for i in countup(0, sonsLen(branch) - 2):
|
for i in countup(0, sonsLen(branch) - 2):
|
||||||
b = branch.sons[i]
|
var b = branch.sons[i]
|
||||||
if b.kind == nkRange:
|
if b.kind == nkRange:
|
||||||
checkSonsLen(b, 2)
|
checkSonsLen(b, 2)
|
||||||
semBranchExpr(c, t, b.sons[0])
|
semBranchExpr(c, t, b.sons[0])
|
||||||
|
|
|
||||||
16
tests/accept/compile/tenum2.nim
Executable file
16
tests/accept/compile/tenum2.nim
Executable file
|
|
@ -0,0 +1,16 @@
|
||||||
|
# Test that enum with holes is handled correctly by case statement
|
||||||
|
|
||||||
|
type
|
||||||
|
TEnumHole = enum
|
||||||
|
eA = 0,
|
||||||
|
eB = 4,
|
||||||
|
eC = 5
|
||||||
|
|
||||||
|
var
|
||||||
|
e: TEnumHole = eB
|
||||||
|
|
||||||
|
case e
|
||||||
|
of eA: echo "A"
|
||||||
|
of eB: echo "B"
|
||||||
|
of eC: echo "C"
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue