From 7ff117e24a97ce98ac13671ea140c45a67400b5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Fri, 21 May 2010 16:00:21 +0200 Subject: 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.) --- lib/hipe/cerl/erl_bif_types.erl | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib/hipe/cerl') diff --git a/lib/hipe/cerl/erl_bif_types.erl b/lib/hipe/cerl/erl_bif_types.erl index be3073c0e6..523c00b2be 100644 --- a/lib/hipe/cerl/erl_bif_types.erl +++ b/lib/hipe/cerl/erl_bif_types.erl @@ -1155,6 +1155,10 @@ type(erlang, monitor_node, 2, Xs) -> type(erlang, monitor_node, 3, Xs) -> strict(arg_types(erlang, monitor_node, 3), Xs, fun (_) -> t_atom('true') end); +type(erlang, nif_error, 1, _) -> + t_any(); +type(erlang, nif_error, 2, Xs) -> + strict(arg_types(erlang, nif_error, 2), Xs, fun (_) -> t_any() end); type(erlang, node, 0, _) -> t_node(); type(erlang, node, 1, Xs) -> strict(arg_types(erlang, node, 1), Xs, fun (_) -> t_node() end); @@ -3628,6 +3632,10 @@ arg_types(erlang, monitor_node, 2) -> [t_node(), t_boolean()]; arg_types(erlang, monitor_node, 3) -> [t_node(), t_boolean(), t_list(t_atom('allow_passive_connect'))]; +arg_types(erlang, nif_error, 1) -> + [t_any()]; +arg_types(erlang, nif_error, 2) -> + [t_any(), t_list()]; arg_types(erlang, node, 0) -> []; arg_types(erlang, node, 1) -> -- cgit v1.2.3