Skip to content

Reject non-integer arguments in Integer.extended_gcd/2 zero clauses#15584

Merged
josevalim merged 1 commit into
elixir-lang:mainfrom
pnezis:fix-extended-gcd-guards
Jul 10, 2026
Merged

Reject non-integer arguments in Integer.extended_gcd/2 zero clauses#15584
josevalim merged 1 commit into
elixir-lang:mainfrom
pnezis:fix-extended-gcd-guards

Conversation

@pnezis

@pnezis pnezis commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

The zero base-case clauses guarded only on comparison with 0, so under Erlang term ordering non-integer arguments (floats, atoms) matched when the other argument was 0, e.g. Integer.extended_gcd(2.5, 0) returned {2.5, 1, 0} instead of raising, violating the spec and diverging from Integer.gcd/2.

iex(1)> Integer.extended_gcd(:atom, 0)
{:atom, 1, 0}
iex(2)> Integer.extended_gcd(2.5, 0)
{2.5, 1, 0}
iex(3)> Integer.extended_gcd(-2.5, 0)
{-2.5, 1, 0}
iex(4)> Integer.extended_gcd(0, -1.2)
{-1.2, 0, 1}

I am evaluating claude fable on code review tasks and this was one of the findings - more to follow

Comment thread lib/elixir/test/elixir/integer_test.exs Outdated
The zero base-case clauses guarded only on comparison with 0, so under
Erlang term ordering non-integer arguments (floats, atoms) matched when
the other argument was 0, e.g. `Integer.extended_gcd(2.5, 0)` returned
`{2.5, 1, 0}` instead of raising, violating the spec and diverging from
`Integer.gcd/2`.
@pnezis pnezis force-pushed the fix-extended-gcd-guards branch from fdd4c56 to e79f7fb Compare July 10, 2026 16:45
@josevalim josevalim merged commit 717952a into elixir-lang:main Jul 10, 2026
15 checks passed
@josevalim

Copy link
Copy Markdown
Member

💚 💙 💜 💛 ❤️

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants