-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dialyzer: false positive #8222
Comments
Well… the error is pretty confusing (as usual), but the second clause for |
This is unfortunate. Here, we have excluded |
@jhogberg - is it somehow connected to records? changing the example to not use records make the error gone: -module(dial).
-export([test1/01]).
-spec test1(binary() | undefined) -> binary().
test1(In) when In =/= undefined ->
to_binary(In).
-spec to_binary(string() | binary()) -> binary().
to_binary(Data) when is_binary(Data) ->
Data;
to_binary(Data) ->
list_to_binary(Data).
|
The error disappears as specs describe arguments upon successful return, not as they enter the function (see point 4 in the EEP draft). This means that
|
Describe the bug
dialyzer considers
Data == undefined
, though it can never be undefined - since the only code path from (exported)test1/1
checks thatF1 =/= undefined
.Expected behavior
No report about
Data :: undefined
.Affected versions
Reproducible with OTP 26.0.2
Additional information
Changing the type of the record field from
f1 :: binary() | undefined
tof1 :: binary() | string() | undefined
make the error gone.The text was updated successfully, but these errors were encountered: