Bug 4076 – Wrong error line number with enum

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-04-09T19:57:00Z
Last change time
2015-06-09T05:11:38Z
Keywords
diagnostic
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2010-04-09T19:57:53Z
This is wrong D2 code: void main() { enum double n = 10; // ***** // ***** // ***** auto arr = new int[n]; } dmd 2.043 prints: test.d(2): Error: cannot implicitly convert expression (10) of type double to uint Note the line number of the error. It says 2 and not 6. If the enum is far away from the line where arr is defined, it's not easy to understand, find, and fix the bug in the code.
Comment #1 by bearophile_hugs — 2010-05-12T02:58:08Z
Another test case: enum int N = 10; // line 1 void main() { int[N] arr; arr[N] = 1; // line 4 } dmd v2.045 outputs: test.d(1): Error: array index 10 is out of bounds arr[0 .. 10] test.d(1): Error: array index 10 is out of bounds arr[0 .. 10] The line number of the error is wrong, and there is no need to print it two times. So a better error message can be: test.d(4): Error: array index 10 is out of bounds arr[0 .. 10]
Comment #2 by samukha — 2011-02-15T04:03:49Z
*** Issue 5588 has been marked as a duplicate of this issue. ***
Comment #3 by bearophile_hugs — 2011-09-21T13:25:54Z
Another test case: import std.typecons; void main() { enum int N = 10; // line 3 // lot of code here... int[Tuple!(int, int)] aa; int x = aa[(1, N)]; } DMD 2.055 gives: test.d(3): Error: cannot implicitly convert expression (10) of type int to Tuple!(int,int) It's not easy to debug such code. The bug is in the line: int x = aa[(1, N)]; Its correct version is: int x = aa[tuple(1, N)];
Comment #4 by yebblies — 2012-02-03T23:53:54Z
This works with the current compiler (1.072 & 2.058)