Skip to content

Commit 3998644

Browse files
authored
Merge pull request swiftlang#32533 from nathawes/fix-indentation-after-incomplete-func-decl-5.3
[5.3][SourceKit/Indentation] Fix over-indent after function declaration with no param list or body.
2 parents 213b598 + eeafb55 commit 3998644

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

lib/IDE/Formatting.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,6 +1906,11 @@ class FormatWalker : public ASTWalker {
19061906
return Aligner.getContextAndSetAlignment(CtxOverride);
19071907
}
19081908

1909+
// There are no parens at this point, so if there are no parameters either,
1910+
// this shouldn't be a context (it's an implicit parameter list).
1911+
if (!PL->size())
1912+
return None;
1913+
19091914
ListAligner Aligner(SM, TargetLocation, ContextLoc, Range.Start);
19101915
for (auto *PD: *PL)
19111916
Aligner.updateAlignment(PD->getSourceRange(), PD);

test/swift-indent/basic.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,3 +1036,19 @@ private var secondThing = item
10361036
.filter {},
10371037
firstThing = 20,
10381038
thirdThing = 56
1039+
1040+
1041+
// Function decls missing their parameter list and body shouldn't pick up the next token as a continuation.
1042+
1043+
struct BarType {
1044+
func bar
1045+
}
1046+
1047+
struct <#name#> {
1048+
<#fields#>
1049+
}
1050+
1051+
struct <#name#> {
1052+
<#fields#>
1053+
func foo() {}
1054+
}

0 commit comments

Comments
 (0)