Bug 14737 – [REG2.058] A concatenation of array literal and static array should make dynamic array
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-06-26T04:51:00Z
Last change time
2017-07-22T12:35:41Z
Keywords
industry, pull, rejects-valid
Assigned to
nobody
Creator
briancschott
Comments
Comment #0 by briancschott — 2015-06-26T04:51:02Z
```
private struct S
{
int a;
int b;
int c;
}
void main()
{
import std.traits:FieldNameTuple;
enum string[2] a = ["d", "e"];
enum b = [FieldNameTuple!S] ~ a;
string[2] a2 = ["c", "d"];
auto b2 = [FieldNameTuple!S] ~ a2;
}
```
With 2.067.1 this fails with the following error:
test.d(16): Error: e2ir: cannot cast ["a", "b", "c"] of type string[] to type string[2]
That's a bug, but at least the enum case was allowed to compile.
With 2.068.0-b1, it fails with this error:
test.d(12): Error: cannot cast expression ["a", "b", "c"] of type string[] to string[2]
test.d(16): Error: cannot cast expression ["a", "b", "c"] of type string[] to string[2]
Comment #1 by briancschott — 2015-06-26T05:38:18Z
Digger has traced this back to DMD commit 0b3641ad960ba7f4d8d5f5a23fec52e506017bd6
Comment #2 by k.hara.pg — 2015-06-26T06:03:51Z
(In reply to briancschott from comment #0)
> With 2.068.0-b1, it fails with this error:
> test.d(12): Error: cannot cast expression ["a", "b", "c"] of type string[]
> to string[2]
> test.d(16): Error: cannot cast expression ["a", "b", "c"] of type string[]
> to string[2]
A concatenation T[] ~ T[n] should be typed as T[], so the both cases should succeed to compile.
With the reduced test case:
void main()
{
string[2] a2 = ["d", "e"];
auto b2 = ["a", "b", "c"] ~ a2;
assert(b2 == ["a", "b", "c", "d", "e"]);
}
It had worked until 2.057, but since 2.058 e2ir error has occurred.
The rejects-valid regression was introduced in:
https://github.com/D-Programming-Language/dmd/pull/618