www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Function with same name as a module name

reply "Daniel Kozak" <kozzi11 gmail.com> writes:
module main;
import std.stdio;

struct A {}

static A a;

void main() {
	writeln(main.a);
}

this code does not work, because it try to use main function 
instead of main module. Even error message is wierd: Error: 
struct A does not overload ()
Nov 29 2014
parent reply "Xinok" <xinok live.com> writes:
On Saturday, 29 November 2014 at 19:35:52 UTC, Daniel Kozak wrote:
 module main;
 import std.stdio;

 struct A {}

 static A a;

 void main() {
 	writeln(main.a);
 }

 this code does not work, because it try to use main function 
 instead of main module. Even error message is wierd: Error: 
 struct A does not overload ()
It's a little confusing but it is referring to module main and not the function main. I think the error message is because struct A doesn't define opCall. See: http://dlang.org/operatoroverloading.html#function-call I tried to provide an example, but I couldn't get the code to compile myself. :-/
Nov 29 2014
parent reply "Daniel Kozak" <kozzi11 gmail.com> writes:
On Saturday, 29 November 2014 at 22:25:46 UTC, Xinok wrote:
 On Saturday, 29 November 2014 at 19:35:52 UTC, Daniel Kozak 
 wrote:
 module main;
 import std.stdio;

 struct A {}

 static A a;

 void main() {
 	writeln(main.a);
 }

 this code does not work, because it try to use main function 
 instead of main module. Even error message is wierd: Error: 
 struct A does not overload ()
It's a little confusing but it is referring to module main and not the function main. I think the error message is because struct A doesn't define opCall.
No, it is refer to main function. And try to call UFCS a(main);
Dec 01 2014
parent reply "Jeremy DeHaan" <dehaan.jeremiah gmail.com> writes:
I don't think you can specify look ups with the name of the 
module in the same module like you can with imported ones. If you 
want to specify that it is a variable in module scope, use the 
module scope operator.

writeln(.a); // the leading '.' specifies module scope
Dec 01 2014
parent reply Daniel Kozak via Digitalmars-d <digitalmars-d puremagic.com> writes:
Dne Mon, 01 Dec 2014 18:10:35 +0100 Jeremy DeHaan via Digitalmars-d  
<digitalmars-d puremagic.com> napsal(a):

 I don't think you can specify look ups with the name of the module in  
 the same module like you can with imported ones. If you want to specify  
 that it is a variable in module scope, use the module scope operator.

 writeln(.a); // the leading '.' specifies module scope
You can. It doesn't work only when there is a another symbol with same name as a module. But it makes a sense.
Dec 01 2014
parent "Jeremy DeHaan" <dehaan.jeremiah gmail.com> writes:
On Monday, 1 December 2014 at 20:29:48 UTC, Daniel Kozak via 
Digitalmars-d wrote:
 Dne Mon, 01 Dec 2014 18:10:35 +0100 Jeremy DeHaan via 
 Digitalmars-d <digitalmars-d puremagic.com> napsal(a):

 I don't think you can specify look ups with the name of the 
 module in the same module like you can with imported ones. If 
 you want to specify that it is a variable in module scope, use 
 the module scope operator.

 writeln(.a); // the leading '.' specifies module scope
You can. It doesn't work only when there is a another symbol with same name as a module. But it makes a sense.
I don't see it mentioned at all in this: http://dlang.org/module.html It sounds like something was over looked. Either you shouldn't be able to specify with the module name in the same module, or you shouldn't be getting this error.
Dec 01 2014