Skip to content

[Property Wrappers] Fix availability inference of synthesized property wrapper setters #36711

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

Conversation

hborla
Copy link
Member

@hborla hborla commented Apr 2, 2021

Intersect the availability of the wrapped/projected value setter with the availability of the enclosing scope when inferring the availability of the synthesized setter for an applied property wrapper.

Resolves: rdar://71872385

…ed value

setter with the availability of the enclosing scope when inferring the
availability of the synthesized setters for an applied property wrapper.
@hborla hborla requested a review from slavapestov April 2, 2021 01:12
@hborla
Copy link
Member Author

hborla commented Apr 2, 2021

@swift-ci please smoke test

@@ -1968,6 +1968,17 @@ static AccessorDecl *createSetterPrototype(AbstractStorageDecl *storage,

// Copy availability from the accessor we'll synthesize the setter from.
SmallVector<Decl *, 2> asAvailableAs;

auto addEnclosingScopeAvailability = [&]() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks similar to the code in configureInheritedDesignatedInitAttributes(). Maybe applyInferredAvailableAttrs() should take an optional Decl in addition to the array of AvailableAttrs, and walk over the Decls parents if its not null?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually it might be better to extract a getInnermostAvailabilityOfDecl() or something and use it in both places, or perhaps its not worth it at all...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd be useful to extract this code somewhere, especially if the availability inference doesn't work for _modify (which I think it doesn't), so it'll need to be used there as well

@@ -1978,6 +1989,7 @@ static AccessorDecl *createSetterPrototype(AbstractStorageDecl *storage,
if (info.valueVar) {
if (auto setter = info.valueVar->getOpaqueAccessor(AccessorKind::Set)) {
asAvailableAs.push_back(setter);
addEnclosingScopeAvailability();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing you don't have to worry about this with the getter because a property wrapper's getter cannot be less available than the property wrapper type, but if the wrapper defines a _modify as well?

@hborla
Copy link
Member Author

hborla commented Apr 5, 2021

@swift-ci please test source compatibility

@hborla
Copy link
Member Author

hborla commented Apr 5, 2021

@swift-ci please smoke test

@hborla
Copy link
Member Author

hborla commented Apr 6, 2021

@swift-ci please test Windows platform

@hborla hborla merged commit 95f8ed8 into swiftlang:main Apr 6, 2021
@hborla hborla deleted the property-wrapper-availability-inference branch April 6, 2021 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants