Comments
Patch
===================================================================
@@ -834,6 +834,20 @@ package body Ch12 is
Set_Sloc (Def_Node, Token_Ptr);
T_Private;
+
+ if Token = Tok_Tagged then -- CODEFIX
+ Error_Msg_SC ("TAGGED must come before PRIVATE");
+ Scan; -- past TAGGED
+
+ elsif Token = Tok_Abstract then -- CODEFIX
+ Error_Msg_SC ("`ABSTRACT TAGGED` must come before PRIVATE");
+ Scan; -- past ABSTRACT
+
+ if Token = Tok_Tagged then
+ Scan; -- past TAGGED
+ end if;
+ end if;
+
return Def_Node;
end P_Formal_Private_Type_Definition;
===================================================================
@@ -309,11 +309,11 @@ package body Ch3 is
-- Error recovery: can raise Error_Resync
- -- Note: The processing for full type declaration, incomplete type
- -- declaration, private type declaration and type definition is
- -- included in this function. The processing for concurrent type
- -- declarations is NOT here, but rather in chapter 9 (i.e. this
- -- function handles only declarations starting with TYPE).
+ -- The processing for full type declarations, incomplete type declarations,
+ -- private type declarations and type definitions is included in this
+ -- function. The processing for concurrent type declarations is NOT here,
+ -- but rather in chapter 9 (this function handles only declarations
+ -- starting with TYPE).
function P_Type_Declaration return Node_Id is
Abstract_Present : Boolean := False;
@@ -770,6 +770,22 @@ package body Ch3 is
when Tok_Private =>
Decl_Node := New_Node (N_Private_Type_Declaration, Type_Loc);
Scan; -- past PRIVATE
+
+ -- Check error cases of private [abstract] tagged
+
+ if Token = Tok_Abstract then
+ Error_Msg_SC ("`ABSTRACT TAGGED` must come before PRIVATE");
+ Scan; -- past ABSTRACT
+
+ if Token = Tok_Tagged then
+ Scan; -- past TAGGED
+ end if;
+
+ elsif Token = Tok_Tagged then
+ Error_Msg_SC ("TAGGED must come before PRIVATE");
+ Scan; -- past TAGGED
+ end if;
+
exit;
-- Ada 2005 (AI-345): Protected, synchronized or task interface
This patch improves the error recovery for cases in which the keywords PRIVATE, ABSTRACT, TAGGED are not in the required order, as shown by this test (previously the diagnostic was missing semicolon with errors cascaded after this message). 1. package keyorder is 2. type FP is private tagged; | >>> "tagged" must come before "private" 3. type RP is private abstract tagged; | >>> "abstract tagged" must come before "private" 4. type RA is private abstract; | >>> "abstract tagged" must come before "private" 5. 6. generic 7. type OK is abstract tagged private; 8. type FT is private tagged; | >>> "tagged" must come before "private" 9. type FP is private abstract tagged; | >>> "abstract tagged" must come before "private" 10. type RA is private abstract; | >>> "abstract tagged" must come before "private" 11. package PP is end; 12. end; Tested on x86_64-pc-linux-gnu, committed on trunk 2010-10-12 Robert Dewar <dewar@adacore.com> * par-ch12.adb (P_Formal_Private_Type_Definition): Improve error messages and recovery for case of out of order Abstract/Tagged/Private keywords. * par-ch3.adb (P_Type_Declaration): Improve error messages and recovery for case of out of order Abstract/Tagged/Private keywords.