comp.lang.ada
 help / color / mirror / Atom feed
* renaming as classwide type
@ 2023-09-21 19:29 Simon Belmont
  2023-09-21 21:03 ` G.B.
  2023-09-22  9:31 ` Simon Wright
  0 siblings, 2 replies; 5+ messages in thread
From: Simon Belmont @ 2023-09-21 19:29 UTC (permalink / raw)


is it really illegal to rename an object as it's classwide parent?  gnat claims so.  Similar results using a type extension as a generic formal "in out" object of classwide type.

  declare  
    type P is interface;
    type C is new P with null record;
  
    o : C;
    r : P'Class renames o;  --error
    begin
      null;
    end;

expected type "P'Class" defined at line
found type "C" defined at line

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: renaming as classwide type
  2023-09-21 19:29 renaming as classwide type Simon Belmont
@ 2023-09-21 21:03 ` G.B.
  2023-09-21 23:19   ` Simon Belmont
  2023-09-22  9:31 ` Simon Wright
  1 sibling, 1 reply; 5+ messages in thread
From: G.B. @ 2023-09-21 21:03 UTC (permalink / raw)


On 21.09.23 21:29, Simon Belmont wrote:
> is it really illegal to rename an object as it's classwide parent?  gnat claims so.  Similar results using a type extension as a generic formal "in out" object of classwide type.
> 
>    declare
>      type P is interface;
>      type C is new P with null record;
>    
>      o : C;
>      r : P'Class renames o;  --error
>      begin
>        null;
>      end;
> 
> expected type "P'Class" defined at line
> found type "C" defined at line

O does not denote an object of a class-wide type,
I think. However, P'Class (o) does, so that renaming
that would make r be of its declared type P'Class.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: renaming as classwide type
  2023-09-21 21:03 ` G.B.
@ 2023-09-21 23:19   ` Simon Belmont
  2023-09-26  5:46     ` Randy Brukardt
  0 siblings, 1 reply; 5+ messages in thread
From: Simon Belmont @ 2023-09-21 23:19 UTC (permalink / raw)


On Thursday, September 21, 2023 at 5:03:06 PM UTC-4, G.B. wrote:
> O does not denote an object of a class-wide type, 
> I think. However, P'Class (o) does, so that renaming 
> that would make r be of its declared type P'Class.

That seems needlessly pedantic, considering that assignment is fine (o2 : P'Class := o) as well as assigning it to an intermediate pointer (po : access P'Class := o'Access; r : P'Class renames po.all)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: renaming as classwide type
  2023-09-21 19:29 renaming as classwide type Simon Belmont
  2023-09-21 21:03 ` G.B.
@ 2023-09-22  9:31 ` Simon Wright
  1 sibling, 0 replies; 5+ messages in thread
From: Simon Wright @ 2023-09-22  9:31 UTC (permalink / raw)


Simon Belmont <sbelmont700@gmail.com> writes:

>     r : P'Class renames o;  --error

This compiles OK with GCC 13.1.0:

   r : P'Class renames P'Class (o);

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: renaming as classwide type
  2023-09-21 23:19   ` Simon Belmont
@ 2023-09-26  5:46     ` Randy Brukardt
  0 siblings, 0 replies; 5+ messages in thread
From: Randy Brukardt @ 2023-09-26  5:46 UTC (permalink / raw)


It's not needless; there is an implicit conversion on an assignment, and it 
only needs to work one way. When you rename a variable, the conversion has 
to work both ways. But that's problematic, since conversions often involve 
checks and we don't want checks popping up in unexpected places (both for 
implementation reasons and for readability reasons).

Also, renaming does not change the nominal subtype of an object, regardless 
of what subtype is given in the renames. Ada 2022 allows you to omit the 
type name altogether since it provides little value.

                        Randy.

"Simon Belmont" <sbelmont700@gmail.com> wrote in message 
news:5ab7e1d5-1491-49c3-877d-32bb6e12b43an@googlegroups.com...
On Thursday, September 21, 2023 at 5:03:06?PM UTC-4, G.B. wrote:
> O does not denote an object of a class-wide type,
> I think. However, P'Class (o) does, so that renaming
> that would make r be of its declared type P'Class.

That seems needlessly pedantic, considering that assignment is fine (o2 : 
P'Class := o) as well as assigning it to an intermediate pointer (po : 
access P'Class := o'Access; r : P'Class renames po.all) 


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-09-26  5:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-21 19:29 renaming as classwide type Simon Belmont
2023-09-21 21:03 ` G.B.
2023-09-21 23:19   ` Simon Belmont
2023-09-26  5:46     ` Randy Brukardt
2023-09-22  9:31 ` Simon Wright

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