Skip to content

[PropertyWrappers] Fix a bug with class property wrapper access control #29023

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 2 commits into from
Jan 14, 2020
Merged

[PropertyWrappers] Fix a bug with class property wrapper access control #29023

merged 2 commits into from
Jan 14, 2020

Conversation

theblixguy
Copy link
Collaborator

The following code currently triggers an error saying that the access level of the initializer is less than the type:

@propertyWrapper
open class OpenPropertyWrapperWithPublicInit {
  // error: public initializer 'init(wrappedValue:)' cannot have 
  //        more restrictive access than its enclosing property 
  //        wrapper type 'OpenPropertyWrapperWithPublicInit' (which is open)  
  public init(wrappedValue: String) {
    self.wrappedValue = wrappedValue
  }
  
  open var wrappedValue: String = "Hello, world"
}

If you change it from public to open, then you get an error because initializers cannot be marked open. So, you're stuck in a loop.

When looking for suitable wrapper inits, make sure we bound the check to AccessLevel::Public.

Resolves SR-11994.

…o make sure to consider that when looking for suitable wrapper inits
@theblixguy theblixguy requested a review from DougGregor January 6, 2020 18:55
Copy link
Member

@DougGregor DougGregor left a comment

Choose a reason for hiding this comment

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

We have threw same kind of getFormalAccess comparison in several places within the property wrappers code. Can you pull this fixed check into a separate static function and use it consistently throughout TypeCheckPropertyWrapper.cpp?

@theblixguy
Copy link
Collaborator Author

@DougGregor Sure, I have done that now.

@theblixguy
Copy link
Collaborator Author

@swift-ci please smoke test

@theblixguy
Copy link
Collaborator Author

@swift-ci please smoke test linux

@theblixguy theblixguy requested a review from DougGregor January 9, 2020 13:51
@theblixguy
Copy link
Collaborator Author

@DougGregor Shall I create a PR for 5.2 as well?

Copy link
Member

@DougGregor DougGregor left a comment

Choose a reason for hiding this comment

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

Looks great! Please do cherry-pick for 5.2

@theblixguy theblixguy merged commit 29268e2 into swiftlang:master Jan 14, 2020
@theblixguy theblixguy deleted the fix/SR-11994 branch January 14, 2020 07:53
@theblixguy theblixguy restored the fix/SR-11994 branch January 14, 2020 07:56
@theblixguy theblixguy deleted the fix/SR-11994 branch January 14, 2020 18:13
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