Skip to content

Conversation

sabiwara
Copy link
Contributor

This is the first issue described in #13895.

end

defp interpolation_to_algebra(quoted, %{skip_eol: skip_eol} = state) do
defp interpolated_to_algebra(quoted, %{skip_eol: skip_eol} = state) do
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I renamed this because I found it confusing, but if anybody has another suggestion I'm happy to take it.

@josevalim
Copy link
Member

I think the bug is actually in the normalizer. :( We only convert the sigil to proper syntax if it has a delimiter:

opening_delimiter when not is_nil(opening_delimiter) <- meta[:delimiter] do

I think the issue is that the normalizer is adding a delimiter, when it is not a proper AST. WDYT?

@sabiwara
Copy link
Contributor Author

sabiwara commented Oct 15, 2024

OK, so the idea is to treat sigil_r(<<"abc", 123>>, []) just as if it was not a sigil, same as foo(<<"abc", 123>>, [])?

Currently there are two differences:

  • adding a delimiter
  • wrapping literal args
iex> Code.Normalizer.normalize(quote do: foo(<<"abc", 123>>, []))
{:foo, [closing: [line: nil]],
 [
   {:<<>>, [], [{:__block__, [], ["abc"]}, {:__block__, [token: "123"], ~c"{"}]},
   {:__block__, [], [[]]}  # <=== [] is wrapped
 ]}
iex> Code.Normalizer.normalize(quote do: sigil_r(<<"abc", 123>>, []))
{:sigil_r, [delimiter: "\"", context: Elixir, imports: [{2, Kernel}]],
 [
   {:<<>>, [], [{:__block__, [], ["abc"]}, {:__block__, [token: "123"], ~c"{"}]},
   []                      # <=== [] is NOT wrapped
 ]}

@josevalim
Copy link
Member

Exactly. We should not add a delimiter and do other sigil things if it is not a sigil.

@sabiwara sabiwara force-pushed the algebra-interpolation branch from 3ce07dc to adfe040 Compare October 16, 2024 10:49
@sabiwara
Copy link
Contributor Author

sabiwara commented Oct 16, 2024

@josevalim makes sense to me, re-pushed with the new approach adfe040.

I wonder though if it could be considered a regression, this felt intentional based on this commit 2d1c64c. Maybe when creating sigils through meta-programming, if that's a thing?

Oh, and we also need to re-evaluate the use of prune_metadata in assert, as the CI points out? Or keep delimiters here?

@josevalim
Copy link
Member

@sabiwara we should definitely support sigils through meta-programming. I think we should not check for delimiters in Code.Normalizer. Instead, we should normalize that both arguments of the sigil macro are "valid" (from the point of view of the formatter) and only add the delimiter if we can normalize them.

@sabiwara
Copy link
Contributor Author

OK I see what you mean now, sorry for the misunderstanding 🙇

BTW, unrelated but this feels like a good change, there is no need to lose the original delimiter in ExUnit no? I won't need it anymore for this PR though.

@josevalim
Copy link
Member

Agreed it is a good change!

@sabiwara sabiwara force-pushed the algebra-interpolation branch 2 times, most recently from 94c5620 to e02ef3e Compare October 16, 2024 23:34
@sabiwara sabiwara force-pushed the algebra-interpolation branch from e02ef3e to 020025a Compare October 16, 2024 23:34
@sabiwara
Copy link
Contributor Author

@josevalim forced-pushed take 3: 020025a.

I also caught a couple of crashes when the modifiers are invalid, covered these cases too.

@sabiwara sabiwara merged commit 673fe4a into elixir-lang:main Oct 17, 2024
9 checks passed
@sabiwara sabiwara deleted the algebra-interpolation branch October 17, 2024 06:38
sabiwara added a commit to sabiwara/elixir that referenced this pull request Oct 17, 2024
@sabiwara
Copy link
Contributor Author

Backported

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