Update all the default parameters after an instantiation (#8689)
The old implementation relied on the (now?) wrong assumption that default-valued parameters can only be placed after the required ones. Fixes #8683
This commit is contained in:
parent
2def616069
commit
b28c7d434b
2 changed files with 16 additions and 6 deletions
|
|
@ -399,12 +399,11 @@ proc updateDefaultParams(call: PNode) =
|
||||||
# the default params with `nfDefaultParam` and `instantiateProcType`
|
# the default params with `nfDefaultParam` and `instantiateProcType`
|
||||||
# computes correctly the default values for each instantiation.
|
# computes correctly the default values for each instantiation.
|
||||||
let calleeParams = call[0].sym.typ.n
|
let calleeParams = call[0].sym.typ.n
|
||||||
for i in countdown(call.len - 1, 1):
|
for i in 1..<call.len:
|
||||||
if nfDefaultParam notin call[i].flags:
|
if nfDefaultParam in call[i].flags:
|
||||||
return
|
let def = calleeParams[i].sym.ast
|
||||||
let def = calleeParams[i].sym.ast
|
if nfDefaultRefsParam in def.flags: call.flags.incl nfDefaultRefsParam
|
||||||
if nfDefaultRefsParam in def.flags: call.flags.incl nfDefaultRefsParam
|
call[i] = def
|
||||||
call[i] = def
|
|
||||||
|
|
||||||
proc semResolvedCall(c: PContext, x: TCandidate,
|
proc semResolvedCall(c: PContext, x: TCandidate,
|
||||||
n: PNode, flags: TExprFlags): PNode =
|
n: PNode, flags: TExprFlags): PNode =
|
||||||
|
|
|
||||||
11
tests/proc/t8683.nim
Normal file
11
tests/proc/t8683.nim
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
discard """
|
||||||
|
output: "1"
|
||||||
|
"""
|
||||||
|
|
||||||
|
proc foo[T](bar: proc (x, y: T): int = system.cmp, baz: int) =
|
||||||
|
echo "1"
|
||||||
|
|
||||||
|
proc foo[T](bar: proc (x, y: T): int = system.cmp) =
|
||||||
|
echo "2"
|
||||||
|
|
||||||
|
foo[int](baz = 5)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue