From patchwork Thu Oct 22 12:12:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Marie de Rodat X-Patchwork-Id: 1386210 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=adacore.com Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CH5pL5ZXkz9sT6 for ; Thu, 22 Oct 2020 23:12:26 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EAB6C3984FD9; Thu, 22 Oct 2020 12:12:15 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from rock.gnat.com (rock.gnat.com [205.232.38.15]) by sourceware.org (Postfix) with ESMTP id 822033857828 for ; Thu, 22 Oct 2020 12:12:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 822033857828 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=derodat@adacore.com Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 5DF121177DD; Thu, 22 Oct 2020 08:12:12 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at gnat.com Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id WEDJ9Kga5R+X; Thu, 22 Oct 2020 08:12:12 -0400 (EDT) Received: from tron.gnat.com (tron.gnat.com [205.232.38.10]) by rock.gnat.com (Postfix) with ESMTP id 4AFA5117644; Thu, 22 Oct 2020 08:12:12 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4862) id 472B6D9; Thu, 22 Oct 2020 08:12:12 -0400 (EDT) Date: Thu, 22 Oct 2020 08:12:12 -0400 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Subject: [Ada] AI12-0307: uniform resolution rules for aggregates Message-ID: <20201022121212.GA3958@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_ASCII_DIVIDERS, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ed Schonberg Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" The resolution rules for container aggregates can lead to ambiguities when homonym subprograms have a formal of a composite type, and the actual in a call is an aggregate. This patch adds an indication that this aggregate should be qualified to remove the ambiguity. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_util.ads, sem_util.adb (Check_Ambiguous_Aggregate): When a subprogram call is found to be ambiguous, check whether ambiguity is caused by an aggregate actual. and indicate that it should carry a type qualification. * sem_ch4.adb (Traverse_Hoonyms, Try_Primitive_Operation): Call it. * sem_res.adb (Report_Ambiguous_Argument): Call it. diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb --- a/gcc/ada/sem_ch4.adb +++ b/gcc/ada/sem_ch4.adb @@ -9339,6 +9339,7 @@ package body Sem_Ch4 is Error_Msg_NE ("ambiguous call to&", N, Hom); Report_Ambiguity (Matching_Op); Report_Ambiguity (Hom); + Check_Ambiguous_Aggregate (New_Call_Node); Error := True; return; end if; @@ -9961,6 +9962,7 @@ package body Sem_Ch4 is Error_Msg_NE ("ambiguous call to&", N, Prim_Op); Report_Ambiguity (Matching_Op); Report_Ambiguity (Prim_Op); + Check_Ambiguous_Aggregate (Call_Node); return True; end if; end if; diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb --- a/gcc/ada/sem_res.adb +++ b/gcc/ada/sem_res.adb @@ -2097,7 +2097,8 @@ package body Sem_Res is then Error_Msg_NE ("ambiguous call to&", Arg, Name (Arg)); - -- Could use comments on what is going on here??? + -- Examine possible interpretations, and adapt the message + -- for inherited subprograms declared by a type derivation. Get_First_Interp (Name (Arg), I, It); while Present (It.Nam) loop @@ -2112,6 +2113,11 @@ package body Sem_Res is Get_Next_Interp (I, It); end loop; end if; + + -- Additional message and hint if the ambiguity involves an Ada2020 + -- container aggregate. + + Check_Ambiguous_Aggregate (N); end Report_Ambiguous_Argument; ----------------------- diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -2425,6 +2425,27 @@ package body Sem_Util is end if; end Cannot_Raise_Constraint_Error; + ------------------------------- + -- Check_Ambiguous_Aggregate -- + ------------------------------- + + procedure Check_Ambiguous_Aggregate (Call : Node_Id) is + Actual : Node_Id; + + begin + if Extensions_Allowed then + Actual := First_Actual (Call); + while Present (Actual) loop + if Nkind (Actual) = N_Aggregate then + Error_Msg_N + ("\add type qualification to aggregate actual", Actual); + exit; + end if; + Next_Actual (Actual); + end loop; + end if; + end Check_Ambiguous_Aggregate; + ----------------------------------------- -- Check_Dynamically_Tagged_Expression -- ----------------------------------------- diff --git a/gcc/ada/sem_util.ads b/gcc/ada/sem_util.ads --- a/gcc/ada/sem_util.ads +++ b/gcc/ada/sem_util.ads @@ -349,6 +349,13 @@ package Sem_Util is -- not necessarily mean that CE could be raised, but a response of True -- means that for sure CE cannot be raised. + procedure Check_Ambiguous_Aggregate (Call : Node_Id); + -- Additional information on an ambiguous call in Ada_2020 when a + -- subprogram call has an actual that is an aggregate, and the + -- presence of container aggregates (or types with the correwponding + -- aspect) provides an additional interpretation. Message indicates + -- that an aggregate actual should carry a type qualification. + procedure Check_Dynamically_Tagged_Expression (Expr : Node_Id; Typ : Entity_Id;