comp.lang.ada
 help / color / mirror / Atom feed
From: "Egil Høvik" <egilhovik@hotmail.com>
Subject: Re: Limited returns
Date: Thu, 26 Jun 2008 05:35:34 -0700 (PDT)
Date: 2008-06-26T05:35:34-07:00	[thread overview]
Message-ID: <449184cd-f581-46ad-810f-dddd5555ebad@p25g2000hsf.googlegroups.com> (raw)
In-Reply-To: pt291p6yh4g9.1iey97ygy74vl.dlg@40tude.net

On Jun 23, 4:21 pm, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:
> Let's consider this:
>
>    with Ada.Finalization;
>    procedure Test_Limited_Stuff is
>       type I is limited interface;
>
>       type T is new Ada.Finalization.Limited_Controlled with record
>          A : Integer;
>       end record;
>
>       type S is new T and I with record
>          Self : not null access S'Class := S'Unchecked_Access;
>       end record;
>
>       function Factory return I'Class is
>       begin
>          return X : S;
> -- GNAT: wrong type for return_subtype_indication
>       end Factory;
>    begin
>       null;
>    end Test_Limited_Stuff;
>
> Is it illegal? I am surprised why? S is in I'Class.
>
> OK, if that is indeed illegal, then let's make another try:
>
>       function Factory return I'Class is
>       begin
>          return X : I'Class := S'(T with others => <>);
> -- GNAT: expected an access type with designated type "S'Class" defined ...
> -- found an access type with designated type "I'Class" defined ...
>       end Factory;
>
> ...still illegal, but more interesting. It seems that a Rosen's trick
> member cannot be initialized because the object's type is more general than
> the designated access type. It should not be so. A compiler bug?
>
> --
> Regards,
> Dmitry A. Kazakovhttp://www.dmitry-kazakov.de



If the goal is to make this compile, do this:

      function Factory return I'Class is
         function S_Factory return S is
         begin
            return X : S;
         end S_Factory;
      begin
         return X : I'Class := S_Factory;
      end Factory;


But then it seems that dispatching on methods of I is broken...
(at least I couldn't get it to work with an abstract procedure.
Didn't
dispatch to the overridden procedure implemented by S or give an
error...)





  parent reply	other threads:[~2008-06-26 12:35 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-23 14:21 Limited returns Dmitry A. Kazakov
2008-06-23 15:04 ` fedya_fedyakoff
2008-06-23 15:20   ` fedya_fedyakoff
2008-06-23 16:53     ` Dmitry A. Kazakov
2008-06-24 10:56       ` fedya_fedyakoff
2008-06-24 13:51         ` Dmitry A. Kazakov
2008-06-24 15:01           ` fedya_fedyakoff
2008-06-24 16:31             ` Dmitry A. Kazakov
2008-06-24 16:42               ` Dmitry A. Kazakov
2008-06-23 15:49   ` Adam Beneschan
2008-06-24 10:13     ` fedya_fedyakoff
2008-06-23 15:15 ` Adam Beneschan
2008-06-23 17:03   ` Dmitry A. Kazakov
2008-06-23 18:15     ` Adam Beneschan
2008-06-23 19:44       ` Dmitry A. Kazakov
2008-06-26 12:35 ` Egil Høvik [this message]
2008-06-26 14:12   ` Dmitry A. Kazakov
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox