www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - import conflicts

reply "AndyC" <andy squeakycode.net> writes:
Hi all, I'm trying to write my first actual app that'll go into 
production.  My file starts with this set of imports:

import std.stdio, std.string, std.json, std.process, std.conv, 
std.file,
	core.sys.posix.syslog, tinyredis.redis;
import core.sys.posix.unistd: chdir;
import core.sys.posix.sys.stat: mkdir, umask;
import core.thread: Thread, dur;
import core.stdc.stdlib: exit;

At some point in code I have added:

if (exists("lastUpdate.7z")) {
   remove("lastUpdate.7z");
}


Now I get compile errors:

autoupdate.d(183): Error: std.file.remove at 
/usr/include/dmd/phobos/std/file.d(429) conflicts with 
core.stdc.stdio.remove at 
/usr/include/dmd/druntime/import/core/stdc/stdio.d(548)


I'm not importing core.stdc.stdio, so why is it conflicting?

Thanks for your time,

-Andy
Jan 18 2015
parent reply "Vlad Levenfeld" <vlevenfeld gmail.com> writes:
I get this all the time with std.array.array (I use my own array 
implementations, but phobos' array seems to secretly creep in 
everywhere). I think its got to do with that private import 
visibility bug (https://issues.dlang.org/show_bug.cgi?id=314 or 
https://issues.dlang.org/show_bug.cgi?id=13096 I think)
which, by the looks of it, should be getting a fix... soon? ish?
Jan 18 2015
parent reply "AndyC" <andy squeakycode.net> writes:
On Sunday, 18 January 2015 at 19:20:34 UTC, Vlad Levenfeld wrote:
 I get this all the time with std.array.array (I use my own 
 array implementations, but phobos' array seems to secretly 
 creep in everywhere). I think its got to do with that private 
 import visibility bug 
 (https://issues.dlang.org/show_bug.cgi?id=314 or 
 https://issues.dlang.org/show_bug.cgi?id=13096 I think)
 which, by the looks of it, should be getting a fix... soon? ish?
Ah, if its just a compiler bug I'm ok with that. I was worried there was something about the language I didnt understand. I got it to compile ok using: import std.file: remove, exists, rename; Thanks, -Andy
Jan 18 2015
parent Mike Parker <aldacron gmail.com> writes:
On 1/19/2015 4:37 AM, AndyC wrote:
 On Sunday, 18 January 2015 at 19:20:34 UTC, Vlad Levenfeld wrote:
 I get this all the time with std.array.array (I use my own array
 implementations, but phobos' array seems to secretly creep in
 everywhere). I think its got to do with that private import visibility
 bug (https://issues.dlang.org/show_bug.cgi?id=314 or
 https://issues.dlang.org/show_bug.cgi?id=13096 I think)
 which, by the looks of it, should be getting a fix... soon? ish?
Ah, if its just a compiler bug I'm ok with that. I was worried there was something about the language I didnt understand. I got it to compile ok using: import std.file: remove, exists, rename; Thanks, -Andy
The problem is, that's the bug Vlad was talking about. Selective imports wind up becoming public, polluting the namespace. The thing to do when you get conflicts is to use the fully-qualified function name, like so: std.file.remove( "lastUpdate.7z" ); Keep those selective imports out of module scope until the bug is fixed. They work in local scope just fine: void foo() { import std.file : remove, exists; if( exists( "foo" )) remove( "foo" ); }
Jan 18 2015