Skip to content

Commit d2f60e6

Browse files
authored
Merge pull request #22287 from nkcsgexi/indent-fix-5.0
[5.0] sourcekitd/format: avoid performing sibling-based indentation for PrefixUnaryExpr.
2 parents 19b6ba7 + 10f4ba1 commit d2f60e6

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

lib/IDE/Formatting.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,8 +575,12 @@ class FormatWalker : public SourceEntityWalker {
575575
};
576576

577577
if (auto AE = dyn_cast_or_null<ApplyExpr>(Node.dyn_cast<Expr *>())) {
578-
collect(AE->getArg());
579-
return;
578+
// PrefixUnaryExpr shouldn't be syntacticly considered as a funtion call
579+
// for sibling alignment.
580+
if (!isa<PrefixUnaryExpr>(AE)) {
581+
collect(AE->getArg());
582+
return;
583+
}
580584
}
581585

582586
if (auto PE = dyn_cast_or_null<ParenExpr>(Node.dyn_cast<Expr *>())) {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
if condition,
2+
!condition,
3+
condition,
4+
condition,
5+
!condition,
6+
condition {
7+
}
8+
9+
10+
// RUN: %sourcekitd-test -req=format -line=2 -length=1 %s >%t.response
11+
// RUN: %sourcekitd-test -req=format -line=3 -length=1 %s >>%t.response
12+
// RUN: %sourcekitd-test -req=format -line=4 -length=1 %s >>%t.response
13+
// RUN: %sourcekitd-test -req=format -line=5 -length=1 %s >>%t.response
14+
// RUN: %sourcekitd-test -req=format -line=6 -length=1 %s >>%t.response
15+
16+
// RUN: %FileCheck --strict-whitespace %s <%t.response
17+
18+
// CHECK: key.sourcetext: " !condition,"
19+
// CHECK: key.sourcetext: " condition,"
20+
// CHECK: key.sourcetext: " condition,"
21+
// CHECK: key.sourcetext: " !condition,"
22+
// CHECK: key.sourcetext: " condition {"

0 commit comments

Comments
 (0)