summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/ccgexprs.nim3
-rw-r--r--compiler/cgen.nim1
-rw-r--r--tests/destructor/tgcdestructors.nim22
3 files changed, 14 insertions, 12 deletions
diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim
index 7376dd374..ece452602 100644
--- a/compiler/ccgexprs.nim
+++ b/compiler/ccgexprs.nim
@@ -1145,7 +1145,8 @@ proc genReset(p: BProc, n: PNode) =
           genTypeInfo(p.module, skipTypes(a.t, {tyVar}), n.info))
 
 proc genDefault(p: BProc; n: PNode; d: var TLoc) =
-  resetLoc(p, d)
+  if d.k == locNone: getTemp(p, n.typ, d, needsInit=true)
+  else: resetLoc(p, d)
 
 proc rawGenNew(p: BProc, a: TLoc, sizeExpr: Rope) =
   var sizeExpr = sizeExpr
diff --git a/compiler/cgen.nim b/compiler/cgen.nim
index b44931fb0..3114a7f70 100644
--- a/compiler/cgen.nim
+++ b/compiler/cgen.nim
@@ -328,6 +328,7 @@ proc resetLoc(p: BProc, loc: var TLoc) =
   let typ = skipTypes(loc.t, abstractVarRange)
   if isImportedCppType(typ): return
   if p.config.selectedGc == gcDestructors and typ.kind in {tyString, tySequence}:
+    assert rdLoc(loc) != nil
     linefmt(p, cpsStmts, "$1.len = 0; $1.p = NIM_NIL;$n", rdLoc(loc))
   elif not isComplexValueType(typ):
     if containsGcRef:
diff --git a/tests/destructor/tgcdestructors.nim b/tests/destructor/tgcdestructors.nim
index daf1925ec..31631ac80 100644
--- a/tests/destructor/tgcdestructors.nim
+++ b/tests/destructor/tgcdestructors.nim
@@ -1,10 +1,9 @@
 discard """
-  disabled: true
-  cmd: '''nim c --gc:destructors $file'''
+  cmd: '''nim c --newruntime $file'''
   output: '''hi
 ho
 ha
-7 7'''
+1 1'''
 """
 
 import allocators
@@ -76,15 +75,16 @@ iterator interpolatedFragments*(s: string): tuple[kind: InterpolatedKind,
       break
     i = j
 
-let input = "$test{}  $this is ${an{  example}}  "
-let expected = @[(ikVar, "test"), (ikStr, "{}  "), (ikVar, "this"),
-                (ikStr, " is "), (ikExpr, "an{  example}"), (ikStr, "  ")]
-var i = 0
-for s in interpolatedFragments(input):
-  doAssert s == expected[i]
-  inc i
+when false:
+  let input = "$test{}  $this is ${an{  example}}  "
+  let expected = @[(ikVar, "test"), (ikStr, "{}  "), (ikVar, "this"),
+                  (ikStr, " is "), (ikExpr, "an{  example}"), (ikStr, "  ")]
+  var i = 0
+  for s in interpolatedFragments(input):
+    doAssert s == expected[i]
+    inc i
 
 
 #echo s
 let (a, d) = allocCounters()
-cprintf("%ld %ld\n", a, d)
+discard cprintf("%ld %ld\n", a, d)