~clint-fewbar/ubuntu/precise/erlang/merge-15b

« back to all changes in this revision

Viewing changes to lib/dialyzer/test/opaque_SUITE_data/src/int/int_adt.erl

  • Committer: Package Import Robot
  • Author(s): Sergei Golovan
  • Date: 2011-12-15 19:20:10 UTC
  • mfrom: (1.1.18) (3.5.15 sid)
  • mto: (3.5.16 sid)
  • mto: This revision was merged to the branch mainline in revision 33.
  • Revision ID: package-import@ubuntu.com-20111215192010-jnxcfe3tbrpp0big
Tags: 1:15.b-dfsg-1
* New upstream release.
* Upload to experimental because this release breaks external drivers
  API along with ABI, so several applications are to be fixed.
* Removed SSL patch because the old SSL implementation is removed from
  the upstream distribution.
* Removed never used patch which added native code to erlang beam files.
* Removed the erlang-docbuilder binary package because the docbuilder
  application was dropped by upstream.
* Documented dropping ${erlang-docbuilder:Depends} substvar in
  erlang-depends(1) manpage.
* Made erlang-base and erlang-base-hipe provide virtual package
  erlang-abi-15.b (the number means the first erlang version, which
  provides current ABI).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
%%----------------------------------------------------------------------------
 
5
 
 
6
-module(int_adt).
 
7
 
 
8
-export([new_i/0, add_i/2, div_i/2, add_f/2, div_f/2]).
 
9
 
 
10
-export_type([int/0]).
 
11
 
 
12
-opaque int() :: integer().
 
13
 
 
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().
 
17
new_i() -> 42.
 
18
 
 
19
%% the success typing is more general than the contract: this is OK
 
20
-spec add_i(int(), int()) -> int().
 
21
add_i(X, Y) -> X + Y.
 
22
 
 
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.
 
26
 
 
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).
 
30
 
 
31
%% the success typing has an incompatible range: this is invalid
 
32
-spec div_f(int(), int()) -> int().
 
33
div_f(X, Y) -> X / Y.