1
%%----------------------------------------------------------------------------
2
%% Module that tests consistency of spec declarations in the presence of
3
%% opaque types. Contains both valid and invalid contracts with opaque types.
4
%%----------------------------------------------------------------------------
8
-export([new_i/0, add_i/2, div_i/2, add_f/2, div_f/2]).
10
-export_type([int/0]).
12
-opaque int() :: integer().
14
%% the user has declared the return to be an opaque type, but the success
15
%% typing inference is too strong and finds a subtype as a return: this is OK
16
-spec new_i() -> int().
19
%% the success typing is more general than the contract: this is OK
20
-spec add_i(int(), int()) -> int().
23
%% the success typing coincides with the contract: this is OK, of course
24
-spec div_i(int(), int()) -> int().
25
div_i(X, Y) -> X div Y.
27
%% the success typing has an incompatible domain element: this is invalid
28
-spec add_f(int(), int()) -> int().
29
add_f(X, Y) when is_float(Y) -> X + trunc(Y).
31
%% the success typing has an incompatible range: this is invalid
32
-spec div_f(int(), int()) -> int().