Specify that address is taken when converter takes a var parameter (#21391)
* Add test case * closes #21247 Add the sfAddrTaken flag to var parameters in converters This allows the JS backend to properly pass the parameter as a fat pointer
This commit is contained in:
parent
de65b380ed
commit
0a45543cc1
2 changed files with 16 additions and 0 deletions
|
|
@ -1980,6 +1980,7 @@ proc userConvMatch(c: PContext, m: var TCandidate, f, a: PType,
|
||||||
param = implicitConv(nkHiddenSubConv, src, copyTree(arg), m, c)
|
param = implicitConv(nkHiddenSubConv, src, copyTree(arg), m, c)
|
||||||
elif src.kind in {tyVar}:
|
elif src.kind in {tyVar}:
|
||||||
# Analyse the converter return type
|
# Analyse the converter return type
|
||||||
|
arg.sym.flags.incl sfAddrTaken
|
||||||
param = newNodeIT(nkHiddenAddr, arg.info, s.typ[1])
|
param = newNodeIT(nkHiddenAddr, arg.info, s.typ[1])
|
||||||
param.add copyTree(arg)
|
param.add copyTree(arg)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
15
tests/js/t21247.nim
Normal file
15
tests/js/t21247.nim
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
import std/typetraits
|
||||||
|
|
||||||
|
type
|
||||||
|
QueryParams* = distinct seq[(string, string)]
|
||||||
|
|
||||||
|
converter toBase*(params: var QueryParams): var seq[(string, string)] =
|
||||||
|
params.distinctBase
|
||||||
|
|
||||||
|
proc foo(): QueryParams =
|
||||||
|
# Issue was that the implicit converter call didn't say that it took the
|
||||||
|
# address of the parameter it was converting. This led to the parameter not being
|
||||||
|
# passed as a fat pointer which toBase expected
|
||||||
|
result.add(("hello", "world"))
|
||||||
|
|
||||||
|
assert foo().distinctBase() == @[("hello", "world")]
|
||||||
Loading…
Add table
Add a link
Reference in a new issue