!standard 7.5(5/2) 08-04-18 AI05-0087-1/03 !standard 12.5.1(5.1/2) !class binding interpretation 08-01-30 !status Amendment 201Z 08-11-26 !status WG9 Approved 08-06-20 !status ARG Approved 8-0-1 08-02-10 !status work item 08-01-30 !status received 08-01-23 !priority Low !difficulty Medium !qualifier Omission !subject Formal nonlimited derived types should not have limited actual types !summary Formal nonlimited derived types should not have limited actual types. A class-wide type is limited if its specific type is limited. !question It appears that we can use formal derived types derived from a limited interface to copy tasks and other limited objects. Consider: declare type Ifc is limited interface; generic type T is abstract new Ifc with private; -- T is nonlimited: 7.5(6.1/2) procedure Classwide_Store (Target : out T'Class; Source : T'Class); procedure Classwide_Store (Target : out T'Class; Source : T'Class) is begin Target := Source; end Classwide_Store; procedure Store is new Classwide_Store (Ifc); -- legal? (No.) task type Tsk; task body Tsk is begin null; end Tsk; type Has_Task is limited new Ifc with record F : Tsk; end record; X, Y : Has_Task; begin Store (X, Y); end; Is the instantiation legal? (No.) 7.5(3-7) seems to imply that most class-wide types are nonlimited, even if the specific type is limited. That is a change from Ada 95; was this intended? (No.) !recommendation (See Summary.) !wording Replace the deleted paragraph 7.5(5/2) with: * a class-wide type whose specific type is limited; Change 12.5.1(5.1/2) as follows: The actual type for a formal derived type shall be a descendant of the ancestor type and every progenitor of the formal type. {If the formal type is nonlimited, the actual type shall be nonlimited.} If the reserved word synchronized appears in the declaration of the formal derived type, the actual type shall be a synchronized tagged type. AARM Discussion: A type derived from a limited interface could be nonlimited; we do not want a limited type derived from such an interface to match a nonlimited formal derived type. (Otherwise, we could assign limited objects.) !discussion There was no intent that the class-wide type associated with a limited specific type be nonlimited; that would open up ways to assign tasks and the like. So we add explicit wording clarifying that class-wide types are limited if their specific type is. We certainly don't want the example in the question to be legal, so we must add wording to prevent that. !corrigendum 7.5(4/2) @dinsa @xbullet, @b, @b, or @b in its definition;> @dinst @xbullet !corrigendum 12.5.1(5.1/2) @drepl The actual type for a formal derived type shall be a descendant of the ancestor type and every progenitor of the formal type. If the reserved word @b appears in the declaration of the formal derived type, the actual type shall be a synchronized tagged type. @dby The actual type for a formal derived type shall be a descendant of the ancestor type and every progenitor of the formal type. If the formal type is nonlimited, the actual type shall be nonlimited. If the reserved word @b appears in the declaration of the formal derived type, the actual type shall be a synchronized tagged type. !ACATS Test A B-Test like the example in the question should be tried. !appendix From: Stephen W. Baird Sent: Wednesday, January 23, 2008 5:43 PM We don't want to allow a limited type to be specified as the actual parameter corresponding to a nonlimited formal type in an instantiation. There may be a hole in this area in the case of a formal type which is derived from a limited interface type. I didn't find RM wording to justify rejecting the following example: declare type Ifc is limited interface; generic type T is abstract new Ifc with private; -- T is nonlimited: 7.5(6.1/2) procedure Classwide_Store (Target : out T'Class; Source : T'Class); procedure Classwide_Store (Target : out T'Class; Source : T'Class) is begin Target := Source; end Classwide_Store; procedure Store is new Classwide_Store (Ifc); -- legal? task type Tsk; task body Tsk is begin null; end Tsk; type Has_Task is new Ifc with record F : Tsk; end record; X, Y : Has_Task; begin Store (X, Y); end; I also didn't find the general rule (whose existence I had always assumed) that a class-wide type is limited iff the corresponding specific type is limited. An unfriendly reading of 7.5 could suggest that if a specific limited type has no limited components, then the corresponding class-wide type is not limited. Is this just an oversight, or am I missing something? **************************************************************** From: Tucker Taft Sent: Wednesday, January 23, 2008 7:32 PM Good point. RM 12.5.1(5.1/2) should probably be revised roughly as follows: The actual type for a formal derived type shall be a descendant of the ancestor type and every progenitor of the formal type. {If the formal type is nonlimited, the actual type shall be nonlimited.} If the reserved word synchronized appears in the declaration of the formal derived type, the actual type shall be a synchronized tagged type. > ... > I also didn't find the general rule (whose existence I had always assumed) > that a class-wide type is limited iff the corresponding specific type is limited. > An unfriendly reading of 7.5 could suggest that if a specific limited type has no > limited components, then the corresponding class-wide type is not limited. > Is this just an oversight, or am I missing something? Another good point. 7.5(3) used to say "a descendant of ..." but that was deleted for Ada 2005. It turns out that classwide types are descendants of their root type, and that is how they were covered. Having deleted that phrase, we need to add back an explicit mention of classwide types. Hence, a bullet at the end is needed, saying something like: * a class-wide type whose associated specific type is limited. (plus the usual replacement of the preceding bullet's "." with a ";") **************************************************************** !topic Class-wide types can be limited, right? !reference 7.5(3-7) !from Adam Beneschan 09-10-28 !discussion This might be a possible omission. 7.5(3-6) lists the things that can make a type limited; 7.5(7) says "Otherwise, the type is nonlimited". It's not clear to me that if T is a limited tagged type, then this section of the RM makes T'Class limited. None of the items in 7.5 make T'Class limited (unless T happens to have a limited component), unless you say that the type_definition that defines T is also the definition of T'Class---which isn't clear to me from the rest of the RM. But it seems like it's necessary to specify somehow that T'Class is limited if T is, otherwise an variable of type T'Class could appear on the left of an assignment. **************************************************************** From: Randy Brukardt Sent: Wednesday, October 28, 2009 6:46 PM I assume you are looking at an Ada 2005 standard. If you look at the current working draft of the Standard, you will see that 7.5(5/3) says: "a class-wide type whose specific type is limited;". And the AARM references AI05-0087-1. That is, we've known that omission for a while and it is already fixed. P.S. At least you weren't the one that reported this omission previously. :-) That was Steve Baird this time. **************************************************************** From: Adam Beneschan Sent: Wednesday, October 28, 2009 6:53 PM OK, I see. Unfortunately, the title of that AI is "Formal nonlimited derived types should not have limited actual types", so when I was looking to see if this problem had already been brought up, it didn't occur to me to look in that one. I know, AI's often cover multiple things, so I shouldn't rely on the titles---guess it's time for me to reprogram the search algorithm in my brain... Anyway, thanks for the pointer. **************************************************************** From: Randy Brukardt Sent: Wednesday, October 28, 2009 7:04 PM Well, now that the draft updated Standard is available to the public (which it has been since last fall), it makes sense to review it for relevant changes. That's how I found the new text; I didn't look in the AIs at all (until I wrote that P.S. at the end). Admittedly, it helped that I knew that we'd fixed that problem, but we've fixed a *lot* of problems and no one can remember them all. I personally use the updated Standard almost exclusively, I only look back at the earlier ones if I have a specific question about a particular language version. (Especially as I use the AARM with the changes marked, so I can usually figure out the old text if I need it.) But I'd only recommend that for committed language lawyers (which you surely qualify as), not the general public. So I suggest starting with the draft updated Standard first, then perhaps check AIs. **************************************************************** From: Adam Beneschan Sent: Wednesday, October 28, 2009 7:36 PM Thanks. For some reason I had missed that this was avaliable already. Dan gave me a pointer to the draft updated Standard, and I've looked at it a bit, and already I have a nitpick. In the AARM, the updated paragraph you mentioned, 7.5(5/3) which says that class-wide are limited if their specific type is limited, refers to AI95-0087 and not AI05-0087. But it really does help. Many thanks, **************************************************************** From: Randy Brukardt Sent: Wednesday, October 28, 2009 7:54 PM > Thanks. For some reason I had missed that this was available already. For the record, I posted a message here on December 5, 2008 that the draft was available. I recall that you'd asked me about it earlier last year; I didn't realize that you didn't know it was available, especially with all of the typos that other people had posted about it here. I would have mentioned it earlier...you were the main reason that I pushed to get permission to make it available publicly. For anyone else who is interested, it is available here: http:/www.adaic.org/standards/ada1z.html > Dan gave me a pointer to the draft updated Standard, and I've looked > at it a bit, and already I have a nitpick. In the AARM, the updated > paragraph you mentioned, 7.5(5/3) which says that class-wide are > limited if their specific type is limited, refers to AI95-0087 and not > AI05-0087. Oops. Fixed. I'm sure there will be many more. ****************************************************************