summary refs log tree commit diff stats
path: root/compiler/ccgexprs.nim
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2019-12-23 13:05:30 +0100
committerAndreas Rumpf <rumpf_a@web.de>2019-12-24 17:33:27 +0100
commit6152eb3be3610654cd57fae67fd07559a8f928f9 (patch)
tree28670b7cda8912c77104972f6cf37f81ef331957 /compiler/ccgexprs.nim
parent767bd572899b60eec626c9193ba84f1ba3ffe472 (diff)
downloadNim-6152eb3be3610654cd57fae67fd07559a8f928f9.tar.gz
a better bugfix
Diffstat (limited to 'compiler/ccgexprs.nim')
-rw-r--r--compiler/ccgexprs.nim63
1 files changed, 33 insertions, 30 deletions
diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim
index 9fca9604d..44a9b794b 100644
--- a/compiler/ccgexprs.nim
+++ b/compiler/ccgexprs.nim
@@ -2876,44 +2876,47 @@ proc genBracedInit(p: BProc, n: PNode; isConst: bool): Rope =
   case n.kind
   of nkHiddenStdConv, nkHiddenSubConv:
     result = genBracedInit(p, n[1], isConst)
-  of nkCurly:
-    var cs: TBitSet
-    toBitSet(p.config, n, cs)
-    result = genRawSetData(cs, int(getSize(p.config, n.typ)))
-  of nkBracket, nkPar, nkTupleConstr, nkClosure:
+  else:
     var t = skipTypes(n.typ, abstractInstOwned)
-    if t.kind == tySequence:
+    case t.kind
+    of tySet:
+      var cs: TBitSet
+      toBitSet(p.config, n, cs)
+      result = genRawSetData(cs, int(getSize(p.config, n.typ)))
+    of tySequence:
       if optSeqDestructors in p.config.globalOptions:
         result = genConstSeqV2(p, n, n.typ, isConst)
       else:
         result = genConstSeq(p, n, n.typ, isConst)
-    elif t.kind == tyProc and t.callConv == ccClosure and n.len > 1 and
-         n[1].kind == nkNilLit:
-      # Conversion: nimcall -> closure.
-      # this hack fixes issue that nkNilLit is expanded to {NIM_NIL,NIM_NIL}
-      # this behaviour is needed since closure_var = nil must be
-      # expanded to {NIM_NIL,NIM_NIL}
-      # in VM closures are initialized with nkPar(nkNilLit, nkNilLit)
-      # leading to duplicate code like this:
-      # "{NIM_NIL,NIM_NIL}, {NIM_NIL,NIM_NIL}"
-      if n[0].kind == nkNilLit:
-        result = ~"{NIM_NIL,NIM_NIL}"
+    of tyProc:
+      if t.callConv == ccClosure and n.len > 1 and n[1].kind == nkNilLit:
+        # Conversion: nimcall -> closure.
+        # this hack fixes issue that nkNilLit is expanded to {NIM_NIL,NIM_NIL}
+        # this behaviour is needed since closure_var = nil must be
+        # expanded to {NIM_NIL,NIM_NIL}
+        # in VM closures are initialized with nkPar(nkNilLit, nkNilLit)
+        # leading to duplicate code like this:
+        # "{NIM_NIL,NIM_NIL}, {NIM_NIL,NIM_NIL}"
+        if n[0].kind == nkNilLit:
+          result = ~"{NIM_NIL,NIM_NIL}"
+        else:
+          var d: TLoc
+          initLocExpr(p, n[0], d)
+          result = "{(($1) $2),NIM_NIL}" % [getClosureType(p.module, t, clHalfWithEnv), rdLoc(d)]
       else:
-        var d: TLoc
-        initLocExpr(p, n[0], d)
-        result = "{(($1) $2),NIM_NIL}" % [getClosureType(p.module, t, clHalfWithEnv), rdLoc(d)]
-    else:
+        result = ~"NIM_NIL"
+    of tyArray, tyTuple, tyOpenArray, tyVarargs:
       result = genConstSimpleList(p, n, isConst)
-  of nkObjConstr:
-    result = genConstObjConstr(p, n, isConst)
-  of nkStrLit..nkTripleStrLit:
-    if optSeqDestructors in p.config.globalOptions:
-      result = genStringLiteralV2Const(p.module, n, isConst)
+    of tyObject:
+      result = genConstObjConstr(p, n, isConst)
+    of tyString, tyCString:
+      if optSeqDestructors in p.config.globalOptions and n.kind != nkNilLit:
+        result = genStringLiteralV2Const(p.module, n, isConst)
+      else:
+        var d: TLoc
+        initLocExpr(p, n, d)
+        result = rdLoc(d)
     else:
       var d: TLoc
       initLocExpr(p, n, d)
       result = rdLoc(d)
-  else:
-    var d: TLoc
-    initLocExpr(p, n, d)
-    result = rdLoc(d)