August 24 [Issue 24716] New: Outer class in derived inner class loses its type. | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=24716 Issue ID: 24716 Summary: Outer class in derived inner class loses its type. Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: normal Priority: P1 Component: dmd Assignee: nobody@puremagic.com Reporter: turkeyman@gmail.com Here's a situation: ```d import std.stdio; class Outer1 { int value1 = 100; class Inner1 { void print() { writeln("value1 from Outer1: ", value1); } } Inner1 make() { return new Inner1; } } class Outer2 : Outer1 { int value2 = 200; class Inner2 : Outer1.Inner1 { override void print() { writeln("value1 from Outer1: ", value1); // <- no problem! writeln("value2 from Outer2: ", value2); // error: accessing non-static variable `value2` requires an instance of `Outer2` } } override Inner2 make() { return new Inner2; } } ``` In this error, it says it requires an instance of Outer2, which it absolutely has, and MUST have; there's no possible arrangement where it doesn't. The outer reference is just carrying the type from its original declaration in the base class. It either needs a local alias typed correctly to shadow the base class outer reference, or symbol references to `outer` should include a cast to typeof(super), which is always true and safe. -- |
Copyright © 1999-2021 by the D Language Foundation