www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Compiler bug: Incorrect line in error message

reply Shachar Shemesh <shachar weka.io> writes:
Please consider the following program:

struct V {
     int a;
}

struct S {
     enum A = V(12); // Line 6
}

void main() {
     int b = cast(int)S.A; // Line 10
}

It fails to compile:
test2.d(6): Error: cannot cast expression V(12) of type V to int

Everything about this error message is correct except the line number. 
It should be line 10, not line 6. The problem is where the incorrect 
cast is performed, not where the enum is defined.

I just spent three hours on this problem (thanks to Idan. Otherwise I'd 
spend much much more).

Shachar
Jan 14
parent Shachar Shemesh <shachar weka.io> writes:
Reported as issue #18236

It is possible this is a duplicate of issue #3773, from 8 years ago 
(opened on D1).

On 14/01/18 14:24, Shachar Shemesh wrote:
 Please consider the following program:
 
 struct V {
      int a;
 }
 
 struct S {
      enum A = V(12); // Line 6
 }
 
 void main() {
      int b = cast(int)S.A; // Line 10
 }
 
 It fails to compile:
 test2.d(6): Error: cannot cast expression V(12) of type V to int
 
 Everything about this error message is correct except the line number. 
 It should be line 10, not line 6. The problem is where the incorrect 
 cast is performed, not where the enum is defined.
 
 I just spent three hours on this problem (thanks to Idan. Otherwise I'd 
 spend much much more).
 
 Shachar
Jan 14