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

Format: remove old code to format &.[] #7699

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions spec/compiler/formatter/formatter_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1329,4 +1329,8 @@ describe Crystal::Formatter do

# #7608
assert_format "enum E\n A # hello\n B # hello; C # hello\nend"

# #7631
assert_format "x.try &.[] 123"
assert_format "x.try &.[]= 123, 456"
end
53 changes: 1 addition & 52 deletions src/compiler/crystal/tools/formatter.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2768,58 +2768,7 @@ module Crystal
when Call
call = body
clear_object call

if !call.obj && (call.name == "[]" || call.name == "[]?")
case @token.type
when :"["
write_token :"["
skip_space_or_newline
format_call_args(call, false)
skip_space_or_newline
write_token :"]"
write_token :"?" if call.name == "[]?"
when :"[]", :"[]?"
write_token @token.type
skip_space_or_newline
if @token.type == :"("
write "("
next_token_skip_space_or_newline
format_call_args(call, true)
skip_space_or_newline
write_token :")"
end
else
raise "BUG: expected `[`, `[]` or `[]?`"
end
elsif !call.obj && call.name == "[]="
case @token.type
when :"["
last_arg = call.args.pop
write_token :"["
skip_space_or_newline
format_call_args(call, false)
skip_space_or_newline
write_token :"]"
skip_space
write_token " ", :"=", " "
skip_space_or_newline
accept last_arg
when :"[]="
write_token @token.type
skip_space_or_newline
if @token.type == :"("
write "("
next_token_skip_space_or_newline
format_call_args(call, true)
skip_space_or_newline
write_token :")"
end
else
raise "BUG: expected `[` or `[]=`"
end
else
indent(@indent, call)
end
indent(@indent, call)
when IsA
if body.obj.is_a?(Var)
if body.nil_check?
Expand Down