[Issue 15086] import doesn't verify module declaration

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Feb 14 16:45:24 UTC 2018


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

--- Comment #26 from Jonathan Marler <johnnymarler at gmail.com> ---
After more pondering I believe I've been able to pin down the fundamental
problem.  

TLDR: The current import semantics fundamentally break import order and module
order invariance.

To demonstrate let me describe current import semantics.

import foo;

When the compiler sees this, it first checks if a module has been loaded whose
"module name" is `foo`.  The important part is "if a module has been loaded". 
If this check fails, then it falls back to searching the fileystem for a file
matching the import name.  Note that when this occurs, the file that ends up
matching the import may not have a "module name" matching the name used to
import it.  And this is the fundamental problem.

What this means is that based on what modules have previously been loaded
(either via previous modules or previous imports in the same file) the
semantics of the import change.  In one case, the import causes a previously
loaded module to be imported, and in the other case, it will query the file
system for the module.  Since module names don't have to match filenames, this
means that the same import can result in loading different modules.  The
important distinction is that this change isn't caused by different command
line arguments, it's cause by changing the import order or the module order,
which breaks order invariance.

--


More information about the Digitalmars-d-bugs mailing list