Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep position meta on & capture special variables in expanded AST #13607

Merged
merged 2 commits into from
May 27, 2024

Conversation

lukaszsamson
Copy link
Contributor

& variables exist in the code so it makes sense to preserve the position in expansion

@@ -1133,6 +1133,12 @@ defmodule Kernel.ExpansionTest do
assert expand(quote(do: &unknown(&1, &2))) == {:&, [], [{:/, [], [{:unknown, [], nil}, 2]}]}
end

test "keeps position meta on & variables" do
assert expand(Code.string_to_quoted!("& &1")) ==
{:fn, [{:line, 1}],
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'm not sure meta on fn and -> makes sense

Var = {list_to_atom([$& | integer_to_list(Pos)]), [], nil},
{Var, orddict:store(Pos, Var, Dict)};
Var = {list_to_atom([$& | integer_to_list(Pos)]), Meta, nil},
{Var, orddict:store(Pos, setelement(2, Var, []), Dict)};
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 didn't add meta on the left arg of -> as that node is not present in the code

Copy link
Member

Choose a reason for hiding this comment

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

I would keep it on both sides, the more information, potentially the better?

@josevalim josevalim merged commit 642cc79 into elixir-lang:main May 27, 2024
9 checks passed
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

@lukaszsamson lukaszsamson deleted the ls-capture-arg-meta branch October 5, 2024 09:20
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