This whole thing is a huge hole in D that needs to be fixed (it may even be necessary to consider it higher priority than the current C++ and GC). As it works currently, I'd go as far as to say that almost every addition to Phobos must be considered a breaking change for these reasons. Given the recent discussion about trying as much as possible to not break code, fixing the issues with import is extremely important. When a library writer can break user code by introducing a *private* symbol (scoped or otherwise), something has gone wrong.

Furthermore:

        // mod.d
        module mod;
        struct S {
                // Use a fully-qualified import.
                // We place it in the body of S because S's methods
                // repeatedly needs it -- after all, DRY is good, right?
                import std.format : format;

                void method1(string fmt) {
                        writeln(format(fmt, ... ));
                }

                void method2() {
                        auto s = format("abc %s def", ...);
                        ...
                }
        }

        // main.d
        module main;
        import mod; // we need the definition of S

        void format(S s) {
                ... /* do something with s */
        }

        void main() {
                S s;
                s.format(); // UFCS -- should call main.format(s), right?
        }

Am I correct that this bug is due to the fact that selective imports from a module implicitly imports all symbols in that module, rather than just the selected symbol? I don't know how anyone could think that D's module system is simple at this point when things behave so differently from how they intuitively should behave (for my own personal definition of intuitive).

Reply via email to