Skip to content

Commit 9ebfa79

Browse files
authored
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 #24724
1 parent 4f32624 commit 9ebfa79

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

compiler/sigmatch.nim

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,9 +1234,10 @@ proc typeRel(c: var TCandidate, f, aOrig: PType,
12341234
else:
12351235
var candidate = f
12361236

1237-
case f.kind
1237+
let fType = f.skipTypes({tySink})
1238+
case fType.kind
12381239
of tyGenericParam:
1239-
var prev = lookup(c.bindings, f)
1240+
var prev = lookup(c.bindings, fType)
12401241
if prev != nil: candidate = prev
12411242
of tyFromExpr:
12421243
let computedType = tryResolvingStaticExpr(c, f.n).typ

tests/concepts/tconcept_old.nim

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
type
2+
Map[K, V] = concept m, var mvar
3+
m[K] is V
4+
m[K] = V
5+
6+
Table[K, V] = object
7+
8+
proc `[]=`[K, V](m: Table[K, V], x: sink K, y: sink V) =
9+
let s = x
10+
11+
proc `[]`[K, V](m: Table[K, V], x: sink K): V =
12+
let s = x
13+
14+
proc bat[K, V](x: Map[K, V]): V =
15+
let m = x
16+
17+
var s = Table[int, string]()
18+
discard bat(s)

0 commit comments

Comments
 (0)