On 10/17/17 2:13 AM, Shriramana Sharma wrote:
Hello.

fun.d:
import std.stdio;
void fun() { writeln("Hello"); }

main.d:
import fun;
void main() { fun(); }

$ dmd -oftest fun.d main.d
main.d(2): Error: function expected before (), not module fun of type void

Why can't I use a function of the same name as the module? IIUC import fun imports all the top-level symbols within module fun as well as the symbol fun referring to the module itself. This is just another case of overloading, no? Can't the compiler understand that I am trying to call the function fun.fun() and not the module even when it is followed by ()?

I know you have filed a report, and probably it should be considered (it surprises me that types work but functions don't, they are all symbols).

But just as reference, the reason it doesn't come up much is because most modules are within a package, which means you never have top level modules.

But it probably doesn't make a lot of sense to create a package if your library only has one module. It's just not very common.

-Steve

Reply via email to