comp.lang.ada
 help / color / mirror / Atom feed
* procedure renames creates a primitive operation?
@ 2017-08-29 15:39 Jere
  2017-08-29 17:42 ` AdaMagica
  2017-08-31  1:24 ` Randy Brukardt
  0 siblings, 2 replies; 3+ messages in thread
From: Jere @ 2017-08-29 15:39 UTC (permalink / raw)


I was curious if this was a bug or intended.  
Given the following code:

***************************************************

procedure Main is

   package Some_Package is

      type Main_Type is tagged null record;
      
      package Non_Primitive_Ops is
         procedure Some_Op(Obj : Main_Type) is null;
      end Non_Primitive_Ops;
      
      -- without this line, the file correctly generates compiler errors
      procedure Some_Op(Obj : Main_Type) renames Non_Primitive_Ops.Some_Op;

   end Some_Package;

   Var : Some_Package.Main_Type;
   
   package Other_Package is
      
      type Derived_Type is new Some_Package.Main_Type with null record;
      
      
      -- Should this create a compiler error?
      overriding
      procedure Some_Op(Obj : Derived_Type) is null;
      
   end Other_Package;
   
begin
   
   Var.Some_Op; -- Should this create a compiler error?

end Main;

***************************************************

I used a renames clause to bring a non primitive operation 
into scope (for client readability when calling the procedure).  
However, when I did that, it created a primitive operation.  
Is this correct behavior or a bug?

It seems odd that a procedure created through a renames clause 
would be primitive, but perhaps it is intended?

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

* Re: procedure renames creates a primitive operation?
  2017-08-29 15:39 procedure renames creates a primitive operation? Jere
@ 2017-08-29 17:42 ` AdaMagica
  2017-08-31  1:24 ` Randy Brukardt
  1 sibling, 0 replies; 3+ messages in thread
From: AdaMagica @ 2017-08-29 17:42 UTC (permalink / raw)


Hm, I'm not sure whether this is a compiler error (a nonprimitve becoming primitive by renaming?).

As a related example, the following renaming of a primitive op. creates a separate slot in the dispatching table, i.e. you can override both operations differently:

package Pack is

  type T is tagged private;

  procedure P (X: T);
  procedure Q (Y: T) renames P;

end Pack;

with Pack;
package Qack is

  type S is new Pack.T with private;

  overriding procedure P (X: S);
  overriding procedure Q (X: S);  -- no renaming of P!

end Qack;


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

* Re: procedure renames creates a primitive operation?
  2017-08-29 15:39 procedure renames creates a primitive operation? Jere
  2017-08-29 17:42 ` AdaMagica
@ 2017-08-31  1:24 ` Randy Brukardt
  1 sibling, 0 replies; 3+ messages in thread
From: Randy Brukardt @ 2017-08-31  1:24 UTC (permalink / raw)


"Jere" <jhb.chat@gmail.com> wrote in message 
news:bc765307-02bd-4a38-b60c-4b743de6b3e4@googlegroups.com...
>I was curious if this was a bug or intended.
...
> I used a renames clause to bring a non primitive operation
> into scope (for client readability when calling the procedure).
> However, when I did that, it created a primitive operation.
> Is this correct behavior or a bug?

Yes, a renames of a non-primitive can be primitive. Similarly, a renames of 
a primitive can be non-primitive.

Its an intended bug. That is, it is generally acknowledged that this 
semantics is the worst possible choice (you've stumbled on one reason why). 
There are some really horrid consequences for things like class-wide 
preconditions. But it wasn't obvious what choice made sense at the time it 
was made in Ada 95. It's way too late to change now, of course.

                                  Randy.


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

end of thread, other threads:[~2017-08-31  1:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-29 15:39 procedure renames creates a primitive operation? Jere
2017-08-29 17:42 ` AdaMagica
2017-08-31  1:24 ` Randy Brukardt

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