!standard 13.13.2(50/2) 06-03-17 AI05-0007-1/01 !standard 13.13.2(51/2) !class binding interpretation 06-03-17 !status work item 06-03-17 !status received 05-10-13 !priority Medium !difficulty Easy !qualifier Clarification !subject Stream 'Read and private scalar types !summary (See recommendation.) !question Presume that We have a limited private type, and we want to define a visible 'Read attribute on it. If the full type is a scalar type, 13.13.2(51/2) requires us to define the attribute using the base subtype. But we can't use 'Base on the partial view, since it is not scalar. package P is type Lim is limited private; procedure Read(S : access Root_Stream_Type'Class; Obj : out Lim); for Lim'Read use Read; private type Lim is new Positive; end P; Is this requirement checked? (No.) If it is, how can we define a visible attribute of a private type? !recommendation Relax the requirement for the base subtype. !wording (TBD.) !discussion One could argue that the check is made at the location of the attribute definition clause. Since Lim is not scalar at that point, the 'Base attribute is not required. But this interpretation causes trouble for formal private types. Consider: generic type Lim is limited private; package G is type My_Lim is new Lim; procedure Read(S : access Root_Stream_Type'Class; Obj : out My_Lim); for My_Lim'Read use Read; end G; By the rules on legality rules in a generic instance (12.3(11)), the legality rules are rechecked in an instance based on the properties of the actual. Thus, if the instantiation is: package Int_G is new G (My_Lim => Integer); the instantiation is illegal, as the attribute definition clause is illegal by 13.13.2(51/2). This is an unnecessary limitation on the use of formal private types; it essentially prevents the creation of mix-in generics that define stream attributes for all types (as such a mix-in would not work for scalar types). [Humm. This seems to be a problem with Ada 95, too. Why am I not surprised? - ED] !ACATS test An ACATS C-Test should be created to test these cases. !appendix From: Tucker Taft Date: Thursday, October 13, 2005 5:25 AM Here is an interesting problem we encountered recently. We have a limited private type, and we want to define a visible 'Read attribute on it. But it turns out the full type is a scalar type. That requires us to define the attribute using the base subtype. How are these two things are incompatible. The 'Base attribute cannot be used on a private type, but the 'Base attribute must be used on a scalar 'Read attribute. Is the 'Base requirement waived for types with a partial view that is not scalar? Should it be? Example: type Lim is limited private; procedure Read(S : access Root_Stream_Type'Class; Obj : out Lim); for Lim'Read use Read; private type Lim is new Positive; -- Oops, Lim'Read is not defined on Lim'Base as is required -- by 13.13.2(51/2) (or the old paragraph 38) I suppose my instinct would be to fix 50/2 and 51/2 so that they require the base subtype unless there is a partial view that is non-scalar, in which case they require the first subtype. Not pretty, but at least well defined. **************************************************************** From: Pascal Leroy Date: Friday, October 14, 2005 5:53 AM I guess I don't see the problem. I have always assumed that 13.13.2(51/2) was checked using the properties that you see at the place of the attribute_definition_clause. At this place Lim is not scalar, so you must use the first subtype. I don't see how you would get an error later on the completion, which is what your example seems to indicate. **************************************************************** From: Tucker Taft Date: Friday, October 14, 2005 6:51 AM Ok with me, though perhaps an AARM note would be helpful. I wonder what happens if you have a non-limited private type T, where the implicit 'Read on the partial view presumably has parameter subtype T, while the 'Read on the full view, presuming it is scalar, has parameter subtype T'Base. The placement of the attribute definition clause, if any, seems even more critical in that case, since using your suggested rule, you must specify a Read procedure with T or T'Base depending on where the attribute definition clause is. I suppose I also wonder about specifying the 'Read on a type derived from a formal private type T. Do we require a recheck on instantiation that the actual type is *not* scalar? Is it impossible to specify 'Read for such a type? I would be tempted to change the rule to *allow* the use of the first subtype always for 'Read, while also allowing the use of the base subtype if the associated type is scalar. That way the user can choose whether to provide an operation that can handle values outside the first subtype. Since the rules no longer require the stream_size to accommodate the base range, requiring its use in the specification of the 'Read attribute seems unnecessary. ****************************************************************