summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2019-09-02 15:49:01 +0200
committerGitHub <noreply@github.com>2019-09-02 15:49:01 +0200
commitf8f96d816cdd1a8edc3f1582a76ae483035f6a37 (patch)
tree396ab5cf59d41fd8bf58a63a39e58b5f21c8a334
parent7ef85db9a9e3df4d6630673ceac33e9fb986e2ed (diff)
parentba18c12005ddbf4859fac3a04ebb149ee20532b0 (diff)
downloadNim-f8f96d816cdd1a8edc3f1582a76ae483035f6a37.tar.gz
sink as lvalue (#12108)
-rw-r--r--compiler/parampatterns.nim6
-rw-r--r--tests/destructor/tnewruntime_misc.nim13
2 files changed, 16 insertions, 3 deletions
diff --git a/compiler/parampatterns.nim b/compiler/parampatterns.nim
index 1bd703fe8..b8f1fd832 100644
--- a/compiler/parampatterns.nim
+++ b/compiler/parampatterns.nim
@@ -224,14 +224,14 @@ proc isAssignable*(owner: PSym, n: PNode; isUnsafeAddr=false): TAssignableResult
         result = arLocalLValue
       else:
         result = arLValue
-    elif n.sym.kind == skParam and n.sym.typ.kind == tyVar:
+    elif n.sym.kind == skParam and n.sym.typ.kind in {tyVar, tySink}:
       result = arLValue
     elif n.sym.kind == skType:
       let t = n.sym.typ.skipTypes({tyTypeDesc})
       if t.kind == tyVar: result = arStrange
   of nkDotExpr:
     let t = skipTypes(n.sons[0].typ, abstractInst-{tyTypeDesc})
-    if t.kind in {tyVar, tyPtr, tyRef}:
+    if t.kind in {tyVar, tySink, tyPtr, tyRef}:
       result = arLValue
     elif isUnsafeAddr and t.kind == tyLent:
       result = arLValue
@@ -242,7 +242,7 @@ proc isAssignable*(owner: PSym, n: PNode; isUnsafeAddr=false): TAssignableResult
       result = arDiscriminant
   of nkBracketExpr:
     let t = skipTypes(n.sons[0].typ, abstractInst-{tyTypeDesc})
-    if t.kind in {tyVar, tyPtr, tyRef}:
+    if t.kind in {tyVar, tySink, tyPtr, tyRef}:
       result = arLValue
     elif isUnsafeAddr and t.kind == tyLent:
       result = arLValue
diff --git a/tests/destructor/tnewruntime_misc.nim b/tests/destructor/tnewruntime_misc.nim
index d6c03b9b0..8abf0d30b 100644
--- a/tests/destructor/tnewruntime_misc.nim
+++ b/tests/destructor/tnewruntime_misc.nim
@@ -85,3 +85,16 @@ testWrongAt()
 
 let (a, d) = allocCounters()
 discard cprintf("%ld  new: %ld\n", a - unpairedEnvAllocs() - d, allocs)
+
+#-------------------------------------------------
+type
+  Table[A, B] = object
+    x: seq[(A, B)]
+
+
+proc toTable[A,B](p: sink openArray[(A, B)]): Table[A, B] = 
+  for zz in mitems(p):
+    result.x.add move(zz)
+
+
+let table = {"a": new(int)}.toTable()