View mode: basic / threaded / horizontal-split · Log in · Help
July 14, 2012
Re: nested class inheritance
On 7/14/12 5:36 AM, Guillaume Chatelet wrote:
> 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);
>      }
> }
>
> This is valid Java code actually and I agree with Gor I would have
> expected it to work with D.
>
> Guillaume

You may want to add the example to the bug report.

Thanks,

Andrei
July 14, 2012
Re: nested class inheritance
On 07/14/12 13:51, Andrei Alexandrescu wrote:
> On 7/14/12 5:36 AM, Guillaume Chatelet wrote:
>> 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);
>>      }
>> }
>>
>> This is valid Java code actually and I agree with Gor I would have
>> expected it to work with D.
>>
>> Guillaume
> 
> You may want to add the example to the bug report.
> 
> Thanks,
> 
> Andrei

Done.
http://d.puremagic.com/issues/show_bug.cgi?id=8389

Guillaume
July 14, 2012
Re: nested class inheritance
On 07/14/12 11:41, Vladimir Panteleev wrote:
> On Friday, 13 July 2012 at 18:00:05 UTC, Gor Gyolchanyan wrote:
>> Which doesn't make sense, IMO. What do you guys think about this? Who
>> makes
>> more sense me or DMD 2.059?
> 
> http://d.puremagic.com/issues/show_bug.cgi?id=1175
> https://github.com/D-Programming-Language/dmd/pull/889
> 

So I marked 8389 as a duplicate of 1175 and closed the issue ( as 1175
has been resolved too)
I hope you don't mind Gor. Feel free to reopen if needed.

Guillaume
July 14, 2012
Re: nested class inheritance
On Sat, Jul 14, 2012 at 4:17 PM, Guillaume Chatelet <
chatelet.guillaume@gmail.com> wrote:

> On 07/14/12 11:41, Vladimir Panteleev wrote:
> > On Friday, 13 July 2012 at 18:00:05 UTC, Gor Gyolchanyan wrote:
> >> Which doesn't make sense, IMO. What do you guys think about this? Who
> >> makes
> >> more sense me or DMD 2.059?
> >
> > http://d.puremagic.com/issues/show_bug.cgi?id=1175
> > https://github.com/D-Programming-Language/dmd/pull/889
> >
>
> So I marked 8389 as a duplicate of 1175 and closed the issue ( as 1175
> has been resolved too)
> I hope you don't mind Gor. Feel free to reopen if needed.
>
> Guillaume
>

Sure, it's fine. :-) As long as the damn thing works. :-D

-- 
Bye,
Gor Gyolchanyan.
July 14, 2012
Re: nested class inheritance
On 13/07/2012 21:10, Andrei Alexandrescu wrote:
> On 7/13/12 3:07 PM, Gor Gyolchanyan wrote:
>> On Fri, Jul 13, 2012 at 11:03 PM, Andrei Alexandrescu
>> <SeeWebsiteForEmail@erdani.org <mailto:SeeWebsiteForEmail@erdani.org>>
>> wrote:
>>
>> On 7/13/12 2:30 PM, Gor Gyolchanyan wrote:
>>
>> The whole point is to have it not static. I need it to be properly
>> nested with the this.outer.
>>
>>
>> What would be the type of this.outer?
>>
>> Andrei
>>
>>
>> For Fruit.Seed it's Fruit, for AppleSeed it's Apple. This makes sense
>> because the Apple, which AppleSeed sees is the same object, which
>> Fruit.Seed sees as it's base type Fruit.
>
> That would mean AppleSeed has two outer fields: a Fruit and an Apple.
>
> Andrei
>

An Apple is a Fruit, so it shouldn't be a problem and don't require 2 
fields.
July 14, 2012
Re: nested class inheritance
On 14/07/2012 08:27, Gor Gyolchanyan wrote:
> On Sat, Jul 14, 2012 at 12:31 AM, Andrei Alexandrescu
> <SeeWebsiteForEmail@erdani.org <mailto:SeeWebsiteForEmail@erdani.org>>
> wrote:
>
>     On 7/13/12 3:49 PM, Gor Gyolchanyan wrote:
>
>         On Fri, Jul 13, 2012 at 11:41 PM, Andrei Alexandrescu
>         <SeeWebsiteForEmail@erdani.org
>         <mailto:SeeWebsiteForEmail@erdani.org>
>         <mailto:SeeWebsiteForEmail@__erdani.org
>         <mailto:SeeWebsiteForEmail@erdani.org>>>
>
>         wrote:
>
>              On 7/13/12 3:36 PM, Gor Gyolchanyan wrote:
>
>                  The initial question was: why does DMD 2.059 reject
>         this if this
>                  makes
>                  sense?
>                  It's not even a new feature. It's a (possibly) new (and
>         apparently
>                  sensible) use case of an existing feature.
>
>
>              I think the simple answer is there was no provision for it. The
>              feature copies the Java feature, and I don't think Java has
>              something like what you defined.
>
>              Andrei
>
>
>         Well, the nested classes are pretty much useless without this
>         feature.
>         Except for translating Java code. If I had multiple inheritance, I'd
>         just make the Apple as base class and have all the seeds virtually
>         derive from it. Not having multiple inheritance drove me to try
>         the next
>         best think. And after it failed, I complained about it.. And here we
>
>         are. Is it a difficult thing to fix?
>
>
>     I don't know, you may want to submit an enhancement request.
>
>     Andrei
>
>
> http://d.puremagic.com/issues/show_bug.cgi?id=8389
>
> Anyone who thinks this is important, please vote up.
>
> --
> Bye,
> Gor Gyolchanyan.

This is something to do, but I don't know if it is really that important.
July 14, 2012
Re: nested class inheritance
On Sat, Jul 14, 2012 at 8:17 PM, deadalnix <deadalnix@gmail.com> wrote:

> On 14/07/2012 08:27, Gor Gyolchanyan wrote:
>
>> On Sat, Jul 14, 2012 at 12:31 AM, Andrei Alexandrescu
>>
>> <SeeWebsiteForEmail@erdani.org <mailto:SeeWebsiteForEmail@**erdani.org<SeeWebsiteForEmail@erdani.org>
>> >>
>> wrote:
>>
>>     On 7/13/12 3:49 PM, Gor Gyolchanyan wrote:
>>
>>         On Fri, Jul 13, 2012 at 11:41 PM, Andrei Alexandrescu
>>         <SeeWebsiteForEmail@erdani.org
>>         <mailto:SeeWebsiteForEmail@**erdani.org<SeeWebsiteForEmail@erdani.org>
>> >
>>         <mailto:SeeWebsiteForEmail@__e**rdani.org <http://erdani.org>
>>
>>         <mailto:SeeWebsiteForEmail@**erdani.org<SeeWebsiteForEmail@erdani.org>
>> >>>
>>
>>         wrote:
>>
>>              On 7/13/12 3:36 PM, Gor Gyolchanyan wrote:
>>
>>                  The initial question was: why does DMD 2.059 reject
>>         this if this
>>                  makes
>>                  sense?
>>                  It's not even a new feature. It's a (possibly) new (and
>>         apparently
>>                  sensible) use case of an existing feature.
>>
>>
>>              I think the simple answer is there was no provision for it.
>> The
>>              feature copies the Java feature, and I don't think Java has
>>              something like what you defined.
>>
>>              Andrei
>>
>>
>>         Well, the nested classes are pretty much useless without this
>>         feature.
>>         Except for translating Java code. If I had multiple inheritance,
>> I'd
>>         just make the Apple as base class and have all the seeds virtually
>>         derive from it. Not having multiple inheritance drove me to try
>>         the next
>>         best think. And after it failed, I complained about it.. And here
>> we
>>
>>         are. Is it a difficult thing to fix?
>>
>>
>>     I don't know, you may want to submit an enhancement request.
>>
>>     Andrei
>>
>>
>> http://d.puremagic.com/issues/**show_bug.cgi?id=8389<http://d.puremagic.com/issues/show_bug.cgi?id=8389>
>>
>> Anyone who thinks this is important, please vote up.
>>
>> --
>> Bye,
>> Gor Gyolchanyan.
>>
>
> This is something to do, but I don't know if it is really that important.
>

It's already fixed and will be in DMD 2.060

-- 
Bye,
Gor Gyolchanyan.
July 14, 2012
Re: nested class inheritance
The only problem about this is:

class Fruit
{
  class Seed {
    void SetFruit(Fruit fruit)
    {
      this.outer = fruit;
    }
  }
}

class Apple: Fruit
{
  void AppleOnlyMethod(){ ... }

  class AppleSeed: Fruit.Seed {
    void DoSomething()
    {
      AppleOnlyMethod();
    }
  }

  auto GetNewSeed() { return new AppleSeed(); }
}

auto apple = new Apple();
auto seed = apple.GetNewSeed();
seed.SetFruit(new Fruit());
seed.DoSomething(); //what happens here?

Kind Regards
Benjamin Thaut
July 14, 2012
Re: nested class inheritance
On Sat, Jul 14, 2012 at 9:12 PM, Benjamin Thaut <code@benjamin-thaut.de>wrote:

> The only problem about this is:
>
> class Fruit
> {
>   class Seed {
>     void SetFruit(Fruit fruit)
>     {
>       this.outer = fruit;
>     }
>   }
> }
>
> class Apple: Fruit
> {
>   void AppleOnlyMethod(){ ... }
>
>   class AppleSeed: Fruit.Seed {
>     void DoSomething()
>     {
>       AppleOnlyMethod();
>     }
>   }
>
>   auto GetNewSeed() { return new AppleSeed(); }
> }
>
> auto apple = new Apple();
> auto seed = apple.GetNewSeed();
> seed.SetFruit(new Fruit());
> seed.DoSomething(); //what happens here?
>
> Kind Regards
> Benjamin Thaut
>
>
I think this.outer is not an lvalue, which solves the problem. It wouldn't
make sense to have it an lvalue, because the object is specifically created
out of the initial outer object.

-- 
Bye,
Gor Gyolchanyan.
July 14, 2012
Re: nested class inheritance
Am 14.07.2012 19:18, schrieb Gor Gyolchanyan:
> On Sat, Jul 14, 2012 at 9:12 PM, Benjamin Thaut <code@benjamin-thaut.de
> <mailto:code@benjamin-thaut.de>> wrote:
>
>     The only problem about this is:
>
>     class Fruit
>     {
>        class Seed {
>          void SetFruit(Fruit fruit)
>          {
>            this.outer = fruit;
>          }
>        }
>     }
>
>     class Apple: Fruit
>     {
>        void AppleOnlyMethod(){ ... }
>
>        class AppleSeed: Fruit.Seed {
>          void DoSomething()
>          {
>            AppleOnlyMethod();
>          }
>        }
>
>        auto GetNewSeed() { return new AppleSeed(); }
>     }
>
>     auto apple = new Apple();
>     auto seed = apple.GetNewSeed();
>     seed.SetFruit(new Fruit());
>     seed.DoSomething(); //what happens here?
>
>     Kind Regards
>     Benjamin Thaut
>
>
> I think this.outer is not an lvalue, which solves the problem. It
> wouldn't make sense to have it an lvalue, because the object is
> specifically created out of the initial outer object.
>
> --
> Bye,
> Gor Gyolchanyan.

The last time I checked you could reassign outer ;-)
1 2 3 4 5 6
Top | Discussion index | About this forum | D home