Bug 24372 – ArraySliceError when calling a function with an optional parameter and typesafe variadic
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2024-02-07T23:08:51Z
Last change time
2024-02-08T05:23:20Z
Assigned to
No Owner
Creator
artha
Comments
Comment #0 by artha — 2024-02-07T23:08:51Z
Tested and reproduced this issue using 2.106.1 and 2.107.0. The following sample will crash the compiler:
```
import std;
struct A { }
struct B { }
struct C { }
void test(A a, B b = B.init, scope C[] c...) {
writeln(a, b, c);
}
void main() {
testWrap(A());
}
```
The above sample works if `b` or `c` is removed from the signature, or if `c` is defined as `scope C[] c = null...`. While iterating on the arguments, the compiler appears to assume the slice has a corresponding argument passed, but it does not.
Related: https://issues.dlang.org/show_bug.cgi?id=14651
Call stack:
```
core.exception.ArraySliceError@src/dmd/mtype.d(4794): slice [2 .. 1] has a larger lower index than
upper index
----------------
??:? onArraySliceError [0x5edb604133da]
??:? _d_arraybounds_slicep [0x5edb60404c32]
src/dmd/mtype.d:4794 int dmd.mtype.TypeFunction.callMatch(dmd.mtype.Type, dmd.expression.ArgumentLi
st, int, const(char)**, dmd.dscope.Scope*).__foreachbody14(ulong, dmd.mtype.Parameter) [0x5edb60216
f27]
src/dmd/mtype.d:6844 int dmd.mtype.Parameter._foreach(dmd.root.array.Array!(dmd.mtype.Parameter).Ar
ray*, int delegate(ulong, dmd.mtype.Parameter)).__lambda3!(ulong, dmd.mtype.Parameter, ulong, dmd.m
type.Parameter).__lambda3(ulong, dmd.mtype.Parameter, ulong, dmd.mtype.Parameter) [0x5edb6021b030]
src/dmd/mtype.d:6889 int dmd.mtype.Parameter._foreachImpl(scope int delegate(ulong, dmd.mtype.Param
eter, ulong, dmd.mtype.Parameter), ulong, dmd.mtype.Parameter, ref ulong, dmd.mtype.Parameter) [0x5
edb6021b217]
src/dmd/mtype.d:6859 int dmd.mtype.Parameter._foreach(dmd.root.array.Array!(dmd.mtype.Parameter).Ar
ray*, int delegate(ulong, dmd.mtype.Parameter, ulong, dmd.mtype.Parameter)) [0x5edb6021b0d8]
src/dmd/mtype.d:6844 int dmd.mtype.Parameter._foreach(dmd.root.array.Array!(dmd.mtype.Parameter).Ar
ray*, int delegate(ulong, dmd.mtype.Parameter)) [0x5edb6021aff4]
src/dmd/mtype.d:6615 int dmd.mtype.ParameterList.opApply(scope int delegate(ulong, dmd.mtype.Parame
ter)) [0x5edb6021a8ba]
src/dmd/mtype.d:4765 dmd.astenums.MATCH dmd.mtype.TypeFunction.callMatch(dmd.mtype.Type, dmd.expres
sion.ArgumentList, int, const(char)**, dmd.dscope.Scope*) [0x5edb60216c10]
[...]
```
Comment #1 by snarwin+bugzilla — 2024-02-08T05:23:20Z
*** This issue has been marked as a duplicate of issue 14651 ***