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
}
}
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