Version 1.4 of ais/ai-00122.txt
!standard 08.04 (08) 99-05-28 AI95-00122/03
!class confirmation 96-04-04
!status WG9 approved 98-06-12
!status ARG Approved 11-0-2 97-11-14
!status work item 96-04-10
!status received 96-04-04
!priority Medium
!difficulty Medium
!subject Use_type_clause where First Subtype is not Directly Visible
!summary
A use_type_clause can make the primitive operators of the type directly
visible even if the first subtype name itself is not directly visible.
!question
Consider:
package Types is
type Entier is range 0 .. 100;
end Types;
with Types;
package Definitions is
subtype Entier is Types.Entier;
end Definitions;
with Definitions;
use type Definitions.Entier;
procedure Test_Definitions is
Mon_Entier : Definitions.Entier := 0;
begin
Mon_Entier := Mon_Entier + 5; --
end Test_Definitions;
In the above example, does the "use type Definitions.Entier;" make the
"+" operator of type Entier directly visible? Note that the name
"Entier" is not directly visible in Test_Definitions.
!response
Yes, the above use_type_clause makes "+" directly visible, so the above
example is legal.
8.4(8) says:
For each type T or T'Class determined by a subtype_mark of a
use_type_clause whose scope encloses a place, the declaration of each
primitive operator of type T is potentially use-visible at this place if
its declaration is visible at this place.
In the last phrase, "its declaration" refers to "each primitive
operator". So, we need to know if the primitive "+" operator of type
Entier is visible in Test_Definitions. It is.
10.1.4(2) says:
2 The declarative_items of the environment are library_items appearing in
an order such that there are no forward semantic dependences.
The body of procedure Test_Definitions depends semantically upon the
declaration of package Types; therefore, the body of procedure
Test_Definitions appears after the declaration of package Types, in
the environment.
8.2(2-4) says:
2 The immediate scope of a declaration is a portion of the declarative
region immediately enclosing the declaration. The immediate scope starts at
the beginning of the declaration, except in the case of an overloadable
declaration, in which case the immediate scope starts just after the place
where the profile of the callable entity is determined (which is at the end
of the _specification for the callable entity, or at the end of the generic_
instantiation if an instance). The immediate scope extends to the end of the
declarative region, with the following exceptions:
3 The immediate scope of a library_item includes only its semantic
dependents.
4 The immediate scope of a declaration in the private part of a
library unit does not include the visible part of any public
descendant of that library unit.
Thus, in the environment, the body of Test_Definitions is within the
immediate scope of the declaration of Types.
8.2(10) says:
10 The scope of a declaration always contains the immediate scope of the
declaration. In addition, for a given declaration that occurs immediately
within the visible part of an outer declaration, or is a public child of an
outer declaration, the scope of the given declaration extends to the end of
the scope of the outer declaration, except that the scope of a library_item
includes only its semantic dependents.
The primitive "+" operator of type Entier is declared in the visible
part of package Types, so the body of Test_Definitions is within the
scope of this "+".
8.3(14) says:
14 A declaration is visible within its scope, except where hidden from all
visibility, as follows:
...
The "+" operator is not hidden from all visibility. Therefore, it is
visible at the point of the use_type_clause.
The use_type_clause then makes this "+" directly visible, by 8.4(8)
and 8.4(9-11).
Don't be confused by 8.3(2), which says:
A declaration is defined to be visible wherever it is directly
visible, as well as at other places where some name (such as a selected_
component) can denote the declaration.
This is merely an introductory explanation; the precise definition of
"visible" is 8.3(14). It is irrelevant that there is no name that would
be legal at the place of the use_type_clause, and that would denote
Types."+".
!ACATS test
A test case was added to ACATS test C840001 to check that "invisible" operators
are still use type visible.
!appendix
!section 8.4(08)
!subject use_type_clause where the first named subtype is not visible
!reference RM95-8.4 (8)
!reference RM95-8.3 (2)
!from Vincent Celier 95-12-26
!reference 95-5415.a Vincent Celier 95-12-26>>
!discussion
8.4 (8) says:
"For type T or T'Class determined by a subtype_mark of a use_type_clause
whose
scope encloses a place, the declaration of each primitive operator of type
T is potentially use-visible at this place if its declaration is visible
at this place."
I believe that "its declaration" means "the declaration of type T". However,
what does mean "the declaration of type T is visible" ?
8.3 (2) defines where a "declaration is visible":
"A declaration is defined to be visible wherever it is directly visible,
as well
as at other places where some name (such as a selected_component) can denote
the declaration."
What names can denote the declaration of a type ? Only the first subtype ?
Any subtype with the same constraint as the first subtype ? Or any subtype ?
Consider:
package Types is
type Entier is range 0 .. 100;
end Types;
with Types;
package Definitions is
subtype Entier is Types.Entier;
end Definitions;
with Definitions;
use type Definitions.Entier;
with Text_Io;
procedure Test_Definitions is
Mon_Entier : Definitions.Entier := 0;
begin
Mon_Entier := Mon_Entier + 5;
ThexT_io.Put_Line (Definitions.Entier'Image (Mon_Entier));
end Test_Definitions;
Is procedure Test_Definitions legal ? Is the "declaration of the type of
Entier" visible in the use type clause ?
I believe it should be.
What if subtype Entier is defined in package Definitions as:
subtype Entier is Types.Entier range 0 .. 10;
Is procedure Test_Definitions still legal ?
I also believe it should be.
****************************************************************
!section 8.4(08)
!subject use_type_clause where the first named subtype is not visible
!reference RM95-8.4 (8)
!reference RM95-8.3 (2)
!reference 95-5415.a Vincent Celier 95-12-26
!from Bob Duff
!reference 95-5416.a Robert A Duff 95-12-27>>
!discussion
> 8.4 (8) says:
>
> "For type T or T'Class determined by a subtype_mark of a use_type_clause
> whose
> scope encloses a place, the declaration of each primitive operator of type
> T is potentially use-visible at this place if its declaration is visible
> at this place."
>
> I believe that "its declaration" means "the declaration of type T".
No, the intent is that "its" refers to "each primitive operator". In
other words, for each primitive operator of T, if the declaration of
that primitive operator is visible, then the use_type_clause makes it
potentially use-visible as well. The point of this is that if there are
private operations of type T, they might not be visible *at all* at the
place of the use_type_clause, so they certainly shouldn't become
use-visible, and therefore directly visible. Directly visible is
supposed to be a subset of visible.
I admit that the wording could have been clearer.
>...However,
> what does mean "the declaration of type T is visible" ?
>
> 8.3 (2) defines where a "declaration is visible":
>
> "A declaration is defined to be visible wherever it is directly visible,
> as well
> as at other places where some name (such as a selected_component) can denote
> the declaration."
>
> What names can denote the declaration of a type ? Only the first subtype ?
> Any subtype with the same constraint as the first subtype ? Or any subtype ?
I don't know, but luckily, I don't need to answer that question, if you
believe what I said above. ;-)
> Consider:
>
> package Types is
> type Entier is range 0 .. 100;
> end Types;
>
> with Types;
> package Definitions is
> subtype Entier is Types.Entier;
> end Definitions;
>
> with Definitions;
> use type Definitions.Entier;
> with Text_Io;
> procedure Test_Definitions is
> Mon_Entier : Definitions.Entier := 0;
> begin
> Mon_Entier := Mon_Entier + 5;
> ThexT_io.Put_Line (Definitions.Entier'Image (Mon_Entier));
> end Test_Definitions;
>
> Is procedure Test_Definitions legal ? Is the "declaration of the type of
> Entier" visible in the use type clause ?
The "+" in Test_Definitions is legal. This is because Types."+" is
visible, and the use_type_clause then makes it potentially use-visible,
which means it is use-visible, by 8.4(9-11), which means it is directly
visible, by 8.3(4).
In your example, there are no private operations, so the part about the
declaration of the operation being visible is irrelevant.
> I believe it should be.
>
> What if subtype Entier is defined in package Definitions as:
>
> subtype Entier is Types.Entier range 0 .. 10;
>
> Is procedure Test_Definitions still legal ?
The constraint makes no difference. It's still legal.
> I also believe it should be.
- Bob
****************************************************************
!section 8.4(08)
!subject use_type_clause where the first named subtype is not visible
!reference RM95-8.4 (8)
!reference RM95-8.3 (2)
!reference 95-5415.a Vincent Celier 95-12-26
!reference 95-5416.a Robert A Duff 95-12-27
!from Vincent Celier
!reference 95-5417.a Vincent Celier 95-12-28>>
!discussion
I was asking if the following code was legal:
package Types is
type Entier is range 0 .. 100;
end Types;
with Types;
package Definitions is
subtype Entier is Types.Entier;
end Definitions;
with Definitions;
use type Definitions.Entier;
with Text_Io;
procedure Test_Definitions is
Mon_Entier : Definitions.Entier := 0;
begin
Mon_Entier := Mon_Entier + 5;
-- Is the "+" visible ? ^
Text_io.Put_Line (Definitions.Entier'Image (Mon_Entier));
end Test_Definitions;
Bob Duff answered:
> The "+" in Test_Definitions is legal. This is because Types."+" is
> visible, and the use_type_clause then makes it potentially use-visible,
> which means it is use-visible, by 8.4(9-11), which means it is directly
> visible, by 8.3(4).
Unfortunately, in procedure Test_Definitions, I don't see how Types."+" can
be visible. There is "with Types;" clause, and the only mention of package
Types in the visible part of package Definitions is as a prefix for first
subtype Entier.
So, I believe that the fact that "its declaration" in 8.4 (8) refers to "the
declaration of each primitive operator" and not to "the declaration of type
T" does not change the fact that the "+" for type Entier is not directly
visible in procedure Test_Definitions.
The operator "+" for type Entier is not visible in Test_Definitions because
there is no way to name it with an extended name. So I believe now that if
we follow Bob's interpretation, Test_Definitions is illegal.
Now what if the specification of package Definitions was:
with Types;
package Definitions is
package T renames Types;
subtype Entier is Types.Entier;
end Definitions;
would that make the procedure Test_Definitions legal?
Now in procedure Test_Definitions we can refer to operator "+" for type
Entier as Definitions.T."+". Does that make "+" visible ?
-- Vincent Celier
-- 9100 McCutcheon Place, RICHMOND, B.C., V7A 5A5, CANADA
-- e-mail: vcelier@direct.ca
****************************************************************
!section 8.4(08)
!subject use_type_clause where the first named subtype is not visible
!reference RM95-8.4 (8)
!reference RM95-8.3 (2)
!reference 95-5415.a Vincent Celier 95-12-26
!reference 95-5416.a Robert A Duff 95-12-27
!reference 95-5417.a Vincent Celier 95-12-28
!from Bob Duff
!reference 96-5460.a Robert A Duff 96-4-9>>
!discussion
Vincent Celier asked if this is legal:
> package Types is
> type Entier is range 0 .. 100;
> end Types;
>
> with Types;
> package Definitions is
> subtype Entier is Types.Entier;
> end Definitions;
>
> with Definitions;
> use type Definitions.Entier;
> with Text_Io;
> procedure Test_Definitions is
> Mon_Entier : Definitions.Entier := 0;
> begin
> Mon_Entier := Mon_Entier + 5;
> -- Is the "+" visible ? ^
> Text_io.Put_Line (Definitions.Entier'Image (Mon_Entier));
> end Test_Definitions;
I answered:
> > The "+" in Test_Definitions is legal. This is because Types."+" is
> > visible, and the use_type_clause then makes it potentially use-visible,
> > which means it is use-visible, by 8.4(9-11), which means it is directly
> > visible, by 8.3(4).
Back to Vincent:
> Unfortunately, in procedure Test_Definitions, I don't see how Types."+" can
> be visible.
I finally understand your question. 8.3(2) says:
A declaration is defined to be visible wherever it is directly
visible, as well as at other places where some name (such as a selected_
component) can denote the declaration.
And you don't see any name that could be legal at the place of the
use_type_clause, that would denote Types."+".
However, 8.3(2) is just a vague introduction to the concept of
visibility. The *real* definition of "visible" is in 8.3(14):
14 A declaration is visible within its scope, except where hidden from all
visibility, as follows:
...
By *this* definition, Types."+" is visible, so the use_type_clause makes
it directly visible. I have written up a draft AI (not yet published)
that explains this in more detail. It will be AI-122 when it comes out
(soon).
> Now what if the specification of package Definitions was:
>
> with Types;
> package Definitions is
> package T renames Types;
> subtype Entier is Types.Entier;
> end Definitions;
>
> would that make the procedure Test_Definitions legal?
It makes no difference -- Test_Definitions is legal either way.
> Now in procedure Test_Definitions we can refer to operator "+" for type
> Entier as Definitions.T."+". Does that make "+" visible ?
- Bob
****************************************************************
Questions? Ask the ACAA Technical Agent