D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 8389 - Classes, nested in the same base class cannot be derived from.
Summary: Classes, nested in the same base class cannot be derived from.
Status: RESOLVED DUPLICATE of issue 1175
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-07-13 23:26 UTC by Gor Gyolchanyan
Modified: 2012-07-14 07:30 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Gor Gyolchanyan 2012-07-13 23:26:04 UTC
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 Guillaume Chatelet 2012-07-14 05:09:35 UTC
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 Guillaume Chatelet 2012-07-14 05:15:02 UTC

*** This issue has been marked as a duplicate of issue 1175 ***
Comment 3 David Piepgrass 2012-07-14 07:30:19 UTC
So this is a regression?

I am using this feature in my Android Java code too.