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 #3 by hsteoh — 2013-08-30T10:40:05Z
Probably a CTFE limitation/bug?
Comment #4 by hsteoh — 2013-08-30T14:27:23Z
The offending commit was introduced by https://github.com/D-Programming-Language/dmd/pull/2136
Comment #5 by henning — 2013-09-02T12:16:08Z
Comment #6 by github-bugzilla — 2013-09-03T16:21:13Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/f66f1efa8dcf76e013de31d50238ca8195850470 fix issue 10687 - Refused cast from uint[] to array of uint-based enums at compile-time https://github.com/D-Programming-Language/dmd/commit/6f9a34f3200f5907200f640cf8055c9dec6e795c Merge pull request #2517 from hpohl/10687 [REG2.064a] fix issue 10687 - Refused cast from uint[] to array of uint-based enums at compile-time
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
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/4fba50787271a39fa560ce973a1eb0423d455cb5 fix Issue 10687 - Refused cast from uint[] to array of uint-based enums at compile-time https://github.com/D-Programming-Language/dmd/commit/cd8323733777ca8725c20892683cafb128b69283 Merge pull request #2612 from 9rnsr/fix10687 [REG2.064a] Issue 10687 - Refused cast from uint[] to array of uint-based enums at compile-time
Comment #10 by bearophile_hugs — 2013-10-08T04:48:40Z
Now the code works again, thank you.