comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Overring function and its returned type
Date: Sat, 10 Nov 2012 01:55:11 -0600
Date: 2012-11-10T01:55:11-06:00	[thread overview]
Message-ID: <k7l195$525$1@munin.nbi.dk> (raw)
In-Reply-To: op.wnhvol1wule2fv@cardamome

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2553 bytes --]

"Yannick Duch�ne (Hibou57)" <yannick_duchene@yahoo.fr> wrote in message 
news:op.wnhvol1wule2fv@cardamome...

>     procedure Ex  is
>
>        -- ========================================
>
>        package P1 is
>
>           type R is interface;
>           type T is interface;
>
>          not overriding
>           function F
>             (E : T)
>              return R'Class
>              is abstract;
>        end;
>
>        -- ========================================
>
>        package P2 is
>
>           type R is interface and P1.R;
>           type T is interface and P1.T;
>
>           overriding
>           function F
>             (E : T)
>              return R'Class -- Not overriding :-(
>              is abstract;
>        end;
>
>        -- ========================================

I'd strongly suggest to use different names for different types in examples, 
otherwise you'll confuse everyone (and yourself). Just because you can use 
the same name in the real code (and might want to in unusual circumstances) 
is no good reason to make examples that confuse the heck out of everyone.

In any case, overriding requires subtype conformance. And if you properly 
named the types, the problem would be obvious.

        package P2 is

           type R2 is interface and P1.R;
           type T2 is interface and P1.T;

           overriding
           function F
             (E : T2)
              return R2'Class -- Not overriding :-(
              is abstract;
        end;

Since overriding requires subtype conformance (among other things, requiring 
the same subtype on all non-controlling parameters and results), and 
R2'Class /= R'Class (and this isn't a controlling result), no overriding is 
possible. There are good reasons for these restrictions (mostly 
implementation-oriented).

I'm sure there exist (very limited) cases where it might make sense to relax 
subtype conformance, but there would need to be a strong justification for 
the significant added complication in the language rules and implementation. 
I'm pretty certain that an example using types T and R isn't it.

In any case, Ada 2012 is finished (with possibility of some editorial 
corrections in the final edition, but nothing substansive). If we were going 
to fix anything in it, it would be the handful of bad bugs that have been 
identified, surely nothing involving features that are unchanged in Ada 2012 
(which is the case with overriding, modulo wording bugs).

                                                       Randy.






  parent reply	other threads:[~2012-11-16  9:32 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-09  7:13 Overring function and its returned type Yannick Duchêne (Hibou57)
2012-11-09  7:22 ` Yannick Duchêne (Hibou57)
2012-11-09  8:24 ` Dmitry A. Kazakov
2012-11-09  9:14   ` Yannick Duchêne (Hibou57)
2012-11-09 13:11     ` Dmitry A. Kazakov
2012-11-09 21:36       ` Yannick Duchêne (Hibou57)
2012-11-09 19:24   ` Adam Beneschan
2012-11-09 19:34 ` Adam Beneschan
2012-11-09 22:00   ` J-P. Rosen
2012-11-09 22:30     ` Yannick Duchêne (Hibou57)
2012-11-09 19:57 ` sbelmont700
2012-11-09 21:10   ` Yannick Duchêne (Hibou57)
2012-11-09 21:56     ` sbelmont700
2012-11-10  0:28     ` Yannick Duchêne (Hibou57)
2012-11-10  2:35       ` Yannick Duchêne (Hibou57)
2012-11-15 15:13   ` Peter C. Chapin
2012-11-16 10:40     ` Maciej Sobczak
2012-11-16 12:39       ` Peter C. Chapin
2012-11-16 15:27         ` Maciej Sobczak
2012-11-16 17:29           ` Peter C. Chapin
2012-11-17  4:16           ` Yannick Duchêne (Hibou57)
2012-11-17 19:11             ` Robert A Duff
2012-11-18 14:53               ` AdaMagica
2012-11-19  8:41                 ` Yannick Duchêne (Hibou57)
2012-11-19 13:04                   ` AdaMagica
2012-11-19 15:19                     ` Dmitry A. Kazakov
2012-11-19 23:42                   ` Randy Brukardt
2012-11-10  7:55 ` Randy Brukardt [this message]
2012-11-11  1:02   ` Yannick Duchêne (Hibou57)
replies disabled

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