www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Why is compilation failing with this selective import?

reply "Nick Hamann" <nick wabbo.org> writes:
I'm not sure if this is a bug or if I'm doing something wrong.

Compilation succeeds and the program runs successfully with this 
code:

import std.stdio;
import std.conv : to;
void main() {
     auto x = std.conv.to!double("7.3");
     writeln(x - 2.2);
}


However, when I change the first line to "import std.stdio : 
writeln;", I instead get:

: dmd main.d
main.d(5): Error: undefined identifier std


I'm running DMD 2.064 on 64-bit Arch Linux.
Dec 21 2013
parent Timon Gehr <timon.gehr gmx.ch> writes:
On 12/21/2013 09:56 PM, Nick Hamann wrote:
 I'm not sure if this is a bug or if I'm doing something wrong.

 Compilation succeeds and the program runs successfully with this code:

 import std.stdio;
 import std.conv : to;
 void main() {
      auto x = std.conv.to!double("7.3");
      writeln(x - 2.2);
 }
 ...
The first import seems to introduce the identifier 'std' (+ more). The second import seems to introduce 'conv' into the scope of 'std'.
 However, when I change the first line to "import std.stdio : writeln;",
 I instead get:

 : dmd main.d
 main.d(5): Error: undefined identifier std
 ...
Now it does not introduce the identifier 'std'.
 I'm running DMD 2.064 on 64-bit Arch Linux.
This part of the language is not specified too well. It cannot hurt to report this though. The current behaviour is non-modular, as which modules are available depends on which modules you imported transitively.
Dec 21 2013