Thread overview
Function with same name as a module name
Nov 29, 2014
Daniel Kozak
Nov 29, 2014
Xinok
Dec 01, 2014
Daniel Kozak
Dec 01, 2014
Jeremy DeHaan
Dec 01, 2014
Daniel Kozak
Dec 01, 2014
Jeremy DeHaan
November 29, 2014
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 ()
November 29, 2014
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. :-/
December 01, 2014
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);

December 01, 2014
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
December 01, 2014
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.
December 01, 2014
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.