aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Squirek <squirek@adacore.com>2022-01-31 21:51:38 +0000
committerPierre-Marie de Rodat <derodat@adacore.com>2022-05-13 08:04:32 +0000
commit6a28d40dc4dd47431cc52edbb8b1994f81aa1748 (patch)
tree6dd2fe2ee289f89c6a57047d2052b5d1f00c48a6
parentcf54619a8e33d2494b9f216f27d0110b8e0a4e49 (diff)
downloadgcc-6a28d40dc4dd47431cc52edbb8b1994f81aa1748.zip
gcc-6a28d40dc4dd47431cc52edbb8b1994f81aa1748.tar.gz
gcc-6a28d40dc4dd47431cc52edbb8b1994f81aa1748.tar.bz2
[Ada] Improve expected type error messages
This patch improves error messages concerning type mismatches by printing the actual expected type in more cases instead of the expected type's first subtype. gcc/ada/ * sem_util.adb (Wrong_Type): Avoid using the first subtype of the expected type in error messages when the expected type is not internally generated.
-rw-r--r--gcc/ada/sem_util.adb16
1 files changed, 14 insertions, 2 deletions
diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index e2a4963..b7ebd4a 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -30374,6 +30374,9 @@ package body Sem_Util is
Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
+ Err_Msg_Exp_Typ : Entity_Id := Expected_Type;
+ -- Type entity used when printing errors concerning the expected type
+
Matching_Field : Entity_Id;
-- Entity to give a more precise suggestion on how to write a one-
-- element positional aggregate.
@@ -30531,6 +30534,15 @@ package body Sem_Util is
end if;
end if;
+ -- Avoid printing internally generated subtypes in error messages and
+ -- instead use the corresponding first subtype in such cases.
+
+ if not Comes_From_Source (Err_Msg_Exp_Typ)
+ or else not Comes_From_Source (Declaration_Node (Err_Msg_Exp_Typ))
+ then
+ Err_Msg_Exp_Typ := First_Subtype (Err_Msg_Exp_Typ);
+ end if;
+
-- An interesting special check. If the expression is parenthesized
-- and its type corresponds to the type of the sole component of the
-- expected record type, or to the component type of the expected one
@@ -30568,7 +30580,7 @@ package body Sem_Util is
Error_Msg_N
("result must be general access type!", Expr);
Error_Msg_NE -- CODEFIX
- ("\add ALL to }!", Expr, Expec_Type);
+ ("\add ALL to }!", Expr, Err_Msg_Exp_Typ);
-- Another special check, if the expected type is an integer type,
-- but the expression is of type System.Address, and the parent is
@@ -30660,7 +30672,7 @@ package body Sem_Util is
Error_Msg_NE ("expected}!", Expr,
Corresponding_Remote_Type (Expec_Type));
else
- Error_Msg_NE ("expected}!", Expr, Expec_Type);
+ Error_Msg_NE ("expected}!", Expr, Err_Msg_Exp_Typ);
end if;
if Is_Entity_Name (Expr)