* [Ada] Further illegalities with operator call in functional notation
@ 2010-06-22 9:08 Arnaud Charlet
0 siblings, 0 replies; only message in thread
From: Arnaud Charlet @ 2010-06-22 9:08 UTC (permalink / raw)
To: gcc-patches; +Cc: Ed Schonberg
[-- Attachment #1: Type: text/plain, Size: 750 bytes --]
With this patch the compiler properly rejects a call of the form P."+" (X, Y)
when X and Y are numeric literals, and the result type is not declared in P.
Compiling the following must be rejected with:
derived_folded_mistyped.adb:8:27: expect type "T3"
---
procedure Derived_Folded_Mistyped is
package Scop is
type T2 is range 1 .. 4;
end Scop;
type T3 is new Scop.T2;
X : constant T3 := Scop."+" (1, 2); -- ERROR: Scop."+" returns T2
begin
null;
end Derived_Folded_Mistyped;
Tested on x86_64-pc-linux-gnu, committed on trunk
2010-06-22 Ed Schonberg <schonberg@adacore.com>
* sem_res.adb (Make_Call_Into_Operator): Diagnose an incorrect scope
for an operator in a functional notation, when operands are universal.
[-- Attachment #2: difs --]
[-- Type: text/plain, Size: 1345 bytes --]
Index: sem_res.adb
===================================================================
--- sem_res.adb (revision 161144)
+++ sem_res.adb (working copy)
@@ -1422,6 +1422,31 @@ package body Sem_Res is
("& not declared in&", N, Selector_Name (Name (N)));
Set_Etype (N, Any_Type);
return;
+
+ -- Detect a mismatch between the context type and the result type
+ -- in the named package, which is otherwise not detected if the
+ -- operands are universal. Check is only needed if source entity is
+ -- an operator, not a function that renames an operator.
+
+ elsif Nkind (Parent (N)) /= N_Type_Conversion
+ and then Ekind (Entity (Name (N))) = E_Operator
+ and then Is_Numeric_Type (Typ)
+ and then not Is_Universal_Numeric_Type (Typ)
+ and then Scope (Base_Type (Typ)) /= Pack
+ and then not In_Instance
+ then
+ if Is_Fixed_Point_Type (Typ)
+ and then (Op_Name = Name_Op_Multiply
+ or else
+ Op_Name = Name_Op_Divide)
+ then
+ -- Already checked above
+
+ null;
+
+ else
+ Error_Msg_NE ("expect type&", N, Typ);
+ end if;
end if;
end if;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2010-06-22 8:44 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-22 9:08 [Ada] Further illegalities with operator call in functional notation Arnaud Charlet
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).