www.digitalmars.com         C & C++   DMDScript  

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


          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:

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

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:

struct str { int a; }

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

$ dmd -ofstr str.d strmain.d

class cla { int a; }

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 2017