public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Crash on inconsistent IF-expression
@ 2015-11-12 11:42 Arnaud Charlet
  0 siblings, 0 replies; only message in thread
From: Arnaud Charlet @ 2015-11-12 11:42 UTC (permalink / raw)
  To: gcc-patches; +Cc: Thomas Quinot

[-- Attachment #1: Type: text/plain, Size: 926 bytes --]

This change makes sure the compiler produces a proper error (rather
than crash) when compiling an (illegal) IF-expression where THEN-expression
is overloaded, and none of its interpretation is compatible with
the ELSE-expression.

The following compilation must display:

$ gcc -c badelse.adb
badelse.adb:4:50: type incompatible with that of "then" expression

package Badelse is
   type K is (Unknown, Blue, Red);
   type Tristate is (False, True, Unknown);
   Boo : Boolean;
   procedure P (X : K);
end Badelse;
package body Badelse is
   procedure P (X : K) is
   begin
      Boo := (if X = Unknown then Unknown else X = Blue);
   end P;
end Badelse;

Tested on x86_64-pc-linux-gnu, committed on trunk

2015-11-12  Thomas Quinot  <quinot@adacore.com>

	* sem_ch4.adb (analyze_If_Expression): Reject IF-expression where
	THEN-expression is overloaded and none of its interpretation is
	compatible with the ELSE-expression.


[-- Attachment #2: difs --]
[-- Type: text/plain, Size: 712 bytes --]

Index: sem_ch4.adb
===================================================================
--- sem_ch4.adb	(revision 230239)
+++ sem_ch4.adb	(working copy)
@@ -2191,6 +2191,17 @@
 
                Get_Next_Interp (I, It);
             end loop;
+
+            --  If no valid interpretation has been found, then the type of
+            --  the ELSE expression does not match any interpretation of
+            --  the THEN expression.
+
+            if Etype (N) = Any_Type then
+               Error_Msg_N
+                 ("type incompatible with that of `THEN` expression",
+                  Else_Expr);
+               return;
+            end if;
          end;
       end if;
    end Analyze_If_Expression;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-11-12 11:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-12 11:42 [Ada] Crash on inconsistent IF-expression 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).