Skip to content

Commit c292861

Browse files
authored
[Parser] Preserve empty getter functions for indentation (#4586)
* [Parser] Preserve empty getter functions to make sure indentation inside its body still works. rdar://28049927 * Using the consistent identifier even though they are identical.
1 parent d790b5f commit c292861

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3417,10 +3417,19 @@ bool Parser::parseGetSetImpl(ParseDeclOptions Flags, ParameterList *Indices,
34173417
// Otherwise, we have a normal var or subscript declaration, parse the full
34183418
// complement of specifiers, along with their bodies.
34193419

3420-
// If the body is completely empty, reject it. This is at best a getter with
3420+
// If the body is completely empty, preserve it. This is at best a getter with
34213421
// an implicit fallthrough off the end.
34223422
if (Tok.is(tok::r_brace)) {
34233423
diagnose(Tok, diag::computed_property_no_accessors);
3424+
auto *TheDecl = createAccessorFunc(VarLBLoc, nullptr, TypeLoc(), nullptr,
3425+
SourceLoc(), Flags,
3426+
AccessorKind::IsGetter,
3427+
AddressorKind::NotAddressor, this,
3428+
SourceLoc());
3429+
3430+
TheDecl->setBody(BraceStmt::create(Context, VarLBLoc, {}, Tok.getLoc()));
3431+
TheDecl->setInvalid();
3432+
Decls.push_back(TheDecl);
34243433
return true;
34253434
}
34263435

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
for i in 0...5 {
22
}
33

4+
var someProperty: String {
5+
6+
}
47
// RUN: %sourcekitd-test -req=format -line=1 -length=1 %s >%t.response
58
// RUN: %sourcekitd-test -req=format -line=2 -length=1 %s >>%t.response
9+
// RUN: %sourcekitd-test -req=format -line=5 -length=1 %s >>%t.response
610
// RUN: %FileCheck --strict-whitespace %s <%t.response
711

812
// CHECK: key.sourcetext: "for i in 0...5 {"
913
// CHECK: key.sourcetext: "}"
14+
// CHECK: key.sourcetext: " "

0 commit comments

Comments
 (0)