Bug 8287 – When a class with the same name as a module exists within that module and has static members, you're required to do modulename.classname.member() in order to access said members
Pretty much exactly what the summary says. Here is an example:
File 1:
module objectA;
class objectA {
public static void doSomething() {
...
}
}
File 2:
module main;
import objectA;
int main(string[] args) {
objectA.doSomething(); // Error: undefined identifier 'doSomething'
objectA.objectA.doSomething(); // Ok
return 0;
}
Obviously, the compiler is searching for a function called doSomething in the module objectA, when it should instead recognize that a class called objectA has been imported and an attempt is being made to access its static member doSomething().
Please note that this is my first bug submission, so if it's already known (I did search before posting this) or has a simple fix, please forgive me. :)
Comment #1 by tbrisbane — 2012-06-23T03:27:28Z
Created attachment 1117
objectA module
Contains a class called objectA with a static member doSomething()
Comment #2 by tbrisbane — 2012-06-23T03:28:36Z
Created attachment 1118
main module
Attempts to access the objectA class's doSomething member, showing the issue.
Comment #3 by issues.dlang — 2012-06-23T17:13:47Z
I believe that that's expected behavior.
Just rename the module so that it's all lowercase and the problem is solved. It's common practice to always name modules using only lowercase letters anyway.
Comment #4 by bearophile_hugs — 2012-06-24T10:57:19Z
I think D is working as designed here. Class and struct names start with an upper case, while modules start with a lower case. I suggest to close this bug report as wontfix.
Comment #5 by tbrisbane — 2012-06-24T16:22:38Z
(In reply to comment #3)
> I believe that that's expected behavior.
>
> Just rename the module so that it's all lowercase and the problem is solved.
> It's common practice to always name modules using only lowercase letters
> anyway.
(In reply to comment #4)
> I think D is working as designed here. Class and struct names start with an
> upper case, while modules start with a lower case. I suggest to close this bug
> report as wontfix.
Fair enough. :)
Thanks for your time.