Skip to content

Rewrite atom interpolations - non keywords#15531

Open
sabiwara wants to merge 3 commits into
elixir-lang:mainfrom
sabiwara:migrate-atom-interpolation
Open

Rewrite atom interpolations - non keywords#15531
sabiwara wants to merge 3 commits into
elixir-lang:mainfrom
sabiwara:migrate-atom-interpolation

Conversation

@sabiwara

@sabiwara sabiwara commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Since we are soft-deprecating the :"foo#{x}" in favor of String.to_unsafe_atom/1, I figured I'd rewrite these in the codebase already.

I added a new migrate_atom_interpolations formatter option to perform this (first commit).
We don't have to keep it though if we don't want to, I wanted this for myself and figured it might help people address this deprecation more easily (which is the point of --migrate).

If we want to indeed support the option, will add proper tests and support for keywords as well, I wanted to get feedback first.

@josevalim josevalim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. My only concern is that the migrate_atom_interpolation will push everyone to Elixir v1.21 but given migration is opt-in, we are likely fine!

@sabiwara

Copy link
Copy Markdown
Contributor Author

My only concern is that the migrate_atom_interpolation will push everyone to Elixir v1.21 but given migration is opt-in, we are likely fine!

That's a good point, this wouldn't be useful as is for library authors yet (which is probably where atom interpolations was the most used).

The keyword migration also happens to be more tricky than expected. We cannot only change the key-value pair locally, we need to change preceding keys too otherwise we might get an invalid pair.
[bar: 1, "foo_#{2}": 2] => [{:bar, 1}, {"foo_#{2}", 2}], can't just be [bar: 1, {"foo_#{2}", 2}].
And it needs to work both for keywords and maps, which have a different way of wrapping keywords.

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