Thread overview
[Issue 8287] New: 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
Jun 23, 2012
Trey Brisbane
Jun 23, 2012
Trey Brisbane
Jun 23, 2012
Trey Brisbane
Jun 24, 2012
Jonathan M Davis
Jun 24, 2012
Trey Brisbane
Jun 25, 2012
Jonathan M Davis
June 23, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8287

           Summary: 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
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: tbrisbane@hotmail.com


--- Comment #0 from Trey Brisbane <tbrisbane@hotmail.com> 2012-06-23 03:24:09 PDT ---
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. :)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 23, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8287



--- Comment #1 from Trey Brisbane <tbrisbane@hotmail.com> 2012-06-23 03:27:28 PDT ---
Created an attachment (id=1117)
objectA module

Contains a class called objectA with a static member doSomething()

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 23, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8287



--- Comment #2 from Trey Brisbane <tbrisbane@hotmail.com> 2012-06-23 03:28:36 PDT ---
Created an attachment (id=1118)
main module

Attempts to access the objectA class's doSomething member, showing the issue.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 24, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8287


Jonathan M Davis <jmdavisProg@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg@gmx.com


--- Comment #3 from Jonathan M Davis <jmdavisProg@gmx.com> 2012-06-23 17:13:47 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 24, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8287


bearophile_hugs@eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bearophile_hugs@eml.cc
         Resolution|                            |FIXED


--- Comment #4 from bearophile_hugs@eml.cc 2012-06-24 10:57:19 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 24, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8287



--- Comment #5 from Trey Brisbane <tbrisbane@hotmail.com> 2012-06-24 16:22:38 PDT ---
(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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 25, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8287


Jonathan M Davis <jmdavisProg@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|FIXED                       |INVALID


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------