Bug 15089 – Marks wrong line as where error occurs.
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-09-20T17:58:00Z
Last change time
2017-07-21T10:44:10Z
Keywords
diagnostic
Assigned to
nobody
Creator
jjohnsonjj1251
Comments
Comment #0 by jjohnsonjj1251 — 2015-09-20T17:58:24Z
Code:
enum Pieces : ubyte
{
Empty,
Pawn,
Rook,
Knight,
Bishop,
Queen,
King
}
int color = 0b10000000;
...
byte[64] pieces;
...
pieces[i] = color ^ Pieces.Rook;
Explanation:
The compiler marked the error as occurring in the enum saying that 129 was too large to store in a byte when the error should have occurred in the last line where 129 was actually being assigned to a byte value.
Comment #1 by ag0aep6g — 2015-09-20T18:20:54Z
Thanks for reporting. You reduced/edited the code a bit too much. It doesn't actually show the problem anymore. But don't worry, I got you.
Here's reduced code that still shows the wrong error message:
----
enum Pieces {Rook} /* line 1 */
immutable int color = 0b10000000;
byte piece = Pieces.Rook ^ color;
----
test.d(1): Error: cannot implicitly convert expression (128) of type int to byte
----
For reference, this originated at Stack Overflow:
http://stackoverflow.com/questions/32681660/compiler-thinks-enum-values-are-starting-at-129
Comment #2 by ag0aep6g — 2015-09-20T19:07:54Z
*** Issue 15090 has been marked as a duplicate of this issue. ***