diff options
author | Zahary Karadjov <zahary@gmail.com> | 2017-06-10 17:55:02 +0300 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2017-06-20 11:29:42 +0200 |
commit | f713e730c8467968be9efe27232e81203fc6c0cd (patch) | |
tree | 0e94d70b3ab657419a6d6c4940ac50a3f46ed9ca | |
parent | dea6d8dd94e474012ad6595f20ece11ea77ee260 (diff) | |
download | Nim-f713e730c8467968be9efe27232e81203fc6c0cd.tar.gz |
fix #5864
-rw-r--r-- | compiler/sigmatch.nim | 2 | ||||
-rw-r--r-- | tests/generics/tgenericsdefaultvalues.nim | 14 |
2 files changed, 16 insertions, 0 deletions
diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index 6a1352508..dfc27bbcb 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -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 diff --git a/tests/generics/tgenericsdefaultvalues.nim b/tests/generics/tgenericsdefaultvalues.nim new file mode 100644 index 000000000..2604c1031 --- /dev/null +++ b/tests/generics/tgenericsdefaultvalues.nim @@ -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 + |