Bug 2826 – failed assignment gives wrong line number
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2009-04-09T09:32:00Z
Last change time
2015-06-09T01:18:03Z
Keywords
diagnostic, patch
Assigned to
bugzilla
Creator
clugdbug
Comments
Comment #0 by clugdbug — 2009-04-09T09:32:02Z
const float foo=200.0;
void main() {
int y = foo;
}
-----------
fog.d(1): Error: cannot implicitly convert expression (200) of type const(float)
to int
But the error is on line 4, not on line 1.
================
Patch: optimize.c line 128. The problem is that isVarDeclaration() on line 119 returns an expression with the line number where the initializer was from. But, we want the line number for the assignment.
This patch fixes it, but I think there's something deeper which is wrong here. There are many similar alias bugs in bugzilla.
--- optimize.c (revision 23)
+++ optimize.c (working copy)
@@ -124,6 +124,7 @@
e = e->copy();
e->type = e1->type;
}
+ e->loc = e1->loc;
}
else
e = e1;
Comment #1 by sandford — 2009-10-12T09:56:20Z
Fixes in DMD 2.034 have exacerbated this issue. Specifically, this effects all void return functions with a non-void return somewhere in the function. Also, note that the error may be in a completely different file, making it harder to track down.