Skip to content
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 ignores guard and reports an error with -Wmissing_return #8031

Open
sabiwara opened this issue Jan 21, 2024 · 1 comment
Open

Dialyzer ignores guard and reports an error with -Wmissing_return #8031

sabiwara opened this issue Jan 21, 2024 · 1 comment
Assignees
Labels
enhancement team:VM Assigned to OTP team VM

Comments

@sabiwara
Copy link

Describe the bug
When using a guard such as when X =:= nil or when X =:= nil orelse orelse X =:= false, dialyzer is not able to eliminate the nil type from the integer() | nil return type and incorrectly complains about a missingnil type when turning on the -Wmissing_return flag.

To Reproduce

-spec foo(string()) -> integer().
foo(Text) ->
  case one(Text) of
    X when X =:= nil orelse X =:= false -> two(Text);
    X -> X
  end.

one("1") -> 1;
one(_) -> nil.

two("2") -> 2;
two(_) -> 0.

fails with

$ dialyzer -Wmissing_return foo.erl
foo.erl:4:2: The success typing for foo:foo/1 implies that the function might also return
          'nil' but the specification return is
          integer()

Expected behavior
No error being raised.

Affected versions
26.2.1

Additional context
This bug is affecting truthiness checks in Elixir such as one(text) || two(text) (see elixir-lang/elixir#13269).

@sabiwara sabiwara added the bug Issue is reported as a bug label Jan 21, 2024
@IngelaAndin IngelaAndin added the team:VM Assigned to OTP team VM label Jan 22, 2024
@jhogberg
Copy link
Contributor

Thanks for your report! We do not consider this a bug, when you ask dialyzer to go beyond its capabilities (e.g. by specifying -Wmissing_return or similar options), it may report things that cannot happen for reasons it's unable to infer.

You're essentially changing its mode from "only report things you know for certain" to "report things you think might be wrong," and warnings like these naturally arise from the latter.

That said, we may be able to fix this particular case. We'll look into it. :)

@jhogberg jhogberg added enhancement and removed bug Issue is reported as a bug labels Jan 22, 2024
@jhogberg jhogberg self-assigned this Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement team:VM Assigned to OTP team VM
Projects
None yet
Development

No branches or pull requests

3 participants