[GAP] Strange OO behaviour when using private primitive subprograms

Matthew Heaney matthewjheaney at earthlink.net
Tue Jun 5 14:03:14 CEST 2007


 

> -----Original Message-----
> From: gap-bounces at gnat.info [mailto:gap-bounces at gnat.info] On 
> Behalf Of Diego Alonso Cáceres
> Sent: Tuesday, June 05, 2007 6:34 AM
> 
> last week I was trying to find a way to make Java-like 
> protected methods using the new OO features of Ada'05 and I 
> found that the compiler behaves in a strange way. I have 
> attached a small project with all the files and I have 
> compiled them with GPS 4.0.2 (20061211) in both Linux a 
> Windows machines.

When I compile main.adb I get the following errors:

main.adb:15:05: no selector "Private_Op" for type "T" defined at
p_parent.ads:2
main.adb:23:05: no selector "Private_Op" for type "TT" defined at
p_parent-child.ads:2
main.adb:38:05: no selector "Private_Op" for type "T" defined at
p_parent.ads:2
main.adb:45:05: no selector "Private_Op" for type "T'Class" defined at
p_parent.ads:2
main.adb:52:05: no selector "Private_Op" for type "T'Class" defined at
p_parent.ads:2
main.adb:59:05: no selector "Private_Op" for type "T'Class" defined at
p_parent.ads:2
main.adb:69:05: no selector "Private_Op" for type "T'Class" defined at
p_parent.ads:2
main.adb:78:08: no selector "Private_Op" for type "T'Class" defined at
p_parent.ads:2
main.adb:90:08: no selector "Private_Op" for type "T'Class" defined at
p_parent.ads:2

Compilation exited abnormally with code 1 at Tue Jun 05 11:50:38


Is this what you were expecting?


 
> So, let's focus on the problem. The package P_Parent has a 
> tagged type T and two primitive operations, one defined in 
> the public part and the other in the private one. I have also 
> declared two types that inherit from T, one in a child 
> package P_Parent-Child (TT) and one in a normal package 
> P_Child (U). I was surprised I was able to do T.Private_Op 
> but not Private_Op(T). Even more, TT.Private_Op also worked 
> but U.Private_Op did not!


If you are able to compile that program, then you must have an older, less
mature version of the compiler.

 
> This two examples are kind of confusing because they show you 
> don't get the same results using the new dot-notation and the 
> old one.

I don't think you can draw any conclusions, since your compiler is almost 6
months old.


> It also shows that private primitive operations do 
> not work well, and that they are not equally inherited by all 
> child classes. 

They are indeed "equally inherited" -- they're just not visible.


> It depends wheter the child tagged type is 
> declared in a child package or not. Any explanation about 
> this behaviour?

The visibility to an operation (or anything else, really) is controlled by
the module relationship.  A child unit has visibility to the private part of
the parent package; non-children do not have such visibility.




More information about the GAP mailing list