Converter bug fixes (#9700)

* Fixes #9698
* Fixes #9699
This commit is contained in:
cooldome 2018-11-15 12:14:48 +00:00 • committed by Andreas Rumpf
commit c5c4da4f3c
4 changed files with 118 additions and 2 deletions

View file

@ -138,6 +138,7 @@ proc effectProblem(f, a: PType; result: var string) =
proc renderNotLValue(n: PNode): string =
result = $n
let n = if n.kind == nkHiddenDeref: n[0] else: n
if n.kind == nkHiddenCallConv and n.len > 1:
result = $n[0] & "(" & result & ")"
elif n.kind in {nkHiddenStdConv, nkHiddenSubConv} and n.len == 2:
@ -394,6 +395,7 @@ proc resolveOverloads(c: PContext, n, orig: PNode,
args])
proc instGenericConvertersArg*(c: PContext, a: PNode, x: TCandidate) =
let a = if a.kind == nkHiddenDeref: a[0] else: a
if a.kind == nkHiddenCallConv and a.sons[0].kind == nkSym:
let s = a.sons[0].sym
if s.ast != nil and s.ast[genericParamsPos].kind != nkEmpty:

View file

@ -640,6 +640,7 @@ proc analyseIfAddressTakenInCall(c: PContext, n: PNode) =
return
for i in countup(1, sonsLen(n) - 1):
let n = if n.kind == nkHiddenDeref: n[0] else: n
if n.sons[i].kind == nkHiddenCallConv:
# we need to recurse explicitly here as converters can create nested
# calls and then they wouldn't be analysed otherwise

View file

@ -13,7 +13,7 @@
import
intsets, ast, astalgo, semdata, types, msgs, renderer, lookups, semtypinst,
magicsys, condsyms, idents, lexer, options, parampatterns, strutils, trees,
linter, lineinfos, modulegraphs
linter, lineinfos, lowerings, modulegraphs
when (defined(booting) or defined(nimsuggest)) and not defined(leanCompiler):
import docgen
@ -1855,8 +1855,14 @@ proc userConvMatch(c: PContext, m: var TCandidate, f, a: PType,
else:
param = copyTree(arg)
addSon(result, param)
if dest.kind in {tyVar, tyLent}:
dest.flags.incl tfVarIsPtr
result = newDeref(result)
inc(m.convMatches)
m.genericConverter = srca == isGeneric or destIsGeneric
if m.genericConverter == false:
m.genericConverter = srca == isGeneric or destIsGeneric
return result
proc localConvMatch(c: PContext, m: var TCandidate, f, a: PType,