Skip to content
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

[SR-11994] Open class cannot be a PropertyWrapper #54428

Closed
4brunu opened this issue Jan 6, 2020 · 3 comments
Closed

[SR-11994] Open class cannot be a PropertyWrapper #54428

4brunu opened this issue Jan 6, 2020 · 3 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself property wrappers Feature: property wrappers type checker Area → compiler: Semantic analysis

Comments

@4brunu
Copy link

4brunu commented Jan 6, 2020

Previous ID SR-11994
Radar None
Original Reporter @4brunu
Type Bug
Status Resolved
Resolution Done
Environment

Xcode Version 11.3 (11C29)

Swift 5.1

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, PropertyWrappers, TypeChecker
Assignee @theblixguy
Priority Medium

md5: d3f7e4c06cfb726dfc243ef2cf442ab2

Issue Description:

I have an open class that I wanted also to be a property wrapper.

The problem is that the property wrapper requires the initializer to have the same visibility modifier as the class (open in this case), but the initilizers cannot be open, so it's a cycle.

Here is a code sample with the Xcode errors as a comment.

@propertyWrapper
open class PropertyWrapperWithOpenInit {
    var _value: String
    open init(wrappedValue: String) { // error: only classes and overridable class members can be declared 'open'; use 'public'
        self._value = wrappedValue
    }
    open var wrappedValue: String {
        get {
            return _value
        }
        set {
            _value = newValue
        }
    }
}

@propertyWrapper
open class PropertyWrapperWithoutOpenInit {
    var _value: String
    public init(wrappedValue: String) { // error: public initializer 'init(wrappedValue:)' cannot have more restrictive access than its enclosing property wrapper type 'PropertyWrapperWithoutOpenInit' (which is open)
        self._value = wrappedValue
    }
    open var wrappedValue: String {
        get {
            return _value
        }
        set {
            _value = newValue
        }
    }
}
@theblixguy
Copy link
Collaborator

Fix: #29023

@theblixguy
Copy link
Collaborator

Fixed on master. Please verify using the next available trunk snapshot!

I have also opened a PR to cherry-pick this to 5.2, once merged you can verify it using the next 5.2 snapshot: #29193

@theblixguy
Copy link
Collaborator

5.2 PR merged as well, please verify using the next available 5.2 development snapshot.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself property wrappers Feature: property wrappers type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

2 participants