public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-393] [Ada] Improve expected type error messages
@ 2022-05-13 8:08 Pierre-Marie de Rodat
0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2022-05-13 8:08 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:6a28d40dc4dd47431cc52edbb8b1994f81aa1748
commit r13-393-g6a28d40dc4dd47431cc52edbb8b1994f81aa1748
Author: Justin Squirek <squirek@adacore.com>
Date: Mon Jan 31 21:51:38 2022 +0000
[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.
Diff:
---
gcc/ada/sem_util.adb | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index e2a49632413..b7ebd4abbaa 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)
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-05-13 8:08 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-13 8:08 [gcc r13-393] [Ada] Improve expected type error messages Pierre-Marie de Rodat
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).