Ada: Robustify error recovery of structural instantiation in generic formal part
GCC's Ada compiler improves error recovery for structural instantiations within generic formal parts, preventing cascading errors during compilation.
The GCC Ada compiler has enhanced its error recovery mechanism for structural instantiations within generic formal parts. This change in sem_ch3.adb and sem_ch12.adb prevents cascading compilation errors that previously occurred when unresolved types were encountered during the analysis of private extensions and formal derived types. By returning Any_Type when Find_Type fails, the compiler can now gracefully continue parsing, providing more localized and understandable error messages.
In Details
The Ada front end of GCC handles the parsing and semantic analysis of Ada code, including generics. This commit specifically targets error recovery in sem_ch3.adb and sem_ch12.adb, focusing on structural instantiation within generic formal parts. The original issue caused cascading errors upon failure to resolve types during Analyze_Private_Extension_Declaration and Analyze_Formal_Derived_Type. The fix involves modifying Find_Type_Of_Subtype_Indic to return Any_Type (a placeholder for an unresolved type) when Find_Type fails to resolve a type. This allows the semantic analyzer t…
For Context
When you write code in a language like Ada and use "generics" (which are like templates that can work with different types), the compiler needs to understand how these generic parts are set up. This commit improves how the GCC Ada compiler handles errors specifically in the "generic formal part," which is where you define the requirements for types or structures that the generic code will operate on. Previously, if the compiler couldn't figure out a type in this section, it would often get completely confused and flood you with many irrelevant error messages. The fix makes the compiler more resilient: if it hits an unresolved type, it now uses a placeholder to continue analyzing the rest of your code. This means you'll get clearer, more focused error messages, making it easier to pinpoint and fix the actual problem in your Ada programs.