www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7491] New: import symbol name unavailable in class scope

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

           Summary: import symbol name unavailable in class scope
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: dawg dawgfoto.de



struct S
{
    private import std.stdio;
}

class Base
{
    private import std.stdio;
}

class Derived : Base
{
    static void print()
    {
        std.stdio.writeln("Derived");
    }
}

void main()
{
    S.std.stdio.writeln("S");
    // Error: Base.std is not a declaration
    Base.std.stdio.writeln("Base");
    // Error: Derived.std is not a declaration
    Derived.std.stdio.writeln("Derived");

    Derived.print();
}

---------

Solution would be to add the disabled code.
https://github.com/D-Programming-Language/dmd/commit/4bce0eb3acbb9ecce5988c55281aa1b3fd5a42f0#L0R7832

----
This is problematic in the following case.
----
module a;

class Base
{
    private import std.algorithm;
}

----
module b;
import a, std.stdio;

class Derived : Base
{
    void foo()
    {
        // 'std' is looked up through Base.std rather than through module level
        // but Derived has no access right to the private import.
        std.stdio.writeln("Derived");
    }
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 12 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7491


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |INVALID



01:48:01 PST ---
Right, the lookup rules are being followed by the compiler, that is, super
classes are looked at before module scope is. To get around that, prefix with
the . as in:

module b;
import a, std.stdio;

class Derived : Base
{
    void foo()
    {
        .std.stdio.writeln("Derived");
        ^ note . prefix
    }
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 13 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7491


dawg dawgfoto.de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |



If that's how things are supposed to work we should enable 'Base.std.stdio'
access.
https://github.com/D-Programming-Language/dmd/pull/712

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 13 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7491


SomeDude <lovelydear mailmetrash.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lovelydear mailmetrash.com



PDT ---
See also issue 7494

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 21 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7491




Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/b19051227f2c06c72f248f23dca13aad73e1d321


fix Issue 7491 - import symbol name unavailable in class scope

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 21 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7491




Walter, D1 also has this bug, but the change of symbol lookup path would
*break* existing codes. Therefore I think we should not *fix* this in D1.

How about?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 21 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7491


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com
            Version|D2                          |D1



13:09:41 PST ---
Marking as D1-only, Walter can close it if he agrees with Kenji.

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