Bug 10687 – Refused cast from uint[] to array of uint-based enums at compile-time
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
All
Creation time
2013-07-20T16:14:00Z
Last change time
2013-10-08T04:48:40Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2013-07-20T16:14:49Z
I think this used to be accepted:
enum Foo : uint { A, B, C, D, E }
void main() {
static immutable uint[5] a1 = [0, 1, 2, 3, 4]; // line 3
auto a2 = cast(immutable(Foo[5]))a1; // OK
static a3 = cast(immutable(Foo[5]))a1; // line 5, error
}
test.d(3): Error: cannot implicitly convert expression ([0u, 1u, 2u, 3u, 4u]) of type immutable(uint[5u]) to immutable(Foo[5u])
Also the error line number is wrong, the right line number is 5.
Comment #1 by hsteoh — 2013-08-30T10:26:47Z
Verified that 2.063.2 compiles this code correctly (Linux/64bit).
Comment #2 by hsteoh — 2013-08-30T10:37:35Z
git bisect shows that the offending commit was: 43a6c87194cae799650249b10a4f7c910081d280
Comment #7 by bearophile_hugs — 2013-09-03T17:26:12Z
(In reply to comment #6)
> Commits pushed to master at https://github.com/D-Programming-Language/dmd
Sorry, I think the issue is not yet fixed, some of my code like this used to work:
immutable uint[5][] M = [[0, 1, 2, 3, 4]];
enum Foo : uint { A, B, C, D, E }
void main() {
auto foos1 = cast(immutable(Foo[5][]))M; // OK
static foos2 = cast(immutable(Foo[5][]))M; // Error
}
Comment #8 by k.hara.pg — 2013-10-01T21:38:20Z
(In reply to comment #7)
> (In reply to comment #6)
> > Commits pushed to master at https://github.com/D-Programming-Language/dmd
>
> Sorry, I think the issue is not yet fixed, some of my code like this used to
> work:
>
> immutable uint[5][] M = [[0, 1, 2, 3, 4]];
> enum Foo : uint { A, B, C, D, E }
> void main() {
> auto foos1 = cast(immutable(Foo[5][]))M; // OK
> static foos2 = cast(immutable(Foo[5][]))M; // Error
> }
https://github.com/D-Programming-Language/dmd/pull/2612
Comment #9 by github-bugzilla — 2013-10-02T17:06:58Z