Skip to content

fix: resolve redundant clause warnings in Elixir 1.20#30

Merged
polvalente merged 1 commit into
elixir-nx:mainfrom
gilbertwong96:fix/redundant-clauses-elixir-1.20
Jul 20, 2026
Merged

fix: resolve redundant clause warnings in Elixir 1.20#30
polvalente merged 1 commit into
elixir-nx:mainfrom
gilbertwong96:fix/redundant-clauses-elixir-1.20

Conversation

@gilbertwong96

Copy link
Copy Markdown
Contributor

Elixir 1.20's gradual set-based type analysis flags three redundant clauses. Two were dead code already matched by earlier clauses; one was a clause-ordering bug that surfaced via the warning.

divide/2 — Removed def divide(n, b) when is_number(n) and b in [:infinity, :neg_infinity]. The earlier divide(a, :infinity) and divide(a, :neg_infinity) clauses already match and return 0.

pow/2 — Moved def pow(%Complex{re: re, im: im}, :neg_infinity) when re == 0 and im == 0 before the pow(%Complex{}, z) when is_non_finite_number(z) catch-all. Previously the catch-all matched first, so this clause was unreachable dead code. It now produces new(:infinity, 0) (0^-∞ = ∞), symmetric with the :infinity zero-base case (0^∞ = 0).

atan2/2 — Removed def atan2(:nan, :nan). The earlier atan2(:nan, a) when is_number(a) or is_non_finite_number(a) already matches (:nan, :nan) and returns :nan.

The corresponding test assertion for pow(Complex.new(0, 0), :neg_infinity) is updated from new(:nan, :nan) to new(:infinity, 0) to reflect the now-correct runtime behavior (the old assertion encoded the buggy catch-all result).

mix compile --warnings-as-errors is clean; mix test passes 70/70 with no new failures.

Remove dead-code clauses in divide/2 and atan2/2 already matched by
earlier clauses returning the same value, and fix a clause-ordering
bug in pow/2 where the :neg_infinity zero-base case was unreachable
because the non-finite catch-all matched first. Move it before the
catch-all, symmetric with the :infinity case.
@polvalente
polvalente merged commit c270974 into elixir-nx:main Jul 20, 2026
2 checks passed
@gilbertwong96
gilbertwong96 deleted the fix/redundant-clauses-elixir-1.20 branch July 20, 2026 04:52
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