Skip to content

Commit 603ca95

Browse files
author
Nathan Hawes
authored
Merge pull request #32513 from nathawes/fix-indentation-after-incomplete-func-decl
[SourceKit/Indentation] Fix over-indent after function decl with no param list or body.
2 parents 2d250bb + 436d475 commit 603ca95

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
@@ -1907,6 +1907,11 @@ class FormatWalker : public ASTWalker {
19071907
return Aligner.getContextAndSetAlignment(CtxOverride);
19081908
}
19091909

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