www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17907] New: Can't automatically resolve to function with same

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

          Issue ID: 17907
           Summary: Can't automatically resolve to function with same name
                    as module
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: samjnaa gmail.com

Compiler does not automatically resolve to function with same name as module:

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

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

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

However, in case of struct-s and classes with same name, there is no problem:

str.d:
struct str { int a; }

strmain.d:
import str;
void main() { str var; var.a = 2; }

$ dmd -ofstr str.d strmain.d

cla.d:
class cla { int a; }

clamain.d:
import cla;
void main() { auto var = new cla; var.a = 2; }

$ dmd -ofcla cla.d clamain.d

If it is possible with types, and indeed it is meaningful to name a module
after the main type or function defined therein, there seems to be no reason
for not being able to resolve to a function with the same name as a module.

Of course, doing `import fun: fun;` will work, but that is unnecessary
verbosity and is not being required even now in the case of types as shown
above. In D, the compiler is all powerful and can know which resolution of
which symbol is appropriate where. The same capability should apply here also.

Thank you!

--
Oct 17