summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/sempass2.nim3
-rw-r--r--compiler/sigmatch.nim3
-rw-r--r--compiler/sinkparameter_inference.nim3
-rw-r--r--lib/pure/algorithm.nim2
-rw-r--r--tests/arc/tarcmisc.nim14
-rw-r--r--tests/arc/twrong_sinkinference.nim18
6 files changed, 36 insertions, 7 deletions
diff --git a/compiler/sempass2.nim b/compiler/sempass2.nim
index b801f4531..0fdf25850 100644
--- a/compiler/sempass2.nim
+++ b/compiler/sempass2.nim
@@ -854,7 +854,8 @@ proc track(tracked: PEffects, n: PNode) =
     when false: cstringCheck(tracked, n)
     if tracked.owner.kind != skMacro:
       createTypeBoundOps(tracked, n[0].typ, n.info)
-    checkForSink(tracked.config, tracked.owner, n[1])
+    if n[0].kind != nkSym or not isLocalVar(tracked, n[0].sym):
+      checkForSink(tracked.config, tracked.owner, n[1])
   of nkVarSection, nkLetSection:
     for child in n:
       let last = lastSon(child)
diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim
index 6c8f926dd..e209f5d78 100644
--- a/compiler/sigmatch.nim
+++ b/compiler/sigmatch.nim
@@ -548,7 +548,8 @@ proc allowsNilDeprecated(c: TCandidate, f: PType): TTypeRelation =
     result = isNone
 
 proc inconsistentVarTypes(f, a: PType): bool {.inline.} =
-  result = f.kind != a.kind and (f.kind in {tyVar, tyLent} or a.kind in {tyVar, tyLent})
+  result = f.kind != a.kind and
+    (f.kind in {tyVar, tyLent, tySink} or a.kind in {tyVar, tyLent, tySink})
 
 proc procParamTypeRel(c: var TCandidate, f, a: PType): TTypeRelation =
   ## For example we have:
diff --git a/compiler/sinkparameter_inference.nim b/compiler/sinkparameter_inference.nim
index 1becc250e..182e44324 100644
--- a/compiler/sinkparameter_inference.nim
+++ b/compiler/sinkparameter_inference.nim
@@ -48,8 +48,7 @@ proc checkForSink*(config: ConfigRef; owner: PSym; arg: PNode) =
         # we only report every potential 'sink' parameter only once:
         incl arg.sym.flags, sfWasForwarded
         message(config, arg.info, hintPerformance,
-          ("could not turn '$1' to a sink parameter " &
-          "because '$2' was forward declared") % [arg.sym.name.s, owner.name.s])
+          "could not turn '$1' to a sink parameter" % [arg.sym.name.s])
       #echo config $ arg.info, " candidate for a sink parameter here"
   of nkStmtList, nkStmtListExpr, nkBlockStmt, nkBlockExpr:
     if not isEmptyType(arg.typ):
diff --git a/lib/pure/algorithm.nim b/lib/pure/algorithm.nim
index ed1ca893d..91f2f41b8 100644
--- a/lib/pure/algorithm.nim
+++ b/lib/pure/algorithm.nim
@@ -504,7 +504,7 @@ template sortedByIt*(seq1, op: untyped): untyped =
     # Nested sort
     assert people.sortedByIt((it.age, it.name)) == @[(name: "p2", age: 20),
        (name: "p3", age: 30), (name: "p4", age: 30), (name: "p1", age: 60)]
-  var result = sorted(seq1, proc(x, y: type(seq1[0])): int =
+  var result = sorted(seq1, proc(x, y: typeof(seq1[0])): int =
     var it {.inject.} = x
     let a = op
     it = y
diff --git a/tests/arc/tarcmisc.nim b/tests/arc/tarcmisc.nim
index 963ae9806..ce8e902c6 100644
--- a/tests/arc/tarcmisc.nim
+++ b/tests/arc/tarcmisc.nim
@@ -46,7 +46,7 @@ type
 proc `=destroy`(x: var AObj) =
   close(x.io)
   echo "closed"
-  
+
 var x = B(io: newStringStream("thestream"))
 
 
@@ -64,4 +64,14 @@ proc main() =
   cryptCTR(nonce2.toOpenArray(0, nonce2.len-1))
   doAssert(nonce2 == "0A234567")
 
-main()
\ No newline at end of file
+main()
+
+# bug #14079
+import std/algorithm
+
+let
+  n = @["c", "b"]
+  q = @[("c", "2"), ("b", "1")]
+
+assert n.sortedByIt(it) == @["b", "c"], "fine"
+assert q.sortedByIt(it[0]) == @[("b", "1"), ("c", "2")], "fails under arc"
diff --git a/tests/arc/twrong_sinkinference.nim b/tests/arc/twrong_sinkinference.nim
new file mode 100644
index 000000000..59930a9fa
--- /dev/null
+++ b/tests/arc/twrong_sinkinference.nim
@@ -0,0 +1,18 @@
+discard """
+  cmd: "nim c --gc:arc $file"
+  errormsg: "type mismatch: got <proc (a: string, b: sink string){.noSideEffect, gcsafe, locks: 0.}>"
+  line: 18
+"""
+
+type
+  Foo = proc (a, b: string)
+
+proc take(x: Foo) =
+  x("a", "b")
+
+proc willSink(a, b: string) = # {.nosinks.} =
+  var arr: array[3, string]
+  var x = a
+  arr[0] = b
+
+take willSink