Bug 11794 – Compilation fails with a certain selective import
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2013-12-21T15:52:00Z
Last change time
2017-07-02T01:41:37Z
Assigned to
nobody
Creator
nick
Comments
Comment #0 by nick — 2013-12-21T15:52:44Z
I'm not sure whether this is a problem with my code or a bug. The following code compiles and executes as expected:
import std.stdio;
import std.conv : to;
void main() {
auto x = std.conv.to!double("7.3");
writeln(x - 2.2);
}
However, changing the first line to this:
import std.stdio : writeln;
results in the following error:
: dmd main.d
main.d(5): Error: undefined identifier std
This is with DMD 2.064.
Comment #1 by nick — 2013-12-21T15:55:30Z
I apologize, the code I pasted is somewhat confusing. There should be a blank line after the imports and before the main() declaration, so that the error message is referring to the "auto x = std.conv.to!double("7.3");" line.
import std.stdio;
import std.conv : to;
void main() {
auto x = std.conv.to!double("7.3");
writeln(x - 2.2);
}
Comment #2 by andrej.mitrovich — 2013-12-22T01:18:03Z
(In reply to comment #0)
> I'm not sure whether this is a problem with my code or a bug.
I think it's a duplicate report, I've seen this before. When you use selective imports you cannot use the fully qualified name of the symbol, e.g.:
-----
import std.stdio : writeln;
void main()
{
std.stdio.writeln("foo"); // error
}
-----
This is by design.
However, for some reason "std.conv" is available when you import std.stdio, but I think this is a dupe report. Here's the accepts-invalid test case:
-----
import std.stdio;
void main()
{
std.conv.to!int("1"); // this should be an error..
}
-----
Comment #3 by dlang-bugzilla — 2017-07-02T01:41:37Z
Fairly sure this is a manifestation of issue 314.
Partial imports (import std.conv : to) do not provide visibility for fully-qualified names (std.conv.to), the example was using std.stdio's "public" import. Today's compilers correctly warn about this.
*** This issue has been marked as a duplicate of issue 314 ***