Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Erlang: NIFs and dialyzer warning

When implementing NIFs, Dialyzer gives me

Function crc16/1 has no local return

probably because I do exit in the .erl module (like the official docs recommend):

-module(my_nifs).
-export([crc16/1]).

-on_load(init/0).

init() ->
    ok = erlang:load_nif("../nifs/my_nifs", 0).

-spec crc16(_Binary :: binary()) -> non_neg_integer().
crc16(_Binary) ->
    exit(nif_library_not_loaded).
...

And generally, it seems that using exit/1 always makes Dialyzer to complain with this message (-spec .. -> no_return() doesn't help).

How can this be fixed?

like image 405
GabiMe Avatar asked Oct 28 '14 15:10

GabiMe


Video Answer


1 Answers

You could use erlang:nif_error/1/2 which where created just for that.

like image 59
mpm Avatar answered Oct 09 '22 21:10

mpm