Skip to content

Commit 777435c

Browse files
author
Harlan Haskins
authored
Merge pull request swiftlang#24194 from harlanhaskins/unindentation-station
[ModuleInterface] Fix indentation for private(set) vars
2 parents 671df74 + 22bab7c commit 777435c

File tree

2 files changed

+30
-25
lines changed

2 files changed

+30
-25
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,6 +1726,10 @@ void PrintAST::printAccessors(const AbstractStorageDecl *ASD) {
17261726

17271727
auto impl = ASD->getImplInfo();
17281728

1729+
// AbstractAccessors is suppressed by FunctionDefinitions.
1730+
bool PrintAbstract =
1731+
Options.AbstractAccessors && !Options.FunctionDefinitions;
1732+
17291733
// Don't print accessors for trivially stored properties...
17301734
if (impl.isSimpleStored()) {
17311735
// ...unless we're printing for SIL, which expects a { get set? } on
@@ -1736,23 +1740,24 @@ void PrintAST::printAccessors(const AbstractStorageDecl *ASD) {
17361740
// ...or you're private/internal(set), at which point we'll print
17371741
// @_hasStorage var x: T { get }
17381742
else if (ASD->isSettable(nullptr) && hasLessAccessibleSetter(ASD)) {
1739-
Printer << " {";
1740-
{
1741-
IndentRAII indentMore(*this);
1743+
if (PrintAbstract) {
1744+
Printer << " { get }";
1745+
} else {
1746+
Printer << " {";
1747+
{
1748+
IndentRAII indentMore(*this);
1749+
indent();
1750+
Printer.printNewline();
1751+
Printer << "get";
1752+
}
17421753
indent();
17431754
Printer.printNewline();
1744-
Printer << "get";
1745-
Printer.printNewline();
1755+
Printer << "}";
17461756
}
1747-
Printer << "}";
17481757
}
17491758
return;
17501759
}
17511760

1752-
// AbstractAccessors is suppressed by FunctionDefinitions.
1753-
bool PrintAbstract =
1754-
Options.AbstractAccessors && !Options.FunctionDefinitions;
1755-
17561761
// We sometimes want to print the accessors abstractly
17571762
// instead of listing out how they're actually implemented.
17581763
bool inProtocol = isa<ProtocolDecl>(ASD->getDeclContext());

test/ModuleInterface/stored-properties.swift

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,29 @@ public struct HasStoredProperties {
3535
public var simpleStoredMutable: Int
3636

3737
// CHECK: @_hasStorage public var storedWithObservers: Swift.Bool {
38-
// RESILIENT: {{^}} public var storedWithObservers: Swift.Bool {
39-
// COMMON-NEXT: get
40-
// COMMON-NEXT: set
41-
// COMMON-NEXT: }
38+
// RESILIENT: {{^}} public var storedWithObservers: Swift.Bool {
39+
// COMMON-NEXT: {{^}} get
40+
// COMMON-NEXT: {{^}} set
41+
// COMMON-NEXT: {{^}} }
4242
public var storedWithObservers: Bool {
4343
willSet {}
4444
}
4545

4646
// CHECK: @_hasStorage public var storedPrivateSet: Swift.Int {
47-
// RESILIENT: {{^}} public var storedPrivateSet: Swift.Int {
48-
// COMMON-NEXT: get
49-
// COMMON-NEXT: }
47+
// RESILIENT: {{^}} public var storedPrivateSet: Swift.Int {
48+
// COMMON-NEXT: {{^}} get
49+
// COMMON-NEXT: {{^}} }
5050
public private(set) var storedPrivateSet: Int
5151

5252
// CHECK: private var privateVar: Swift.Bool
5353
// RESILIENT-NOT: private var privateVar: Swift.Bool
5454
private var privateVar: Bool
5555

5656
// CHECK: @_hasStorage @_hasInitialValue public var storedWithObserversInitialValue: Swift.Int {
57-
// RESILIENT: {{^}} public var storedWithObserversInitialValue: Swift.Int {
58-
// COMMON-NEXT: get
59-
// COMMON-NEXT: set
60-
// COMMON-NEXT: }
57+
// RESILIENT: {{^}} public var storedWithObserversInitialValue: Swift.Int {
58+
// COMMON-NEXT: {{^}} get
59+
// COMMON-NEXT: {{^}} set
60+
// COMMON-NEXT: {{^}} }
6161
public var storedWithObserversInitialValue: Int = 0 {
6262
didSet {}
6363
}
@@ -101,10 +101,10 @@ public struct HasStoredPropertiesFixedLayout {
101101
// COMMON: public var simpleStoredMutable: StoredProperties.BagOfVariables
102102
public var simpleStoredMutable: BagOfVariables
103103

104-
// COMMON: @_hasStorage public var storedWithObservers: StoredProperties.BagOfVariables {
105-
// COMMON-NEXT: get
106-
// COMMON-NEXT: set
107-
// COMMON-NEXT: }
104+
// COMMON: {{^}} @_hasStorage public var storedWithObservers: StoredProperties.BagOfVariables {
105+
// COMMON-NEXT: {{^}} get
106+
// COMMON-NEXT: {{^}} set
107+
// COMMON-NEXT: {{^}} }
108108
public var storedWithObservers: BagOfVariables {
109109
didSet {}
110110
}

0 commit comments

Comments
 (0)