Skip to content

Commit 2b9fa92

Browse files
committed
[AST Printing] Consider the storage decl as the "enclosing" decl of an acccessor
Fixes spurious #if's when printing for backward compatibility, rdar://75074036
1 parent 931c47d commit 2b9fa92

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2629,14 +2629,14 @@ static std::vector<Feature> getUniqueFeaturesUsed(Decl *decl) {
26292629
if (features.empty())
26302630
return features;
26312631

2632-
auto enclosingDecl = decl->getDeclContext()->getAsDecl();
2632+
Decl *enclosingDecl;
2633+
if (auto accessor = dyn_cast<AccessorDecl>(decl))
2634+
enclosingDecl = accessor->getStorage();
2635+
else
2636+
enclosingDecl = decl->getDeclContext()->getAsDecl();
26332637
if (!enclosingDecl)
26342638
return features;
26352639

2636-
if (!isa<NominalTypeDecl>(enclosingDecl) &&
2637-
!isa<ExtensionDecl>(enclosingDecl))
2638-
return features;
2639-
26402640
auto enclosingFeatures = getFeaturesUsed(enclosingDecl);
26412641
if (enclosingFeatures.empty())
26422642
return features;

test/ModuleInterface/features.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,17 @@ public class OldSchool: MP {
7373
func f() throws
7474
}
7575

76+
// CHECK: public struct UsesRP {
77+
public struct UsesRP {
78+
// CHECK: #if compiler(>=5.3) && $RethrowsProtocol
79+
// CHECK-NEXT: public var value: FeatureTest.RP? {
80+
// CHECK-NOT: #if compiler(>=5.3) && $RethrowsProtocol
81+
// CHECK: get
82+
public var value: RP? {
83+
nil
84+
}
85+
}
86+
7687
// CHECK: #if compiler(>=5.3) && $RethrowsProtocol
7788
// CHECK-NEXT: public func acceptsRP
7889
public func acceptsRP<T: RP>(_: T) { }

0 commit comments

Comments
 (0)