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-9958] Incorrect error message for non-matching signatures with KeyPaths #52362

Closed
tkrajacic opened this issue Feb 19, 2019 · 2 comments
Closed
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation good first issue Good for newcomers type checker Area → compiler: Semantic analysis

Comments

@tkrajacic
Copy link

Previous ID SR-9958
Radar None
Original Reporter @tkrajacic
Type Bug
Status Closed
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI, StarterBug, TypeChecker
Assignee @tkrajacic
Priority Medium

md5: 7a614cb1ea7c7324d5370aec7df5396f

is duplicated by:

  • SR-9961 Incorrect diagnostic when using read-only property with ReferenceWritableKeyPath (on in Swift >= 5 mode).

Issue Description:

Notes inline:

import Cocoa
class MsPiggy: NSObject {
    let k = Kermit()
    
    func party() {
        // `Type of expression is ambiguous without more context`
        // but in Swift 5 the compiler correctly sees that both 
        // functions `a` don't match because the keypath is not 
        // writable (`private(set)`). The error message could be better
        k.a(\.color) { v in }
    }
}
class Kermit: NSObject {
    @objc dynamic private(set) var color: NSColor!
}
extension NSObjectProtocol where Self: NSObject {
    func a<Value>(_ keyPath: ReferenceWritableKeyPath<Self, Value>, onChange: @escaping (Value) -> ()) {}
    func a<Value>(_ keyPath: ReferenceWritableKeyPath<Self, Value>, onChange: @escaping (Self, Value) -> ()) {}
}
@swift-ci
Copy link
Collaborator

swift-ci commented Jun 8, 2019

Comment by Steven Brunwasser (JIRA)

Fixed in Swift 5.1. Please verify with the latest nightly build.

/Users/steve/Desktop/Piggy.swift:11:13: error: cannot convert value of type 'KeyPath<Kermit, NSColor?>' to specified type 'ReferenceWritableKeyPath<Kermit, NSColor?>'
        k.a(\.color) { v in }
            ^~~~~~~

@tkrajacic
Copy link
Author

Checked in Xcode 11b3 and it works as intended now.

Thank you for your hard work.

@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 diagnostics QoI Bug: Diagnostics Quality of Implementation good first issue Good for newcomers type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

2 participants