D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2826 - failed assignment gives wrong line number
Summary: failed assignment gives wrong line number
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: Walter Bright
URL:
Keywords: diagnostic, patch
Depends on:
Blocks:
 
Reported: 2009-04-09 09:32 UTC by Don
Modified: 2015-06-09 01:18 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Don 2009-04-09 09:32:02 UTC
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 Rob Jacques 2009-10-12 09:56:20 UTC
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.
Comment 2 Don 2009-10-21 06:40:38 UTC
Fixed DMD2.035.