Skip to content

Commit 8c9a645

Browse files
authored
fix generic converter regression with var/subtype args (#24902)
refs #24867, #24867 (comment) The argument node of the converter can be wrapped in [hidden `addr` or subtype conversion nodes](https://github.com/nim-lang/Nim/blob/dc100c5caa673b039155e9e5d4c7fc0c239f4eb5/compiler/sigmatch.nim#L2327-L2335) which have to be skipped when matching the type again, since the type of the node is the uninstantiated type taken from the proc parameter.
1 parent 5dcfd8d commit 8c9a645

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

compiler/semcall.nim

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,9 @@ proc instGenericConvertersArg*(c: PContext, a: PNode, x: TCandidate) =
688688
if s.isGenericRoutineStrict:
689689
var src = s.typ.firstParamType
690690
var convMatch = newCandidate(c, src)
691-
let srca = typeRel(convMatch, src, a[1].typ)
691+
var arg = a[1]
692+
if arg.kind in {nkHiddenAddr, nkHiddenSubConv}: arg = arg[^1]
693+
let srca = typeRel(convMatch, src, arg.typ)
692694
if srca notin {isEqual, isGeneric, isSubtype}:
693695
internalError(c.config, a.info, "generic converter failed rematch")
694696
let finalCallee = generateInstance(c, s, convMatch.bindings, a.info)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# regression test
2+
3+
converter toPtr[T](x: var T): ptr T =
4+
result = addr x
5+
6+
var x = 123
7+
let y: ptr int = x

0 commit comments

Comments
 (0)