On Tuesday, 17 October 2017 at 06:13:45 UTC, 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 ()?
Thanks!
Compiler made that way so it doesn't guess or assume too much,
because later on it will bite you when you don't even expect
that, and in some unpredictable place too.
you can always access symbols with fully qualified name, so in
this case
void main() { fun.fun(); }