[Issue 24716] New: Outer class in derived inner class loses its type.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Aug 24 17:33:14 UTC 2024


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 at puremagic.com
          Reporter: turkeyman at 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.

--


More information about the Digitalmars-d-bugs mailing list