Skip to content

Evaluate the subject of to_existing_atom/2 once - #16043

Merged
josevalim merged 2 commits into
elixir-lang:mainfrom
bmalum:fix/to-existing-atom-single-eval
Nov 1, 2026
Merged

josevalim merged 2 commits into
elixir-lang:mainfrom
bmalum:fix/to-existing-atom-single-eval

Conversation

@bmalum

@bmalum bmalum commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

When the allowed list is a literal, String.to_existing_atom/2 and List.to_existing_atom/2 are compiled into a case expression whose fallback clause calls to_existing_atom/2 to raise. The translated first argument was spliced into both the case subject and the fallback call, so any argument that is not a variable was evaluated twice when no atom matched, and the error could report a value the case never saw.

Bind the subject to a fresh variable first, as the lists:member/2 rewrite already does, so it is evaluated exactly once.

Assisted-by: Kiro:claude-fable-5.1

bmalum and others added 2 commits October 31, 2026 22:10
When the allowed list is a literal, String.to_existing_atom/2 and
List.to_existing_atom/2 are compiled into a case expression whose
fallback clause calls __to_existing_atom__/2 to raise. The translated
first argument was spliced into both the case subject and the fallback
call, so any argument that is not a variable was evaluated twice when no
atom matched, and the error could report a value the case never saw.

Bind the subject to a fresh variable first, as the lists:member/2
rewrite already does, so it is evaluated exactly once.

Assisted-by: Kiro:claude-fable-5.1
Assisted-by: Claude Code:claude-opus-5-5
@josevalim
josevalim merged commit 4b9f0c1 into elixir-lang:main Nov 1, 2026
15 checks passed
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