www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5084] New: Static code does not ignore instance names during name lookup

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5084

           Summary: Static code does not ignore instance names during name
                    lookup
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: ah08010-d yahoo.com



PDT ---
In the code
==========
module scratch;

import std.stdio;

int[ 3 ] x;

struct S {

    int[ 2 ] x;

    static void foo() {
        writeln( x[2] );
    }
}
=========

I would expect that the static method performed static name lookup. In this
case, 
that would resolve the x[] reference to the variable at module scope.

Instead, the reference is apparently resolved to the member, despite the member
being an illegal reference. If the [2], which generates an "index out of
bounds" error, is replaced with [1], then the compiler proceeds to issue a
"this required for reference to member" error.

Obviously, .x would work in this case, but I think this may be a general bug.
Alternatively, could someone provide a pointer to the rules for name lookup?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 20 2010
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5084


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |andrej.mitrovich gmail.com
         Resolution|                            |INVALID



17:52:46 PST ---
That would mean that an imported module which has a module-scoped variable or
property function with the same name as a non-static field could hijack that
field instead of giving you an error. It would be dangerous to allow such
behavior.

You can always use the dot prefix to lookup module-scoped variables, via
writeln(.x[2]).

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