Handle subtype relations for converter parameters (#8248)

Fixes #7098
This commit is contained in:
LemonBoy 2018-07-09 20:05:53 +02:00 • committed by Andreas Rumpf
commit 5c5388c0a6
2 changed files with 38 additions and 2 deletions

View file

@ -1801,7 +1801,7 @@ proc userConvMatch(c: PContext, m: var TCandidate, f, a: PType,
# 'f <- dest' in order to not break the unification:
# see tests/tgenericconverter:
let srca = typeRel(m, src, a)
if srca notin {isEqual, isGeneric}: continue
if srca notin {isEqual, isGeneric, isSubtype}: continue
let destIsGeneric = containsGenericType(dest)
if destIsGeneric:
@ -1814,7 +1814,12 @@ proc userConvMatch(c: PContext, m: var TCandidate, f, a: PType,
s.info = arg.info
result = newNodeIT(nkHiddenCallConv, arg.info, dest)
addSon(result, s)
addSon(result, copyTree(arg))
var param: PNode = nil
if srca == isSubtype:
param = implicitConv(nkHiddenSubConv, src, copyTree(arg), m, c)
else:
param = copyTree(arg)
addSon(result, param)
inc(m.convMatches)
m.genericConverter = srca == isGeneric or destIsGeneric
return result