Bug 7491 – import symbol name unavailable in class scope

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
All
OS
All
Creation time
2012-02-12T19:19:44Z
Last change time
2019-08-11T15:40:57Z
Keywords
pull, rejects-valid
Assigned to
No Owner
Creator
Martin Nowak

Comments

Comment #0 by code — 2012-02-12T19:19:44Z
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"); } }
Comment #1 by bugzilla — 2012-02-13T01:48:01Z
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 } }
Comment #2 by code — 2012-02-13T07:47:09Z
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
Comment #3 by lovelydear — 2012-04-21T06:09:43Z
See also issue 7494
Comment #4 by github-bugzilla — 2012-07-21T00:29:58Z
Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/b19051227f2c06c72f248f23dca13aad73e1d321 Merge pull request #712 from dawgfoto/fix7491 fix Issue 7491 - import symbol name unavailable in class scope
Comment #5 by k.hara.pg — 2012-07-21T00:51:33Z
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?
Comment #6 by andrej.mitrovich — 2013-02-05T13:09:41Z
Marking as D1-only, Walter can close it if he agrees with Kenji.
Comment #7 by pro.mathias.lang — 2019-08-11T15:40:57Z
D1 is gone