Repository navigation
Keep trailing comments after nodes without closing metadata - #1
Closed
rubas-agent[bot] wants to merge 1 commit into
Closed
rubas-agent[bot] wants to merge 1 commit into
rubas-agent[bot] wants to merge 1 commit into
Conversation
Author
|
Upstream merged the fix in elixir-lang#15961. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since
elixir-lang/elixir#15893,Code.quoted_to_algebra/2moves a comment into the node before it when that node has no:closingor:endmetadata. ASTs built by hand or withquoteoften have no such metadata. On main, this breaks the Igniter tests of Phoenix LiveView (test/phoenix_live_view/igniter/upgrade_to_1_1_test.exs).Here a list holds a call without metadata, and a comment follows the call:
v1.20 and this branch:
main:
SteffenDE reported the same bug with a 3-tuple in a comment on
elixir-lang/elixir#15893. Operators, 2-tuples, maps, lists and keyword lists without metadata break the same way.The cause is
comments_boundaries/3incode.ex. A node without:closingor:endgives its children the boundary of its parent, or its own:end_of_expressionline. The last child then takes every comment up to that line as its trailing comments.With this change, such a node gives its children no boundary, so a comment stays with the nearest node that has
:closingor:end.:->passes the boundary on to its body, as:.already does. InCode.Formatter.map_to_algebra/4, the|of a map update now prints its trailing comments, because comments can attach to it now.Tests:
quoted_ast_test.exshas the 3-tuple, call and operator cases without metadata.comments_test.exshas parsed cases with a comment after an operator, an attribute, a list tail, a map update, and a single expression in parens. All of them fail on main.