diff options
author | Ed Schonberg <schonberg@adacore.com> | 2018-05-21 14:52:05 +0000 |
---|---|---|
committer | Pierre-Marie de Rodat <pmderodat@gcc.gnu.org> | 2018-05-21 14:52:05 +0000 |
commit | 516057d379930306bc240b7b2b4eedb2c9bb1aeb (patch) | |
tree | cc70f2f649a9342809957071fbb75959fdf5cf0c | |
parent | def6e435f48990bcf8aebe9432b9b1aea593e4e9 (diff) | |
download | gcc-516057d379930306bc240b7b2b4eedb2c9bb1aeb.zip gcc-516057d379930306bc240b7b2b4eedb2c9bb1aeb.tar.gz gcc-516057d379930306bc240b7b2b4eedb2c9bb1aeb.tar.bz2 |
[Ada] Error message on invalid conversion involving limited views
A type conversion may be illegal if the expression in the conversion has a
limited view of a type. This patch expands the error report to indicate the
presence of a limited view, and when the context is a package body it suggests
the addition of a regular with-clause to make the full view available.
Compiling client.adb must yield:
client.adb:6:16: invalid conversion, not compatible with limited view
of type "Map_Type" defined at maps.ads:2
client.adb:6:16: add with_clause for "Maps" to current unit
----
package Maps is
type Map_Type is null record;
end;
----
limited with Maps;
package Payloads is
function Get_Map return access Maps.Map_Type;
end;
----
with Maps;
package Maps2 is
type New_Map_Type is new Maps.Map_Type;
end;
----
with Maps2;
package Client is
procedure Foo (Map : Maps2.New_Map_Type) is null;
procedure Bar;
end;
----
with Payloads;
package body Client is
procedure Bar is
begin
Foo (Maps2.New_Map_Type (Payloads.Get_Map.all));
end;
end;
2018-05-21 Ed Schonberg <schonberg@adacore.com>
gcc/ada/
* sem_res.adb (Valid_Conversion): Improve error message on an illegal
type conversion whose expression has a limited view of a type.
From-SVN: r260466
-rw-r--r-- | gcc/ada/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/ada/sem_res.adb | 29 |
2 files changed, 32 insertions, 2 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index b29b3ab..5cbb973 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,8 @@ +2018-04-04 Ed Schonberg <schonberg@adacore.com> + + * sem_res.adb (Valid_Conversion): Improve error message on an illegal + type conversion whose expression has a limited view of a type. + 2018-05-21 Ed Schonberg <schonberg@adacore.com> * exp_ch5.adb (Build_Formal_Container_Iteration): If source has diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb index a4d6a26..d31aca2 100644 --- a/gcc/ada/sem_res.adb +++ b/gcc/ada/sem_res.adb @@ -13011,8 +13011,33 @@ package body Sem_Res is -- Here we have a real conversion error else - Conversion_Error_NE - ("invalid conversion, not compatible with }", N, Opnd_Type); + + -- Check for missing regular with_clause when only a limited view + -- of target is available. + + if From_Limited_With (Opnd_Type) + and then In_Package_Body + then + Conversion_Error_NE + ("invalid conversion, not compatible with limited view of }", + N, Opnd_Type); + Conversion_Error_NE ("\add with_clause for& to current unit!", N, + Scope (Opnd_Type)); + + elsif Is_Access_Type (Opnd_Type) + and then From_Limited_With (Designated_Type (Opnd_Type)) + and then In_Package_Body + then + Conversion_Error_NE + ("invalid conversion, not compatible with }", N, Opnd_Type); + Conversion_Error_NE ("\add with_clause for& to current unit!", N, + Scope (Designated_Type (Opnd_Type))); + + else + Conversion_Error_NE + ("invalid conversion, not compatible with }", N, Opnd_Type); + end if; + return False; end if; end Valid_Conversion; |