Skip to content

[AST Printing] Consider the storage decl as the "enclosing" decl of an accessor #36304

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2629,14 +2629,14 @@ static std::vector<Feature> getUniqueFeaturesUsed(Decl *decl) {
if (features.empty())
return features;

auto enclosingDecl = decl->getDeclContext()->getAsDecl();
Decl *enclosingDecl;
if (auto accessor = dyn_cast<AccessorDecl>(decl))
enclosingDecl = accessor->getStorage();
else
enclosingDecl = decl->getDeclContext()->getAsDecl();
if (!enclosingDecl)
return features;

if (!isa<NominalTypeDecl>(enclosingDecl) &&
!isa<ExtensionDecl>(enclosingDecl))
return features;

auto enclosingFeatures = getFeaturesUsed(enclosingDecl);
if (enclosingFeatures.empty())
return features;
Expand Down
11 changes: 11 additions & 0 deletions test/ModuleInterface/features.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ public class OldSchool: MP {
func f() throws
}

// CHECK: public struct UsesRP {
public struct UsesRP {
// CHECK: #if compiler(>=5.3) && $RethrowsProtocol
// CHECK-NEXT: public var value: FeatureTest.RP? {
// CHECK-NOT: #if compiler(>=5.3) && $RethrowsProtocol
// CHECK: get
public var value: RP? {
nil
}
}

// CHECK: #if compiler(>=5.3) && $RethrowsProtocol
// CHECK-NEXT: public func acceptsRP
public func acceptsRP<T: RP>(_: T) { }
Expand Down