www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4076] New: Wrong error line number with enum

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4076

           Summary: Wrong error line number with enum
           Product: D
           Version: future
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: diagnostic
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc


--- Comment #0 from bearophile_hugs eml.cc 2010-04-09 19:57:53 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 09 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4076



--- Comment #1 from bearophile_hugs eml.cc 2010-05-12 02:58:08 PDT ---
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]

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 12 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4076


Max Samukha <samukha voliacable.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |samukha voliacable.com


--- Comment #2 from Max Samukha <samukha voliacable.com> 2011-02-15 04:03:49
PST ---
*** Issue 5588 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 15 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4076



--- Comment #3 from bearophile_hugs eml.cc 2011-09-21 13:25:54 PDT ---
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)];

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 21 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4076


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |yebblies gmail.com
           Platform|x86                         |All
            Version|D2                          |D1 & D2
         Resolution|                            |WORKSFORME
         OS/Version|Windows                     |All


--- Comment #4 from yebblies <yebblies gmail.com> 2012-02-04 18:53:54 EST ---
This works with the current compiler (1.072 & 2.058)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 03 2012