summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorcooldome <cdome@bk.ru>2020-03-16 12:40:40 +0000
committerGitHub <noreply@github.com>2020-03-16 13:40:40 +0100
commit613ea6e85e8289fee92c396e07f8f1b2a991167f (patch)
tree41316bed21fa3a3ad5230f9183b401597863cbaf
parentfe53f6ef4f4fe296d70c68b8c56d3c8afa06a168 (diff)
downloadNim-613ea6e85e8289fee92c396e07f8f1b2a991167f.tar.gz
fixes #12747 [backport] (#13651)
* fixes #12747
* fix tests
* improve code style

Co-authored-by: cooldome <ariabushenko@bk.ru>
-rw-r--r--compiler/transf.nim15
-rw-r--r--tests/destructor/tgcdestructors.nim2
-rw-r--r--tests/destructor/twidgets_unown.nim2
-rw-r--r--tests/iter/titer11.nim11
4 files changed, 25 insertions, 5 deletions
diff --git a/compiler/transf.nim b/compiler/transf.nim
index cd5eaa100..c1af6c23f 100644
--- a/compiler/transf.nim
+++ b/compiler/transf.nim
@@ -565,10 +565,19 @@ proc putArgInto(arg: PNode, formal: PType): TPutArgInto =
   case arg.kind
   of nkEmpty..nkNilLit:
     result = paDirectMapping
-  of nkPar, nkTupleConstr, nkCurly, nkBracket:
-    result = paFastAsgn
+  of nkDotExpr, nkDerefExpr, nkHiddenDeref, nkAddr, nkHiddenAddr:
+    result = putArgInto(arg[0], formal)
+  of nkCurly, nkBracket:
     for i in 0..<arg.len:
-      if putArgInto(arg[i], formal) != paDirectMapping: return
+      if putArgInto(arg[i], formal) != paDirectMapping: 
+        return paFastAsgn
+    result = paDirectMapping
+  of nkPar, nkTupleConstr, nkObjConstr:
+    for i in 0..<arg.len:
+      let a = if arg[i].kind == nkExprColonExpr: arg[i][1]
+              else: arg[0]
+      if putArgInto(a, formal) != paDirectMapping: 
+        return paFastAsgn
     result = paDirectMapping
   else:
     if skipTypes(formal, abstractInst).kind in {tyVar, tyLent}: result = paVarAsgn
diff --git a/tests/destructor/tgcdestructors.nim b/tests/destructor/tgcdestructors.nim
index 7169daaf1..e089aedd1 100644
--- a/tests/destructor/tgcdestructors.nim
+++ b/tests/destructor/tgcdestructors.nim
@@ -10,7 +10,7 @@ a: @[4, 2, 3]
 0
 30
 true
-(allocCount: 41, deallocCount: 41)'''
+(allocCount: 40, deallocCount: 40)'''
 """
 
 include system / ansi_c
diff --git a/tests/destructor/twidgets_unown.nim b/tests/destructor/twidgets_unown.nim
index 1d2f26f2a..3a3c4c665 100644
--- a/tests/destructor/twidgets_unown.nim
+++ b/tests/destructor/twidgets_unown.nim
@@ -2,7 +2,7 @@ discard """
   cmd: '''nim c -d:nimAllocStats --newruntime $file'''
   output: '''button
 clicked!
-(allocCount: 9, deallocCount: 9)'''
+(allocCount: 7, deallocCount: 7)'''
 """
 
 import system / ansi_c
diff --git a/tests/iter/titer11.nim b/tests/iter/titer11.nim
index c4c7d4a16..2b39c74f7 100644
--- a/tests/iter/titer11.nim
+++ b/tests/iter/titer11.nim
@@ -26,3 +26,14 @@ var output = represent(s)
 
 for item in output():
   echo item
+
+
+#------------------------------------------------------------------------------
+# Issue #12747
+
+type
+  ABC = ref object
+      arr: array[0x40000, pointer]
+let a = ABC()
+for a in a.arr:
+    assert a == nil
\ No newline at end of file