Bug 12598 – Poor diagnostic with local import hijacking
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-04-19T11:12:00Z
Last change time
2014-04-19T18:26:39Z
Keywords
diagnostic
Assigned to
andrej.mitrovich
Creator
dlang-bugzilla
Comments
Comment #0 by dlang-bugzilla — 2014-04-19T11:12:30Z
Consider the following program:
//////////////////// test.d ////////////////////
class C
{
void addLine(string l)
{
debug
{
import std.stdio;
stderr.writeln("Adding line: " ~ l);
}
lines ~= l;
}
immutable(string)[] lines;
}
////////////////////////////////////////////////
When compiled with -debug, the compiler produces the following error message:
test.d(10,3): Error: lines is not an lvalue
This error message is misleading - it's not clear that a symbol from std.stdio is hijacking the "lines" field.
One way to improve the situation is to print fully-qualified symbol names in error messages.
Another would be to add a warning or error when a locally-imported symbol is hijacking a non-global symbol. The user can silence this message by using a selective, static or named import.
Comment #1 by github-bugzilla — 2014-04-19T18:26:39Z