summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/sigmatch.nim5
-rw-r--r--tests/typerel/tclosure_nil_as_default.nim11
2 files changed, 15 insertions, 1 deletions
diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim
index 4a5132d6d..22915a4bb 100644
--- a/compiler/sigmatch.nim
+++ b/compiler/sigmatch.nim
@@ -1777,7 +1777,10 @@ proc matches*(c: PContext, n, nOrig: PNode, m: var TCandidate) =
           break
       else:
         # use default value:
-        setSon(m.call, formal.position + 1, copyTree(formal.ast))
+        var def = copyTree(formal.ast)
+        if def.kind == nkNilLit:
+          def = implicitConv(nkHiddenStdConv, formal.typ, def, m, c)
+        setSon(m.call, formal.position + 1, def)
     inc(f)
 
 proc argtypeMatches*(c: PContext, f, a: PType): bool =
diff --git a/tests/typerel/tclosure_nil_as_default.nim b/tests/typerel/tclosure_nil_as_default.nim
new file mode 100644
index 000000000..fe9f42b14
--- /dev/null
+++ b/tests/typerel/tclosure_nil_as_default.nim
@@ -0,0 +1,11 @@
+
+# bug #4328
+type
+    foo[T] = object
+        z: T
+
+proc test[T](x: foo[T], p: proc(a: T) = nil) =
+    discard
+
+var d: foo[int]
+d.test()  # <- param omitted