Skip to content

Commit c18ef1a

Browse files
committed
Properly collect all enclosing features.
1 parent 7015543 commit c18ef1a

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2697,15 +2697,30 @@ static std::vector<Feature> getUniqueFeaturesUsed(Decl *decl) {
26972697
if (features.empty())
26982698
return features;
26992699

2700-
Decl *enclosingDecl;
2701-
if (auto accessor = dyn_cast<AccessorDecl>(decl))
2702-
enclosingDecl = accessor->getStorage();
2703-
else
2704-
enclosingDecl = decl->getDeclContext()->getAsDecl();
2705-
if (!enclosingDecl)
2706-
return features;
2700+
// Gather the features used by all enclosing declarations.
2701+
Decl *enclosingDecl = decl;
2702+
std::vector<Feature> enclosingFeatures;
2703+
while (true) {
2704+
// Find the next outermost enclosing declaration.
2705+
if (auto accessor = dyn_cast<AccessorDecl>(enclosingDecl))
2706+
enclosingDecl = accessor->getStorage();
2707+
else
2708+
enclosingDecl = enclosingDecl->getDeclContext()->getAsDecl();
2709+
if (!enclosingDecl)
2710+
break;
2711+
2712+
auto outerEnclosingFeatures = getFeaturesUsed(enclosingDecl);
2713+
if (outerEnclosingFeatures.empty())
2714+
continue;
2715+
2716+
auto currentEnclosingFeatures = std::move(enclosingFeatures);
2717+
enclosingFeatures.clear();
2718+
std::merge(outerEnclosingFeatures.begin(), outerEnclosingFeatures.end(),
2719+
currentEnclosingFeatures.begin(), currentEnclosingFeatures.end(),
2720+
std::back_inserter(enclosingFeatures));
2721+
}
27072722

2708-
auto enclosingFeatures = getFeaturesUsed(enclosingDecl);
2723+
// If there were no enclosing features, we're done.
27092724
if (enclosingFeatures.empty())
27102725
return features;
27112726

test/ModuleInterface/features.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public class OldSchool2: MP {
7878
// CHECK: #if compiler(>=5.3) && $RethrowsProtocol
7979
// CHECK-NEXT: @rethrows public protocol RP
8080
@rethrows public protocol RP {
81-
func f() throws
81+
func f() throws -> Bool
8282
}
8383

8484
// CHECK: public struct UsesRP {
@@ -95,7 +95,15 @@ public struct UsesRP {
9595
// CHECK: #if compiler(>=5.3) && $RethrowsProtocol
9696
// CHECK-NEXT: public struct IsRP
9797
public struct IsRP: RP {
98-
public func f() { }
98+
// CHECK-NEXT: public func f()
99+
public func f() -> Bool { }
100+
101+
// CHECK-NOT: $RethrowsProtocol
102+
// CHECK-NEXT: public var isF:
103+
// CHECK-NEXT: get
104+
public var isF: Bool {
105+
f()
106+
}
99107
}
100108

101109
// CHECK: #if compiler(>=5.3) && $RethrowsProtocol

0 commit comments

Comments
 (0)