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-12530] Faulty compiler error when passing keypath to property wrapper in Swift 5.2 #54973

Closed
swift-ci opened this issue Apr 6, 2020 · 4 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself regression swift 5.2

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Apr 6, 2020

Previous ID SR-12530
Radar rdar://problem/61911117
Original Reporter xy (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Additional Detail from JIRA
Votes 2
Component/s Compiler
Labels Bug, 5.2Regression
Assignee xy (JIRA)
Priority Medium

md5: 08076328c000c9215ccfcb5afab360f0

Issue Description:

The Problem:

The below code compiles fine on Swift 5.1 compiler, however Swift 5.2 introduced a bug in the compiler. Now it fails to compile, with the error "Key path cannot refer to static member 'bar'"

@propertyWrapper
struct Wrap<R, V> {
    var val: V 
    var wrappedValue: V {
        get { val }
        set { val = newValue }
    }
    init(_ key: WritableKeyPath<R,V>, val: V) {
        self.val = val
    }
}

struct Foo {
    @Wrap(\Foo.bar, val: 1) var bar: Int
}

Current Workaround

The following compiles in 5.2 with no errors and works fine:

struct Foo {
    static let barKeyPath: WritableKeyPath<Foo, Int> = \.bar
    @Wrap(barKeyPath, val: 1) var bar: Int
}

This is not an acceptable workaround though due to how many places we would need to use it. As a result this bug makes Swift 5.2 unusable for us. Please fix soon, thanks.

@weissi
Copy link
Member

weissi commented Apr 7, 2020

@swift-ci create

@theblixguy
Copy link
Collaborator

Works fine on master. Can you verify using the latest trunk snapshot?

@swift-ci
Copy link
Collaborator Author

swift-ci commented May 3, 2020

Comment by Thomas Dekker (JIRA)

This issue is also really quite breaking for me. I use KeyPaths to neatly match the property within a meta model for a database without a lot of boilerplate.

The issue only occurs if a KeyPath is used with the initializer of the property wrapper of that same property. See my attachment for an example. It occurs in Xcode 11.4.1 using Swift 5.2.

However, I did test this using the Swift Snapshot 2020-04-30 with Xcode 11.4.1. This DOES work correctly. It seems this has already been fixed, but not released.

@hborla
Copy link
Member

hborla commented Jul 2, 2020

This is fixed in Swift 5.3. Could you please verify with Xcode 12 beta 1? Thank you!

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

No branches or pull requests

5 participants