summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorLemonBoy <LemonBoy@users.noreply.github.com>2018-06-29 15:10:51 +0200
committerAndreas Rumpf <rumpf_a@web.de>2018-06-29 15:10:51 +0200
commit64c84a7d11697a03a7b2e54a5ef4bffa099535fe (patch)
tree54a269e0c733203105eb979519e354e9f6310aa1 /compiler
parent7674df0dffc8746a9377ed9680b179118f14a0cd (diff)
downloadNim-64c84a7d11697a03a7b2e54a5ef4bffa099535fe.tar.gz
Fix codegen for mInSet magic and empty sets (#8140)
Fixes #8041
Diffstat (limited to 'compiler')
-rw-r--r--compiler/ccgexprs.nim30
1 files changed, 17 insertions, 13 deletions
diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim
index 0e8af5af5..56dd0dea2 100644
--- a/compiler/ccgexprs.nim
+++ b/compiler/ccgexprs.nim
@@ -1587,20 +1587,24 @@ proc genInOp(p: BProc, e: PNode, d: var TLoc) =
                e.sons[2]
     initLocExpr(p, ea, a)
     initLoc(b, locExpr, e, OnUnknown)
-    b.r = rope("(")
     var length = sonsLen(e.sons[1])
-    for i in countup(0, length - 1):
-      let it = e.sons[1].sons[i]
-      if it.kind == nkRange:
-        initLocExpr(p, it.sons[0], x)
-        initLocExpr(p, it.sons[1], y)
-        addf(b.r, "$1 >= $2 && $1 <= $3",
-             [rdCharLoc(a), rdCharLoc(x), rdCharLoc(y)])
-      else:
-        initLocExpr(p, it, x)
-        addf(b.r, "$1 == $2", [rdCharLoc(a), rdCharLoc(x)])
-      if i < length - 1: add(b.r, " || ")
-    add(b.r, ")")
+    if length > 0:
+      b.r = rope("(")
+      for i in countup(0, length - 1):
+        let it = e.sons[1].sons[i]
+        if it.kind == nkRange:
+          initLocExpr(p, it.sons[0], x)
+          initLocExpr(p, it.sons[1], y)
+          addf(b.r, "$1 >= $2 && $1 <= $3",
+               [rdCharLoc(a), rdCharLoc(x), rdCharLoc(y)])
+        else:
+          initLocExpr(p, it, x)
+          addf(b.r, "$1 == $2", [rdCharLoc(a), rdCharLoc(x)])
+        if i < length - 1: add(b.r, " || ")
+      add(b.r, ")")
+    else:
+      # handle the case of an empty set
+      b.r = rope("0")
     putIntoDest(p, d, e, b.r)
   else:
     assert(e.sons[1].typ != nil)