sem_ch4.adb: Fix typos in comments.
authorYannick Moy <moy@adacore.com>
Wed, 20 Apr 2016 10:44:17 +0000 (10:44 +0000)
committerArnaud Charlet <charlet@gcc.gnu.org>
Wed, 20 Apr 2016 10:44:17 +0000 (12:44 +0200)
2016-04-20  Yannick Moy  <moy@adacore.com>

* sem_ch4.adb: Fix typos in comments.
* sem_res.adb (Resolve_Case_Expression): Fix type of case alternatives.

From-SVN: r235263

gcc/ada/ChangeLog
gcc/ada/sem_ch4.adb
gcc/ada/sem_res.adb

index 185040a55cc32afcbc49ac3e6dc784ea6c26df18..1409c795e354722e2fdfb552aeda9392adaf41cc 100644 (file)
@@ -1,3 +1,8 @@
+2016-04-20  Yannick Moy  <moy@adacore.com>
+
+       * sem_ch4.adb: Fix typos in comments.
+       * sem_res.adb (Resolve_Case_Expression): Fix type of case alternatives.
+
 2016-04-20  Ed Schonberg  <schonberg@adacore.com>
 
        * sem_ch4.adb (Analyze_Selected_Component): A reference to the
index 6226c8c137acf9bb7283f6940ccaddb416f28e5a..6ba51e8f3d8c2b259ebeb3bbe416ecae5bb595d1 100644 (file)
@@ -2175,12 +2175,12 @@ package body Sem_Ch4 is
          begin
             Set_Etype (N, Any_Type);
 
-            --  Loop through intepretations of Then_Expr
+            --  Loop through interpretations of Then_Expr
 
             Get_First_Interp (Then_Expr, I, It);
             while Present (It.Nam) loop
 
-               --  Add possible intepretation of Then_Expr if no Else_Expr, or
+               --  Add possible interpretation of Then_Expr if no Else_Expr, or
                --  Else_Expr is present and has a compatible type.
 
                if No (Else_Expr)
index 23ce8279b3f2e166c524ba9b85dff7ab5278750b..2ce47e23f97266fe2e68ded96850246b2d59d412 100644 (file)
@@ -6509,13 +6509,27 @@ package body Sem_Res is
    -----------------------------
 
    procedure Resolve_Case_Expression (N : Node_Id; Typ : Entity_Id) is
-      Alt    : Node_Id;
-      Is_Dyn : Boolean;
+      Alt      : Node_Id;
+      Alt_Expr : Node_Id;
+      Alt_Typ  : Entity_Id;
+      Is_Dyn   : Boolean;
 
    begin
       Alt := First (Alternatives (N));
       while Present (Alt) loop
-         Resolve (Expression (Alt), Typ);
+         Alt_Expr := Expression (Alt);
+         Resolve (Alt_Expr, Typ);
+         Alt_Typ := Etype (Alt_Expr);
+
+         --  When the expression is of a scalar subtype different from the
+         --  result subtype, then insert a conversion to ensure the generation
+         --  of a constraint check.
+
+         if Is_Scalar_Type (Alt_Typ) and then Alt_Typ /= Typ then
+            Rewrite (Alt_Expr, Convert_To (Typ, Alt_Expr));
+            Analyze_And_Resolve (Alt_Expr, Typ);
+         end if;
+
          Next (Alt);
       end loop;
 
@@ -6523,13 +6537,14 @@ package body Sem_Res is
       --  dynamically tagged must be known statically.
 
       if Is_Tagged_Type (Typ) and then not Is_Class_Wide_Type (Typ) then
-         Alt := First (Alternatives (N));
+         Alt    := First (Alternatives (N));
          Is_Dyn := Is_Dynamically_Tagged (Expression (Alt));
 
          while Present (Alt) loop
             if Is_Dynamically_Tagged (Expression (Alt)) /= Is_Dyn then
-               Error_Msg_N ("all or none of the dependent expressions "
-                            & "can be dynamically tagged", N);
+               Error_Msg_N
+                 ("all or none of the dependent expressions can be "
+                  & "dynamically tagged", N);
             end if;
 
             Next (Alt);