Skip to content

Commit 8b04c3b

Browse files
author
Sonny Martin
committed
Tests for 'use type' & 'use all type' clause
NB our package implementation does not support function calls atm, so although 'use type' can work fully if only built-in operators are used, any use of functions or overloaded operators or new 'basic operations' for a custom type will fail.
1 parent a44159c commit 8b04c3b

File tree

7 files changed

+56
-12
lines changed

7 files changed

+56
-12
lines changed

testsuite/gnat2goto/tests/package_use_type_N_Use_Type_Clause/Use_Type_Clause.adb

-8
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package body Count_Types is
2+
------------------------------------------------------------
3+
function "=" (X : Counter; Y: Integer) return Boolean is
4+
begin
5+
if X.Value = Y then
6+
return True;
7+
else
8+
return False;
9+
end if;
10+
end "=";
11+
------------------------------------------------------------
12+
function Double (X : in out Counter) return Counter is
13+
begin
14+
X.Value := X.Value + X.Value;
15+
-- return X.Value + X.Value;
16+
return X;
17+
end Double;
18+
------------------------------------------------------------
19+
end Count_Types;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package Count_Types is
2+
type Count is new Integer;
3+
------------------------------------------------------------
4+
type Counter is
5+
record
6+
Value : Integer := 1;
7+
end record;
8+
9+
function "=" (X : Counter; Y : Integer) return Boolean;
10+
11+
function Double (X : in out Counter) return Counter;
12+
------------------------------------------------------------
13+
end Count_Types;

testsuite/gnat2goto/tests/package_use_type_N_Use_Type_Clause/external_types.ads

-3
This file was deleted.

testsuite/gnat2goto/tests/package_use_type_N_Use_Type_Clause/test.opt

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
**** WARNING: no body for function count_types__double
2+
[1] file use_type_clause.adb line 16 assertion: SUCCESS
3+
VERIFICATION SUCCESSFUL
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
-- 'use type' clause makes visible only the operators associated with a type
2+
-- (NB but not the type itself, this must still be fully qualified
3+
with Count_Types; use type Count_Types.Count;
4+
5+
-- 'use all type' clause makes visible both the operators and primitive
6+
-- operations associated with a type (NB but not the type itself, this must
7+
-- still be fully qualified)
8+
with Count_Types; use all type Count_Types.Counter;
9+
10+
procedure Use_Type_Clause is
11+
A : Count_Types.Count := 1;
12+
13+
B : Count_Types.Counter;
14+
C : Count_Types.Counter;
15+
begin
16+
pragma Assert (A=1);
17+
18+
C := Double(B); -- Double is accessible due to 'use all type' clause
19+
-- next statement would fail as packages do not support function calls atm
20+
-- pragma Assert (C=2);
21+
end Use_Type_Clause;

0 commit comments

Comments
 (0)