mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-23 04:50:45 +00:00
fix #5864
This commit is contained in:
committed by
Andreas Rumpf
parent
dea6d8dd94
commit
f713e730c8
@@ -2228,6 +2228,8 @@ proc matches*(c: PContext, n, nOrig: PNode, m: var TCandidate) =
|
||||
var def = copyTree(formal.ast)
|
||||
if def.kind == nkNilLit:
|
||||
def = implicitConv(nkHiddenStdConv, formal.typ, def, m, c)
|
||||
if {tfImplicitTypeParam, tfGenericTypeParam} * formal.typ.flags != {}:
|
||||
put(m, formal.typ, def.typ)
|
||||
setSon(m.call, formal.position + 1, def)
|
||||
inc(f)
|
||||
# forget all inferred types if the overload matching failed
|
||||
|
||||
14
tests/generics/tgenericsdefaultvalues.nim
Normal file
14
tests/generics/tgenericsdefaultvalues.nim
Normal file
@@ -0,0 +1,14 @@
|
||||
discard """
|
||||
output: "12"
|
||||
"""
|
||||
|
||||
# https://github.com/nim-lang/Nim/issues/5864
|
||||
|
||||
proc defaultStatic(s: openarray, N: static[int] = 1): int = N
|
||||
proc defaultGeneric[T](a: T = 2): int = a
|
||||
|
||||
let a = [1, 2, 3, 4].defaultStatic()
|
||||
let b = defaultGeneric()
|
||||
|
||||
echo a, b
|
||||
|
||||
Reference in New Issue
Block a user