Version 1.1 of acs/ac-00183.txt

Unformatted version of acs/ac-00183.txt version 1.1
Other versions for file acs/ac-00183.txt

!standard 7.3.1(6)          10-02-08 AC95-00183/01
!standard 8.3(10/1)
!class confirmation 10-02-08
!status received no action 10-02-08
!status received 09-06-11
!subject Visibility and inherited operations
!summary
!appendix

!topic Question about visibility and inherited operations
!reference 7.3.1(6), 8.3
!from Adam Beneschan 09-06-11
!discussion

Hi, everyone,

This isn't really a comment about the Ada language rules, but rather a check to
make sure I understand them correctly.  Our compiler and GNAT both compile the
following source with no errors, but I believe that this is wrong; I'd like to
check my understanding of the RM before I try to hack on our compiler.  (Of
course, this could turn into a proposed change if it turns out the rules are
ambiguous or that the result is unintended and undesirable.)

By the way, if this is an inappropriate list for asking language-lawyer
questions like this and there's a better way to ask, please let me
know---thanks.

    package Pak1 is
        type T1 is tagged record
            F1 : Integer;
        end record;
        procedure Op1 (X : in out T1);
        procedure Op2 (X : in out T1);
    end Pak1;

    package body Pak1 is

        procedure Op1 (X : in out T1) is
        begin
            null;
        end Op1;

        procedure Op2 (X : in out T1) is
        begin
            null;
        end Op2;

    end Pak1;

    with Pak1;
    package Pak2 is
        type T2 is new Pak1.T1 with null record;
        Op2 : Integer;
    private
        Op1 : Integer;
    end Pak2;

    with Pak2;
    package Pak3 is
        type T3 is new Pak2.T2 with null record;
        procedure Test;
    end Pak3;

    package body Pak3 is

        procedure Test is
            V : T3;
        begin
            Op1 (V);   -- OK
            Op2 (V);   -- ERROR:
        end Test;

    end Pak3;

    package Pak2.Pak4 is
        procedure Test2;
    private
        type T4 is new T2 with null record;
    end Pak2.Pak4;

    package body Pak2.Pak4 is

        procedure Test2 is
            V : T4;
        begin
            Op1 (V);   -- ERROR:
            Op2 (V);   -- ERROR:
        end Test2;

    end Pak2.Pak4;


    private package Pak2.Pak5 is
        procedure Test3;
        type T5 is new T2 with null record;
    end Pak2.Pak5;

    package body Pak2.Pak5 is

        procedure Test3 is
            V : T5;
        begin
            Op1 (V);   -- ERROR:
            Op2 (V);   -- ERROR:
        end Test3;

    end Pak2.Pak5;

The way I read the rules is this: In Pak2, implicit declarations of
Op1 and Op2 are declared right after the declaration of T2.

In Pak3, when T3 is derived from T2, the rule in 7.3.1(6) says that "each
inherited primitive subprogram is implicitly declared at the earliest place, if
any, immediately within the declarative region in which the type_declaration [of
T3] occurs, but after the type_declaration, where the corresponding declaration
from the parent is visible.  If there is no such place, then the inherited
subprogram is not declared at all."  Since the declaration of Op2 the variable
overrides the implicit declaration of procedure Op2 in Pak2 (8.3(10)), this
means that the implicit declaration of procedure Op2 is hidden from all
visibility within the scope of the variable Op2 (8.3(15)), which includes all of
Pak3's specification and body (8.2(10)).  Since the procedure Op2 is hidden from
all visibility, that means that there is "no such place" where the implicit
declaration of procedure Op2 becomes visible, which I believe means Op2 is not
implicitly declared at all for T3.  So the statement that tries to call Op2 on
an object of type T3 must be illegal.  It's also illegal for objects of type T4
and T5; and furthermore Op1 is not implicitly declared for those types either,
since the variable Op1 overrides the implicit procedure Op1 and therefore the
implicit procedure Op1 is not visible at any place where the private part of
Pak2 is visible.

So is my interpretation correct, or did I miss something again?

Thanks, I appreciate it.

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

From: Gary Dismukes
Date: Thursday, June 11, 2009  6:47 PM

> By the way, if this is an inappropriate list for asking
> language-lawyer questions like this and there's a better way to ask,
> please let me know---thanks.

Seems OK to me, but Randy will know for sure. :-)

> The way I read the rules is this: In Pak2, implicit declarations of
> Op1 and Op2 are declared right after the declaration of T2.
>
> In Pak3, when T3 is derived from T2, the rule in 7.3.1(6) says that
> "each inherited primitive subprogram is implicitly declared at the ...
> where the private part of Pak2 is visible.
>
> So is my interpretation correct, or did I miss something again?

Your interpretation looks right to me.  As far as I can see, your exegesis is
spot on, and both of the compilers are wrong.

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

Questions? Ask the ACAA Technical Agent