summary refs log tree commit diff stats
path: root/rod
diff options
context:
space:
mode:
authorAndreas Rumpf <andreas@andreas-desktop>2010-03-09 21:36:11 +0100
committerAndreas Rumpf <andreas@andreas-desktop>2010-03-09 21:36:11 +0100
commit7dff3e64bbb44cfc57314038c2c047f2ccb1da1e (patch)
tree47ca722cbdc80347fb325283d03212d4bb4df2e9 /rod
parentfe4cc78294fc3eed5335690e155a78dc119e39a8 (diff)
downloadNim-7dff3e64bbb44cfc57314038c2c047f2ccb1da1e.tar.gz
bugfix: wrong error: not all cases covered with enums with holes
Diffstat (limited to 'rod')
-rwxr-xr-xrod/semstmts.nim9
-rwxr-xr-xrod/semtypes.nim3
2 files changed, 9 insertions, 3 deletions
diff --git a/rod/semstmts.nim b/rod/semstmts.nim
index f792dc691..b07e724bc 100755
--- a/rod/semstmts.nim
+++ b/rod/semstmts.nim
@@ -136,6 +136,13 @@ proc semWhile(c: PContext, n: PNode): PNode =
   dec(c.p.nestedLoopCounter)
   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 = 
   # check selector:
   result = n
@@ -169,7 +176,7 @@ proc semCase(c: PContext, n: PNode): PNode =
       checkSonsLen(x, 1)
       x.sons[0] = semStmtScope(c, x.sons[0])
     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)
   closeScope(c.tab)
 
diff --git a/rod/semtypes.nim b/rod/semtypes.nim
index c4fadac8a..f4b17f071 100755
--- a/rod/semtypes.nim
+++ b/rod/semtypes.nim
@@ -275,9 +275,8 @@ proc semBranchExpr(c: PContext, t: PNode, ex: var PNode) =
 
 proc SemCaseBranch(c: PContext, t, branch: PNode, branchIndex: int, 
                    covered: var biggestInt) = 
-  var b: PNode
   for i in countup(0, sonsLen(branch) - 2): 
-    b = branch.sons[i]
+    var b = branch.sons[i]
     if b.kind == nkRange: 
       checkSonsLen(b, 2)
       semBranchExpr(c, t, b.sons[0])