6

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?

Hynek -Pichi- Vychodil
  • 26,174
  • 5
  • 52
  • 73
GabiMe
  • 18,105
  • 28
  • 76
  • 113

1 Answers1

13

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

mpm
  • 3,534
  • 23
  • 33