From 56015e52b9028097446e06bc3f09581992e6d692 Mon Sep 17 00:00:00 2001 From: Kier Davis Date: Mon, 11 Jul 2016 14:53:37 +0100 Subject: [PATCH 1/2] Fix #4475 Existing implementation would append the default value for a varargs parameter (the empty array) to the end of the sons of the nnkCall node, rather than storing it into the correct index. This left the location where it should have been stored set to its default value of nil, causing later code that uses this node to segfault. --- compiler/sigmatch.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index 511a44954f..8c8c83d0fb 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -1746,8 +1746,8 @@ proc matches*(c: PContext, n, nOrig: PNode, m: var TCandidate) = if formal.ast == nil: if formal.typ.kind == tyVarargs: var container = newNodeIT(nkBracket, n.info, arrayConstr(c, n.info)) - addSon(m.call, implicitConv(nkHiddenStdConv, formal.typ, - container, m, c)) + setSon(m.call, formal.position + 1, + implicitConv(nkHiddenStdConv, formal.typ, container, m, c)) else: # no default value m.state = csNoMatch From 023f1da40a1343dab0e3d8d2f1ef3bf08b55f91a Mon Sep 17 00:00:00 2001 From: Kier Davis Date: Mon, 11 Jul 2016 15:16:23 +0100 Subject: [PATCH 2/2] Add regression test for fix for #4475 --- tests/overload/tissue4475.nim | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 tests/overload/tissue4475.nim diff --git a/tests/overload/tissue4475.nim b/tests/overload/tissue4475.nim new file mode 100644 index 0000000000..34618cac57 --- /dev/null +++ b/tests/overload/tissue4475.nim @@ -0,0 +1,6 @@ +# Bug: https://github.com/nim-lang/Nim/issues/4475 +# Fix: https://github.com/nim-lang/Nim/pull/4477 + +proc test(x: varargs[string], y: int) = discard + +test(y = 1)