From 9ebfa7973a09439ba76ea477dad0ddf3bf433e4a Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Thu, 13 Mar 2025 00:31:19 +0800 Subject: [PATCH] fixes generic types `sink T` cannot be inferred for passed arguments (#24761) Otherwise, `sink T` is kept as it is. This PR treats sink types as its base types for the arguments. So the concept would match both cases Required by https://github.com/nim-lang/Nim/pull/24724 --- compiler/sigmatch.nim | 5 +++-- tests/concepts/tconcept_old.nim | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 tests/concepts/tconcept_old.nim diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index 47d155e192..da5452b2bf 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -1234,9 +1234,10 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, else: var candidate = f - case f.kind + let fType = f.skipTypes({tySink}) + case fType.kind of tyGenericParam: - var prev = lookup(c.bindings, f) + var prev = lookup(c.bindings, fType) if prev != nil: candidate = prev of tyFromExpr: let computedType = tryResolvingStaticExpr(c, f.n).typ diff --git a/tests/concepts/tconcept_old.nim b/tests/concepts/tconcept_old.nim new file mode 100644 index 0000000000..9459d66410 --- /dev/null +++ b/tests/concepts/tconcept_old.nim @@ -0,0 +1,18 @@ +type + Map[K, V] = concept m, var mvar + m[K] is V + m[K] = V + + Table[K, V] = object + +proc `[]=`[K, V](m: Table[K, V], x: sink K, y: sink V) = + let s = x + +proc `[]`[K, V](m: Table[K, V], x: sink K): V = + let s = x + +proc bat[K, V](x: Map[K, V]): V = + let m = x + +var s = Table[int, string]() +discard bat(s)