aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/sem_ch4.adb
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2019-08-13 08:07:18 +0000
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>2019-08-13 08:07:18 +0000
commit258325dddf752c578f1da15f63577090b1db2de5 (patch)
treeca59335f2e7442884a652520b533a5e973a44d5c /gcc/ada/sem_ch4.adb
parent2e8362bc219d6e900756128450c365dd31045a7b (diff)
downloadgcc-258325dddf752c578f1da15f63577090b1db2de5.zip
gcc-258325dddf752c578f1da15f63577090b1db2de5.tar.gz
gcc-258325dddf752c578f1da15f63577090b1db2de5.tar.bz2
[Ada] Spurious error on nested instantiation
This fixes a spurious error given by the compiler for a call to a subprogram which is the formal subprogram parameter of a generic package, if the generic package is instantiated in the body of an enclosing generic package with two formal types and two formal subprogram parameter homonyms taking them, and this instantiation takes one the two formal types as actual, and the enclosing generic package is instantiated on the same actual type with a single actual subprogram parameter, and the aforementioned call is overloaded. In this case, the renaming generated for the actual subprogram parameter in the nested instantiation is ambiguous and must be disambiguated using the corresponding formal parameter of the enclosing instantiation, otherwise a (sub)type mismatch is created and later subprogram disambiguation is not really possible. 2019-08-13 Eric Botcazou <ebotcazou@adacore.com> gcc/ada/ * sem_ch4.adb (Analyze_One_Call): Remove bypass for type mismatch in nested instantiations. * sem_ch8.adb (Find_Nearer_Entity): New function. (Find_Renamed_Entity): Use it to disambiguate the candidates for the renaming generated for an instantiation when it is ambiguous. gcc/testsuite/ * gnat.dg/generic_inst9.adb, gnat.dg/generic_inst9.ads, gnat.dg/generic_inst9_pkg1-operator.ads, gnat.dg/generic_inst9_pkg1.ads, gnat.dg/generic_inst9_pkg2.adb, gnat.dg/generic_inst9_pkg2.ads: New testcase. From-SVN: r274343
Diffstat (limited to 'gcc/ada/sem_ch4.adb')
-rw-r--r--gcc/ada/sem_ch4.adb53
1 files changed, 0 insertions, 53 deletions
diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb
index f7b99d4..c049f9d 100644
--- a/gcc/ada/sem_ch4.adb
+++ b/gcc/ada/sem_ch4.adb
@@ -3619,59 +3619,6 @@ package body Sem_Ch4 is
Next_Actual (Actual);
Next_Formal (Formal);
- -- In a complex case where an enclosing generic and a nested
- -- generic package, both declared with partially parameterized
- -- formal subprograms with the same names, are instantiated
- -- with the same type, the types of the actual parameter and
- -- that of the formal may appear incompatible at first sight.
-
- -- generic
- -- type Outer_T is private;
- -- with function Func (Formal : Outer_T)
- -- return ... is <>;
-
- -- package Outer_Gen is
- -- generic
- -- type Inner_T is private;
- -- with function Func (Formal : Inner_T) -- (1)
- -- return ... is <>;
-
- -- package Inner_Gen is
- -- function Inner_Func (Formal : Inner_T) -- (2)
- -- return ... is (Func (Formal));
- -- end Inner_Gen;
- -- end Outer_Generic;
-
- -- package Outer_Inst is new Outer_Gen (Actual_T);
- -- package Inner_Inst is new Outer_Inst.Inner_Gen (Actual_T);
-
- -- In the example above, the type of parameter
- -- Inner_Func.Formal at (2) is incompatible with the type of
- -- Func.Formal at (1) in the context of instantiations
- -- Outer_Inst and Inner_Inst. In reality both types are generic
- -- actual subtypes renaming base type Actual_T as part of the
- -- generic prologues for the instantiations.
-
- -- Recognize this case and add a type conversion to allow this
- -- kind of generic actual subtype conformance. Note that this
- -- is done only when the call is non-overloaded because the
- -- resolution mechanism already has the means to disambiguate
- -- similar cases.
-
- elsif not Is_Overloaded (Name (N))
- and then Is_Type (Etype (Actual))
- and then Is_Type (Etype (Formal))
- and then Is_Generic_Actual_Type (Etype (Actual))
- and then Is_Generic_Actual_Type (Etype (Formal))
- and then Base_Type (Etype (Actual)) =
- Base_Type (Etype (Formal))
- then
- Rewrite (Actual,
- Convert_To (Etype (Formal), Relocate_Node (Actual)));
- Analyze_And_Resolve (Actual, Etype (Formal));
- Next_Actual (Actual);
- Next_Formal (Formal);
-
-- Handle failed type check
else