Erlang: NIFs and dialyzer warning
Asked Answered
I

1

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?

Immolation answered 28/10, 2014 at 15:47 Comment(0)
P
13

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

Portauprince answered 28/10, 2014 at 15:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.