public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Arnaud Charlet <charlet@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Thomas Quinot <quinot@adacore.com>
Subject: [Ada] Crash on inconsistent IF-expression
Date: Thu, 12 Nov 2015 11:42:00 -0000	[thread overview]
Message-ID: <20151112114205.GA72284@adacore.com> (raw)

[-- 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;

                 reply	other threads:[~2015-11-12 11:42 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151112114205.GA72284@adacore.com \
    --to=charlet@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=quinot@adacore.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).