[Issue 17907] Can't automatically resolve to function with same name as module

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Oct 20 09:29:35 UTC 2017


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

RazvanN <razvan.nitu1305 at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |razvan.nitu1305 at gmail.com

--- Comment #1 from RazvanN <razvan.nitu1305 at gmail.com> ---
The problem here is that in the first example you are doing symbol resolution
while in the second case you are doing type resolution.


Here is what happens in the first case: the generated AST in this case, can be
roughly reduced to : IdentifierExp -> CallExp. When semantic is performed on
the IdentifierExp node, the symbol "fun" is resolved following these rules [1].
Note that no type check is performed, just plain string comparison, so "fun" is
resolved to the import symbol. Later, when semantic is performed on the child
node, the CallExp node, the type checks are performed and indeed you cannot
call a module declaration as a function, hence the error you receive.

The second case, on the other hand, is doing type resolution, which implicitly
checks that the types are equal (through pointer comparison). That is why the
second case compiles successfully .

So, by all means the compiler is doing the right thing. Note that calling
fun.fun compiles successfully.

I suggest we close this as invalid.

[1] https://dlang.org/spec/module.html#name_lookup

--


More information about the Digitalmars-d-bugs mailing list