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-11131] Nested protocolWrappers can't be typealias'ed when parent type is generic #53527

Closed
swift-ci opened this issue Jul 15, 2019 · 7 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-11131
Radar rdar://problem/53107270
Original Reporter johnestropia (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Swift 5.1, Xcode 11 release

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

md5: 4fdc99fc5b539614f8e04a4b134d7537

duplicates:

  • SR-11288 Property wrappers aren't inherited as type aliases

relates to:

  • SR-11120 [5.1] [property wrapper] attribute lookup does not include typealiases

Issue Description:

A @propertyWrapper declared nested within any generic type can't be accessed from a typealias of it's parent type. See example below:

protocol DynamicObject {}
 
enum ValueContainer<O: DynamicObject> {
    @propertyWrapper struct Required<V> {
        let key: String
        var wrappedValue: V
        init(_ key: String, initial: () -> V) {
            self.key = key
            self.wrappedValue = initial()
        }
    }
}
 
extension DynamicObject {
    typealias Value = ValueContainer<Self>
}
 
open class MyObject: DynamicObject {
    /* Works, but not ideal */
    @ValueContainer<MyObject>.Required("name", initial: { "" })
    var name: String
 
    /* Does NOT work: */
//    @Value.Required("age", initial: { 0 })
//    var age: Int
 
    /* Note, this had always worked */
    let birthday = Value.Required<Date>("birthday", initial: { Date() })
}

Note that it works if we don't use the @propertyWrapper mechanism and use the type directly as a value (as in birthday above).

The Self constraint on ValueContainer does not seem to be relevant as it still has the same problem if we assign any arbitrary protocol, for example:

enum ValueContainer<O: Equatable> // ...

extension DynamicObject {
    typealias Value = ValueContainer<Int>
}
@belkadan
Copy link
Contributor

@swift-ci create

@swift-ci
Copy link
Collaborator Author

Comment by John Estropia (JIRA)

I understand this was marked "Resolved" due to https://bugs.swift.org/browse/SR-11120 being fixed, but there is still the error where generic typealiases that involve Self could not be resolved

    typealias Value = ValueContainer<Self>
    /* Unknown attribute 'Value.Required' */
//    @Value.Required("age", initial: { 0 })
//    var age: Int
 
    /* This works */
    let birthday = Value.Required<Date>("birthday", initial: { Date() })

Since the direct use of Value.Required in stored properties work, it doesn't make much sense for it to NOT be allowed in propertyWrappers.

@theblixguy
Copy link
Collaborator

The example in the bug report works as expected on master. This fix was not cherry-picked into Swift 5.1, so it won't work on Xcode 11 or on a 5.1 toolchain. It may be cherry-picked later and available in a point release.

@swift-ci
Copy link
Collaborator Author

Comment by John Estropia (JIRA)

@theblixguy I see, thanks for the clarification!

@swift-ci
Copy link
Collaborator Author

Comment by John Estropia (JIRA)

@theblixguy Is there any target Swift version for this patch?
It had been quite a while but it doesn't look like Swift 5.2 contains this commit yet so I'm curious if there is anything keeping it from being cherry-picked.

@theblixguy
Copy link
Collaborator

The example above works for me on master. Are you using the most recent 5.2 toolchain?

@swift-ci
Copy link
Collaborator Author

Comment by John Estropia (JIRA)

Ah sorry, I was under the misconception that Xcode 11.3 had Swift 5.2 already.
Confirmed this works on the development snapshot for 5.2. Thanks again!

@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
Projects
None yet
Development

No branches or pull requests

3 participants