Bug 24716 – Outer class in derived inner class loses its type.

Status
NEW
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2024-08-24T17:33:14Z
Last change time
2024-12-13T19:36:56Z
Keywords
pull
Assigned to
No Owner
Creator
Manu
Moved to GitHub: dmd#20498 →

Comments

Comment #0 by turkeyman — 2024-08-24T17:33:14Z
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.
Comment #1 by dlang-bot — 2024-08-25T07:16:33Z
@thewilsonator created dlang/dmd pull request #16810 "Fix bugzilla issue 24716" fixing this issue: - Fix bugzilla issue 24716 checks for `isNeedThisScope` should check up the inheritance chain for nested classes. https://github.com/dlang/dmd/pull/16810
Comment #2 by robert.schadek — 2024-12-13T19:36:56Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20498 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB