Thread overview
inconsistent behavior with implicit imports
Sep 09, 2012
timotheecour
Sep 10, 2012
Jonathan M Davis
Sep 10, 2012
Timon Gehr
Sep 10, 2012
timotheecour
September 09, 2012
This works:
----
import std.stdio;
void main(){
	writeln(std.conv.to!double(1));
}
----

This doesn't compile:
----
import std.stdio;
void main(){
	std.stdio.writeln(std.conv.to!double(1));
}
----
=>Error: undefined identifier std

So it seems for conv, import std.conv is not needed, but for writeln, import std.stdio is needed. Why?

Also, I always get link errors when using those "implicit imports" for my own modules and using "rdmd". Is there a way to allow this without link errors in the following (using rdmd) ?
----
void main(){
	mypackage.mymodule.myfun(0);
}
----
which would behave as:
----
import mypackage.mymodule;
void main(){
	myfun(0);
}
----




September 10, 2012
On Monday, September 10, 2012 01:47:35 timotheecour wrote:
> This works:
> ----
> import std.stdio;
> void main(){
> 	writeln(std.conv.to!double(1));
> }
> ----
> 
> This doesn't compile:
> ----
> import std.stdio;
> void main(){
> 	std.stdio.writeln(std.conv.to!double(1));
> }
> ----
> =>Error: undefined identifier std
> 
> So it seems for conv, import std.conv is not needed, but for writeln, import std.stdio is needed. Why?
> 
> Also, I always get link errors when using those "implicit imports" for my own modules and using "rdmd". Is there a way to allow this without link errors in the following (using rdmd) ?
> ----
> void main(){
> 	mypackage.mymodule.myfun(0);
> }
> ----
> which would behave as:
> ----
> import mypackage.mymodule;
> void main(){
> 	myfun(0);
> }
> ----

Any and all implicit imports are a _bug_. They should _never_ happen. You should have to import both std.stdio and std.conv. If you don't have to, then you've found a bug. The _only_ exception is when one module publicly imports another, which Phobos _does_ do in a few places, but it definitely doesn't do that here. Nether of your examples should compile.

- Jonathan M Davis
September 10, 2012
On 09/10/2012 01:47 AM, timotheecour wrote:
> This works:
> ----
> import std.stdio;
> void main(){
>      writeln(std.conv.to!double(1));
> }
> ----
>
> This doesn't compile:
> ----
> import std.stdio;
> void main(){
>      std.stdio.writeln(std.conv.to!double(1));
> }
> ----
> =>Error: undefined identifier std
>
> So it seems for conv, import std.conv is not needed, but for writeln,
> import std.stdio is needed. Why?
>

I assume because std.stdio imports std.conv, but not vice versa.

> Also, I always get link errors when using those "implicit imports" for
> my own modules and using "rdmd". Is there a way to allow this without
> link errors in the following (using rdmd) ?
> ----
> void main(){
>      mypackage.mymodule.myfun(0);
> }
> ----
> which would behave as:
> ----
> import mypackage.mymodule;
> void main(){
>      myfun(0);
> }
> ----
>

This is a quirk of DMD, not a language feature.
You can file the implicit import behaviour as a bug.

September 10, 2012
> This is a quirk of DMD, not a language feature.
> You can file the implicit import behaviour as a bug.

done:
http://d.puremagic.com/issues/show_bug.cgi?id=8636