Thread overview
[Issue 8389] New: Classes, nested in the same base class cannot be derived from.
Jul 14, 2012
Gor Gyolchanyan
Jul 14, 2012
Guillaume Chatelet
Jul 14, 2012
Guillaume Chatelet
Jul 14, 2012
David Piepgrass
July 14, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8389

           Summary: Classes, nested in the same base class cannot be
                    derived from.
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: gor@boloneum.com


--- Comment #0 from Gor Gyolchanyan <gor@boloneum.com> 2012-07-13 23:26:04 PDT ---
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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 14, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8389


Guillaume Chatelet <chatelet.guillaume@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |chatelet.guillaume@gmail.co
                   |                            |m


--- Comment #1 from Guillaume Chatelet <chatelet.guillaume@gmail.com> 2012-07-14 05:09:35 PDT ---
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);
    }
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 14, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8389


Guillaume Chatelet <chatelet.guillaume@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE


--- Comment #2 from Guillaume Chatelet <chatelet.guillaume@gmail.com> 2012-07-14 05:15:02 PDT ---
*** This issue has been marked as a duplicate of issue 1175 ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 14, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8389


David Piepgrass <qwertie256@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |qwertie256@gmail.com


--- Comment #3 from David Piepgrass <qwertie256@gmail.com> 2012-07-14 07:30:19 PDT ---
So this is a regression?

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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------