Bug 8389 – Classes, nested in the same base class cannot be derived from.
Status
RESOLVED
Resolution
DUPLICATE
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-07-13T23:26:00Z
Last change time
2012-07-14T07:30:19Z
Assigned to
nobody
Creator
gor
Comments
Comment #0 by gor — 2012-07-13T23:26:04Z
class Fruit
{
class Seed {} // Not static, because this.outer is necessary
}
class Apple: Fruit
{
class RedAppleSeed: Fruit.Seed {}
class GreenAppleSeed: Fruit.Seed {}
}
DMD 2.059:
Error: class main.Apple.RedAppleSeed is nested within Apple, but super class
Seed is nested within Fruit
Error: class main.Apple.GreenAppleSeed is nested within Apple, but super class
Seed is nested within Fruit
Comment #1 by chatelet.guillaume — 2012-07-14T05:09:35Z
Indeed. The following is valid Java code and I would have expected it to work with D too as D took the Java way for OOP.
class Fruit {
class Seed {
}
}
class Apple extends Fruit {
class AppleSeed extends Fruit.Seed {
Apple getOuter() {
return Apple.this;
}
}
}
class Main {
public static void main(String[] args) {
final Apple apple = new Apple();
final Apple.AppleSeed appleSeed = apple.new AppleSeed();
assert (appleSeed instanceof Fruit.Seed);
assert (apple == appleSeed.getOuter());
assert (appleSeed.getOuter() instanceof Apple);
assert (appleSeed.getOuter() instanceof Fruit);
}
}
Comment #2 by chatelet.guillaume — 2012-07-14T05:15:02Z
*** This issue has been marked as a duplicate of issue 1175 ***
Comment #3 by qwertie256 — 2012-07-14T07:30:19Z
So this is a regression?
I am using this feature in my Android Java code too.