Skip to content

Replace :erlang.exit with :erlang.nif_error to suppress Dialyzer warnings#5

Open
japhib wants to merge 1 commit intoIanleeclark:masterfrom
japhib:nif-error
Open

Replace :erlang.exit with :erlang.nif_error to suppress Dialyzer warnings#5
japhib wants to merge 1 commit intoIanleeclark:masterfrom
japhib:nif-error

Conversation

@japhib
Copy link

@japhib japhib commented Jan 25, 2022

Currently when you run Dialyzer on a project that depends on libsalty2, you get a warning that every function calling a libsalty2 function will never return. This is because Dialyzer just sees the :erlang.exit in the placeholder implementation and thinks that's the real implementation. The way around this is to use :erlang.nif_error in its place: https://www.erlang.org/doc/man/erlang.html#nif_error-1

From the docs:

Works exactly like error/1, 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 does not generate false warnings.

The only functional difference is that it'll raise an error instead of just immediately exiting. I'm assuming that's fine though?

@andrew-lewin
Copy link

@Ianleeclark Just bumping this since it's been a year and I'm also running into the same issue.

@hazen
Copy link

hazen commented Mar 13, 2024

Thank you so much for this @japhib! I spent much time trying to figure out why Dialyzer was failing for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants