Skip to content

Commit 4f7d5f3

Browse files
authored
[fix] Always render parens for capitalized methods with receivers (#870)
1 parent 3fd2134 commit 4f7d5f3

3 files changed

Lines changed: 64 additions & 1 deletion

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Call nodes don't need to disambiguate blocks
2+
Case
3+
Case()
4+
Case { }
5+
Case() { }
6+
Case do; end
7+
Case() do; end
8+
Case(args) { }
9+
Case(args) do ;end
10+
11+
# But ConstantReadNodes must disambiguate blocks
12+
Test::Case
13+
Test::Case()
14+
Test::Case { }
15+
Test::Case() { }
16+
Test::Case() do; end
17+
Test::Case(args) { }
18+
Test::Case(args) do ;end
19+
20+
Test.Case
21+
Test.Case()
22+
Test.Case { }
23+
Test.Case() { }
24+
Test.Case() do; end
25+
Test.Case(args) { }
26+
Test.Case(args) do ;end
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Call nodes don't need to disambiguate blocks
2+
Case
3+
Case()
4+
Case { }
5+
Case { }
6+
Case do
7+
end
8+
9+
Case do
10+
end
11+
12+
Case(args) { }
13+
Case(args) do
14+
end
15+
16+
# But ConstantReadNodes must disambiguate blocks
17+
Test::Case
18+
Test::Case()
19+
Test::Case() { }
20+
Test::Case() { }
21+
Test::Case() do
22+
end
23+
24+
Test::Case(args) { }
25+
Test::Case(args) do
26+
end
27+
28+
Test.Case()
29+
Test.Case()
30+
Test.Case() { }
31+
Test.Case() { }
32+
Test.Case() do
33+
end
34+
35+
Test.Case(args) { }
36+
Test.Case(args) do
37+
end

librubyfmt/src/format_prism.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1708,7 +1708,7 @@ fn use_parens_for_call_node<'src>(
17081708
});
17091709

17101710
if is_terminal_call && method_name.first().is_some_and(|c| c.is_ascii_uppercase()) {
1711-
if !has_arguments && call_node.block().is_some() {
1711+
if !has_arguments && call_node.block().is_some() && call_node.receiver().is_none() {
17121712
return false;
17131713
}
17141714
return true;

0 commit comments

Comments
 (0)