summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorHans Raaf <hara@oderwat.de>2015-02-20 23:07:05 +0100
committerHans Raaf <hara@oderwat.de>2015-02-24 14:54:27 +0100
commit79384ea729075a2242923bf28ee1d3513a174d9b (patch)
treedc5f1fce2424cdd735b0cb610a9e318c753218fb /compiler
parent7324ed7f1fb5a265de57c95e08a5b4044c662d0e (diff)
downloadNim-79384ea729075a2242923bf28ee1d3513a174d9b.tar.gz
Allow empty sets in case/of branches.
Added support for conditional compilation using 'when' with empty sets and arrays in
'case of' branches.

 Please enter the commit message for your changes. Lines starting
Diffstat (limited to 'compiler')
-rw-r--r--compiler/semtypes.nim8
1 files changed, 6 insertions, 2 deletions
diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim
index d9c7b6c92..32a384f97 100644
--- a/compiler/semtypes.nim
+++ b/compiler/semtypes.nim
@@ -452,6 +452,7 @@ proc semCaseBranchSetElem(c: PContext, t, b: PNode,
 
 proc semCaseBranch(c: PContext, t, branch: PNode, branchIndex: int, 
                    covered: var BiggestInt) = 
+  
   for i in countup(0, sonsLen(branch) - 2): 
     var b = branch.sons[i]
     if b.kind == nkRange:
@@ -461,8 +462,11 @@ proc semCaseBranch(c: PContext, t, branch: PNode, branchIndex: int,
     else:
       # constant sets and arrays are allowed:
       var r = semConstExpr(c, b)
-      # for ``{}`` we want to trigger the type mismatch in ``fitNode``:
-      if r.kind notin {nkCurly, nkBracket} or len(r) == 0:
+      if r.kind in {nkCurly, nkBracket} and len(r) == 0  and sonsLen(branch)==2:
+        # discarding ``{}`` and ``[]`` branches silently
+        delSon(branch, 0)
+        return
+      elif r.kind notin {nkCurly, nkBracket} or len(r) == 0:
         checkMinSonsLen(t, 1)
         branch.sons[i] = skipConv(fitNode(c, t.sons[0].typ, r))
         inc(covered)