Skip to content

Commit

Permalink
Fix indentation of parenthesized Expressions#to_s (#14511)
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil committed May 14, 2024
1 parent 8661e70 commit 90d1e4a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions spec/compiler/parser/to_s_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ describe "ASTNode#to_s" do
expect_to_s %(if (1 + 2\n3)\n 4\nend)
expect_to_s "%x(whoami)", "`whoami`"
expect_to_s %(begin\n ()\nend)
expect_to_s %(begin\n (1)\nend)
expect_to_s %(begin\n (@x = x).is_a?(Foo)\nend)
expect_to_s %(begin\n (1)\n 2\nend)
expect_to_s %(if 1\n begin\n 2\n end\nelse\n begin\n 3\n end\nend)
expect_to_s %(foo do\n begin\n bar\n end\nend)
expect_to_s %q("\e\0\""), %q("\e\u0000\"")
Expand Down Expand Up @@ -256,8 +259,10 @@ describe "ASTNode#to_s" do
expect_to_s "offsetof(Foo, @bar)"
expect_to_s "def foo(**options, &block)\nend"
expect_to_s "macro foo\n 123\nend"
expect_to_s "if true\n( 1)\nend"
expect_to_s "begin\n( 1)\nrescue\nend"
expect_to_s "if true\n (1)\nend"
expect_to_s "if true\n (1)\n 2\nend"
expect_to_s "begin\n (1)\nrescue\nend"
expect_to_s "begin\n (1)\n 2\nrescue\nend"
expect_to_s %[他.说("你好")]
expect_to_s %[他.说 = "你好"]
expect_to_s %[あ.い, う.え.お = 1, 2]
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/crystal/syntax/to_s.cr
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ module Crystal
else
node.expressions.each_with_index do |exp, i|
unless exp.nop?
append_indent
append_indent unless node.keyword.paren? && i == 0
exp.accept self
newline unless node.keyword.paren? && i == node.expressions.size - 1
end
Expand Down Expand Up @@ -1572,7 +1572,7 @@ module Crystal

def accept_with_indent(node : Expressions)
with_indent do
append_indent if node.keyword.begin?
append_indent unless node.keyword.none?
node.accept self
end
newline unless node.keyword.none?
Expand Down

0 comments on commit 90d1e4a

Please sign in to comment.