From 219b4f07e47f9a0b4c4304b6b02620335bc2a172 Mon Sep 17 00:00:00 2001 From: RazvanN7 Date: Wed, 11 Sep 2024 16:04:08 +0300 Subject: [PATCH] Fix Bugzilla Issue 24760 - ICE on variadic after default argument --- compiler/src/dmd/typesem.d | 4 +++- compiler/test/compilable/test24760.d | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 compiler/test/compilable/test24760.d diff --git a/compiler/src/dmd/typesem.d b/compiler/src/dmd/typesem.d index a909fcf14c18..3933d7dfddbb 100644 --- a/compiler/src/dmd/typesem.d +++ b/compiler/src/dmd/typesem.d @@ -835,7 +835,9 @@ extern (D) MATCH callMatch(TypeFunction tf, Type tthis, ArgumentList argumentLis L1: if (parameterList.varargs == VarArg.typesafe && u + 1 == nparams) // if last varargs param { - auto trailingArgs = args[u .. $]; + Expression[] trailingArgs; + if (args.length >= u) + trailingArgs = args[u .. $]; if (auto vmatch = matchTypeSafeVarArgs(tf, p, trailingArgs, pMessage)) return vmatch < match ? vmatch : match; // Error message was already generated in `matchTypeSafeVarArgs` diff --git a/compiler/test/compilable/test24760.d b/compiler/test/compilable/test24760.d new file mode 100644 index 000000000000..7c84848a6fe9 --- /dev/null +++ b/compiler/test/compilable/test24760.d @@ -0,0 +1,4 @@ +// https://issues.dlang.org/show_bug.cgi?id=24760 + +long f(int e = 0, uint[] optional...) => optional.length; +long f0() => f(); // compiler segfaults