jeremyjh / dialyxir

Mix tasks to simplify use of Dialyzer in Elixir projects.
Apache License 2.0
1.69k stars 141 forks source link

Seemingly incorrect error with "with" statement #452

Closed sax closed 2 years ago

sax commented 2 years ago

Precheck

√ Take a look at the open issues and be sure that your issue is not already covered. √ Be sure your versions of Dialyxir and Erlex are up to date.

Environment

Current behavior

I'm using a with statement that may return two different patterns. I use this same with statement twice. In one of the statements, dialyxer (or maybe dialyzer?) only sees the return values from one of the patterns.

Here is the code, pinned to a specific commit: https://github.com/geometerio/dyd/blob/fee50b18962f0f63dfbe411b242c8c5a87f47dd7/lib/dyd.ex#L101

lib/dyd.ex:101:pattern_match
The pattern can never match the type.

Pattern:
{:error, {:invalid_toml, _error}}

Type:
{:error, :invalid_time_unit | :not_a_datetime}

Here is the second usage, which does not generate a dialyzer warning: https://github.com/geometerio/dyd/blob/fee50b18962f0f63dfbe411b242c8c5a87f47dd7/lib/dyd.ex#L136

Here is the spec that should make the statement valid: https://github.com/geometerio/dyd/blob/fee50b18962f0f63dfbe411b242c8c5a87f47dd7/lib/dyd/manifest.ex#L41

So far every time I've fought with dialyzer, it's been my own fault—it's helped me to catch incorrect specs and incorrect code. Apologies if it's something I've gotten wrong in the code... I'm stumped on this one, though.

Expected behavior

jeremyjh commented 2 years ago

This project doesn't have anything to do with the warnings that are generated, that is all handled by Erlang's dialyzer library; so in the unlikely event its a dialyzer bug its a bug in the OTP tracker (you'd need to reproduce in Erlang). I'd ask on the Elixir forums, like you said its usually code. I've struggled with some of these as well and its always my code.

sax commented 2 years ago

Thanks! I'll head to the Elixir forums.