Skip to content

Commit 1fbb705

Browse files
authored
[Parser] Preserve empty getter functions for indentation (#4586) (#4592)
* [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 de74c5a commit 1fbb705

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
@@ -3522,10 +3522,19 @@ bool Parser::parseGetSetImpl(ParseDeclOptions Flags, ParameterList *Indices,
35223522
// Otherwise, we have a normal var or subscript declaration, parse the full
35233523
// complement of specifiers, along with their bodies.
35243524

3525-
// If the body is completely empty, reject it. This is at best a getter with
3525+
// If the body is completely empty, preserve it. This is at best a getter with
35263526
// an implicit fallthrough off the end.
35273527
if (Tok.is(tok::r_brace)) {
35283528
diagnose(Tok, diag::computed_property_no_accessors);
3529+
auto *TheDecl = createAccessorFunc(VarLBLoc, nullptr, TypeLoc(), nullptr,
3530+
SourceLoc(), Flags,
3531+
AccessorKind::IsGetter,
3532+
AddressorKind::NotAddressor, this,
3533+
SourceLoc());
3534+
3535+
TheDecl->setBody(BraceStmt::create(Context, VarLBLoc, {}, Tok.getLoc()));
3536+
TheDecl->setInvalid();
3537+
Decls.push_back(TheDecl);
35293538
return true;
35303539
}
35313540

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)