I think perhaps the correct change is to import format only inside those functions that need it.
Comment #2 by hsteoh — 2014-12-02T15:37:32Z
Argh... yet another scoped import pathological behaviour. Apparently putting an import in the body of a struct S pulls symbols into the struct's namespace, so that S.symbol now refers to the imported symbol.
This is really nasty, and greatly limits the usefulness of scoped imports, for example:
-----
// mod.d
module mod;
struct S {
// This is necessary for myFunc, and we can't move it inside myFunc,
// because we need it in the sig constraint
import std.range.primitives : isInputRange;
auto myFunc(R)(R input)
if (isInputRange!R)
{ ... }
}
// main.d
import mod;
void main() {
S s;
static if (s.isInputRange!(int[])) { // this actually works :-(
...
}
static if (isInputRange!(int[])) { // whereas this doesn't compile
}
}
-----
Note that making the import in S static doesn't help, because static imports cannot bind specific symbols, so you have to alias specific import symbols... but that again leaks them to the outside via UFCS.
This is no longer just about std.datetime, this is a glaring hole in the import system.
Comment #3 by hsteoh — 2014-12-02T16:02:30Z
Workaround for std.datetime:
https://github.com/D-Programming-Language/phobos/pull/2780
This is not a complete fix, as there are a bunch of other scoped imports as well, and it would take quite a bit more effort to sort all of them out. :-( In any case, it's probably better if we address this in the compiler instead of putting workarounds into every library that uses scoped imports at the struct/class level.
Comment #4 by k.hara.pg — 2014-12-04T15:04:26Z
(In reply to hsteoh from comment #2)
> Argh... yet another scoped import pathological behaviour. Apparently putting
> an import in the body of a struct S pulls symbols into the struct's
> namespace, so that S.symbol now refers to the imported symbol.
Any imported symbols in struct body scope should not be visible via the struct instance object.
> This is really nasty, and greatly limits the usefulness of scoped imports,
> for example:
>
> -----
> // mod.d
> module mod;
> struct S {
> // This is necessary for myFunc, and we can't move it inside myFunc,
> // because we need it in the sig constraint
> import std.range.primitives : isInputRange;
>
> auto myFunc(R)(R input)
> if (isInputRange!R)
> { ... }
> }
>
> // main.d
> import mod;
> void main() {
> S s;
> static if (s.isInputRange!(int[])) { // this actually works :-(
> ...
> }
> static if (isInputRange!(int[])) { // whereas this doesn't compile
> }
> }
> -----
My import mechanism improvement will disallow the weird name lookup `s.isInputRange!(int[])`.
https://github.com/D-Programming-Language/dmd/pull/3407
Comment #5 by github-bugzilla — 2014-12-04T20:47:54Z