Fixes 6544 (#9427)
* Fix call to converters with var/lent args Fixes #6544 * Fix printing of lent types * lent is only valid for result types
This commit is contained in:
parent
d0dd5ea887
commit
16a70c84aa
3 changed files with 20 additions and 1 deletions
|
|
@ -1826,9 +1826,12 @@ proc userConvMatch(c: PContext, m: var TCandidate, f, a: PType,
|
||||||
let srca = typeRel(m, src, a)
|
let srca = typeRel(m, src, a)
|
||||||
if srca notin {isEqual, isGeneric, isSubtype}: continue
|
if srca notin {isEqual, isGeneric, isSubtype}: continue
|
||||||
|
|
||||||
|
# What's done below matches the logic in ``matchesAux``
|
||||||
let constraint = c.converters[i].typ.n[1].sym.constraint
|
let constraint = c.converters[i].typ.n[1].sym.constraint
|
||||||
if not constraint.isNil and not matchNodeKinds(constraint, arg):
|
if not constraint.isNil and not matchNodeKinds(constraint, arg):
|
||||||
continue
|
continue
|
||||||
|
if src.kind in {tyVar, tyLent} and not arg.isLValue:
|
||||||
|
continue
|
||||||
|
|
||||||
let destIsGeneric = containsGenericType(dest)
|
let destIsGeneric = containsGenericType(dest)
|
||||||
if destIsGeneric:
|
if destIsGeneric:
|
||||||
|
|
@ -1841,9 +1844,16 @@ proc userConvMatch(c: PContext, m: var TCandidate, f, a: PType,
|
||||||
s.info = arg.info
|
s.info = arg.info
|
||||||
result = newNodeIT(nkHiddenCallConv, arg.info, dest)
|
result = newNodeIT(nkHiddenCallConv, arg.info, dest)
|
||||||
addSon(result, s)
|
addSon(result, s)
|
||||||
|
# We build the call expression by ourselves in order to avoid passing this
|
||||||
|
# expression trough the semantic check phase once again so let's make sure
|
||||||
|
# it is correct
|
||||||
var param: PNode = nil
|
var param: PNode = nil
|
||||||
if srca == isSubtype:
|
if srca == isSubtype:
|
||||||
param = implicitConv(nkHiddenSubConv, src, copyTree(arg), m, c)
|
param = implicitConv(nkHiddenSubConv, src, copyTree(arg), m, c)
|
||||||
|
elif src.kind == tyVar:
|
||||||
|
# Analyse the converter return type
|
||||||
|
param = newNodeIT(nkHiddenAddr, arg.info, s.typ[1])
|
||||||
|
param.addSon(copyTree(arg))
|
||||||
else:
|
else:
|
||||||
param = copyTree(arg)
|
param = copyTree(arg)
|
||||||
addSon(result, param)
|
addSon(result, param)
|
||||||
|
|
|
||||||
|
|
@ -397,7 +397,7 @@ const
|
||||||
"float", "float32", "float64", "float128",
|
"float", "float32", "float64", "float128",
|
||||||
"uint", "uint8", "uint16", "uint32", "uint64",
|
"uint", "uint8", "uint16", "uint32", "uint64",
|
||||||
"opt", "sink",
|
"opt", "sink",
|
||||||
"lent", "varargs[$1]", "UncheckedArray[$1]", "Error Type",
|
"lent ", "varargs[$1]", "UncheckedArray[$1]", "Error Type",
|
||||||
"BuiltInTypeClass", "UserTypeClass",
|
"BuiltInTypeClass", "UserTypeClass",
|
||||||
"UserTypeClassInst", "CompositeTypeClass", "inferred",
|
"UserTypeClassInst", "CompositeTypeClass", "inferred",
|
||||||
"and", "or", "not", "any", "static", "TypeFromExpr", "FieldAccessor",
|
"and", "or", "not", "any", "static", "TypeFromExpr", "FieldAccessor",
|
||||||
|
|
@ -1176,6 +1176,7 @@ proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind,
|
||||||
case t.kind
|
case t.kind
|
||||||
of tyVar, tyLent:
|
of tyVar, tyLent:
|
||||||
if kind in {skProc, skFunc, skConst}: return t
|
if kind in {skProc, skFunc, skConst}: return t
|
||||||
|
elif t.kind == tyLent and kind != skResult: return t
|
||||||
var t2 = skipTypes(t.sons[0], abstractInst-{tyTypeDesc})
|
var t2 = skipTypes(t.sons[0], abstractInst-{tyTypeDesc})
|
||||||
case t2.kind
|
case t2.kind
|
||||||
of tyVar, tyLent:
|
of tyVar, tyLent:
|
||||||
|
|
|
||||||
|
|
@ -18,3 +18,11 @@ converter toPtr*(some: var TFoo): ptr TFoo = (addr some)
|
||||||
proc zoot(x: ptr TFoo) = discard
|
proc zoot(x: ptr TFoo) = discard
|
||||||
var x: Tfoo
|
var x: Tfoo
|
||||||
zoot(x)
|
zoot(x)
|
||||||
|
|
||||||
|
# issue #6544
|
||||||
|
converter withVar(b: var string): int = ord(b[1])
|
||||||
|
|
||||||
|
block:
|
||||||
|
var x = "101"
|
||||||
|
var y: int = x # instantiate withVar
|
||||||
|
doAssert(y == ord('0'))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue