diff options
author | Björn Gustavsson <[email protected]> | 2010-05-21 16:00:21 +0200 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2010-05-31 14:58:27 +0200 |
commit | 7ff117e24a97ce98ac13671ea140c45a67400b5d (patch) | |
tree | 7f2d7ab72be28b2630eb46c6d35f7b0233c9bef6 /erts/doc | |
parent | 56f23b4aca7c8bfcceeb0095536926ddb1a8102c (diff) | |
download | otp-7ff117e24a97ce98ac13671ea140c45a67400b5d.tar.gz otp-7ff117e24a97ce98ac13671ea140c45a67400b5d.tar.bz2 otp-7ff117e24a97ce98ac13671ea140c45a67400b5d.zip |
Add erlang:nif_error/1,2
A stub function that is supposed to be replaced by a NIF usually
calls erlang:error/1 to cause an exception if the NIF library
is not loaded. For example:
foo() ->
erlang:error(nif_not_loaded).
The problem is that although erlang:error/1 will normally never be
called, Dialyzer will think that any call to the function will fail
and thus generate false warnings. Adding a spec for the function
will not help because Dialyzer will not believe the spec.
Add erlang:nif_error/1,2 that work exactly like erlang:error/1,2.
Define the return types for both BIFs to be t_any().
erlang:nif_error is used like this:
-spec foo() -> binary().
foo() ->
erlang:nif_error(nif_not_loaded).
(The -spec is optional but highly recommended, since Dialyzer
otherwise has no chance to figure out the types.)
Diffstat (limited to 'erts/doc')
-rw-r--r-- | erts/doc/src/erlang.xml | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/erts/doc/src/erlang.xml b/erts/doc/src/erlang.xml index e683f161f1..7ff52c5b50 100644 --- a/erts/doc/src/erlang.xml +++ b/erts/doc/src/erlang.xml @@ -2644,6 +2644,37 @@ os_prompt%</pre> </desc> </func> <func> + <name>erlang:nif_error(Reason)</name> + <fsummary>Stop execution with a given reason</fsummary> + <type> + <v>Reason = term()</v> + </type> + <desc> + <p>Works exactly like + <seealso marker="#error/1">erlang:error/1</seealso>, + but Dialyzer thinks that this BIF will return an arbitrary term. + When used in a stub function for a NIF to generate an + exception when the NIF library is not loaded, Dialyzer + will not generate false warnings.</p> + </desc> + </func> + <func> + <name>erlang:nif_error(Reason, Args)</name> + <fsummary>Stop execution with a given reason</fsummary> + <type> + <v>Reason = term()</v> + <v>Args = [term()]</v> + </type> + <desc> + <p>Works exactly like + <seealso marker="#error/2">erlang:error/2</seealso>, + but Dialyzer thinks that this BIF will return an arbitrary term. + When used in a stub function for a NIF to generate an + exception when the NIF library is not loaded, Dialyzer + will not generate false warnings.</p> + </desc> + </func> + <func> <name>node() -> Node</name> <fsummary>Name of the local node</fsummary> <type> |