Bug 21258 – Tuple parameters with defaults use the first tuple element for all defaults since 2.094.0-beta.1
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-09-17T10:07:09Z
Last change time
2020-09-26T20:09:01Z
Keywords
pull
Assigned to
No Owner
Creator
Richard Manthorpe
Comments
Comment #0 by rmanth — 2020-09-17T10:07:09Z
alias AliasSeq(TList...) = TList;
int foo(AliasSeq!(int, int) args = AliasSeq!(3, 5))
{
return args[0] * args[1];
}
static assert(foo(2) == 10); // fails in 2.094.0-beta.1
static assert(foo() == 15); // fails in 2.094.0-beta.1
This used to give defaults of 3 and 5 but now gives defaults of 3 and 3 as of 2.094.0-beta.1. More generally any tuple parameter with tuple defaults just tries to apply the first default value to all arguments.
Looks like it was broken by https://github.com/dlang/dmd/pull/11564
Comment #1 by rmanth — 2020-09-17T10:41:23Z
It's even more fun if you try it with different types:
alias AliasSeq(TList...) = TList;
auto foo(AliasSeq!(int, string) args = AliasSeq!(3, "hello"))
{
return args[0] * args[1].length;
}
static assert(foo() == 15); // Error: cannot implicitly convert expression 3 of type int to string
Comment #2 by dlang-bot — 2020-09-17T16:41:48Z
@Geod24 created dlang/dmd pull request #11749 "Fix 21258 - Tuple parameters use the first element of a default tuple value" fixing this issue:
- Fix 21258 - Tuple parameters use the first element of a default tuple value
A single character sometimes means the world.
https://github.com/dlang/dmd/pull/11749
Comment #3 by dlang-bot — 2020-09-18T02:48:15Z
dlang/dmd pull request #11749 "Fix 21258 - Tuple parameters use the first element of a default tuple value" was merged into stable:
- 8d3fe8fe5bf12a4bf493ddcd78bc4f6a82118784 by Geod24:
Fix 21258 - Tuple parameters use the first element of a default tuple value
The logic tried to use a single variable for both keeping track of the
original index and the extended index, but actually only tracked the
extended index.
Since `if (tupleStartIdx < eidx) tupleStartIdx = eidx` would be true
for every iteration, we would always assign the value at index 0.
https://github.com/dlang/dmd/pull/11749
Comment #4 by dlang-bot — 2020-09-26T20:09:01Z
dlang/dmd pull request #11793 "merge stable" was merged into master:
- e0a9304324b7d1d2fcf9662c2f77b5c42e804b05 by Geod24:
Fix 21258 - Tuple parameters use the first element of a default tuple value
The logic tried to use a single variable for both keeping track of the
original index and the extended index, but actually only tracked the
extended index.
Since `if (tupleStartIdx < eidx) tupleStartIdx = eidx` would be true
for every iteration, we would always assign the value at index 0.
https://github.com/dlang/dmd/pull/11793