[Issue 15086] import doesn't verify module declaration

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Feb 13 18:59:03 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=15086

--- Comment #11 from Andrei Alexandrescu <andrei at erdani.com> ---
(In reply to Jonathan Marler from comment #10)
> > I think at the least we can do a vastly better job at issuing error messages.
> 
> I'm limiting focus to this issue alone. Do you have an idea on a way to
> improve the error message for this case?
> 
> CURRENT BEHAVIOR
> ----------------------------
> dmd -c foo.d bar.d
> Error: module baz from file bar.d must be imported with 'import baz;'
> 
> PROPOSED BEHAVIOR
> ----------------------------
> dmd -c foo.d bar.d
> Error: module baz from file bar.d must be imported with 'import baz;' or
> must be compiled separately

To make clear what the use case is, I'll paste the files again:

foo.d:
----
import bar;
----

bar.d:
----
module baz; /* not bar */
----

In this case, attempting to compile them together would be mistaken. I suggest:

Error: file bar.d masquerades as module `baz`, so it must be compiled
separately or imported with `import baz;`

This way we clarify where the discrepancy is and even mildly disapprove of it.
It's also clear that if no mismatch, this problem would disappear.

--


More information about the Digitalmars-d-bugs mailing list