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-8088] Unhelpful error message when dealing with generics #50621

Closed
swift-ci opened this issue Jun 23, 2018 · 3 comments
Closed

[SR-8088] Unhelpful error message when dealing with generics #50621

swift-ci opened this issue Jun 23, 2018 · 3 comments
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 type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-8088
Radar rdar://problem/41704731
Original Reporter twof (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Xcode 9.4
Swift 4.1

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI, TypeChecker
Assignee twof (JIRA)
Priority Medium

md5: c0189d6595a8cb64dd9f4d3c55345615

Issue Description:

Repro code

public class TestBlankClass {}

public class Option<U, S> {
    public var onExecution: ([U], S) -> S
    
    public init(
        onExecution: @escaping ([U], S) -> S
    ) {
        self.onExecution = onExecution
    }
    
    public func execute() {
        let change: S = self.onExecution([], TestBlankClass()) // error:'([U], S) -> S' is not convertible to '@lvalue ([U], S) -> S'
    }
}

This particular contrived case can be resolved (poorly) by force downcasting to `S`

let change: S = self.onExecution([], TestBlankClass() as! S) // compiles

The error message does a poor job of describing what the problem is though and ought to be changed to be more descriptive.

@belkadan
Copy link
Contributor

Still occurs on near-master. @xedin, do you have a dup for this already?

@xedin
Copy link
Member

xedin commented Jul 2, 2018

@swift-ci create

@hborla
Copy link
Member

hborla commented Feb 6, 2020

This is resolved in Swift 5.2. The compiler now reports the specific conversion failure along with a fix-it:

error: cannot convert value of type 'TestBlankClass' to expected argument type 'S'
        let change: S = self.onExecution([], TestBlankClass())
                                             ^
                                                              as! S

Could you please verify using a recent 5.2 snapshot or the latest Xcode beta? 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 diagnostics QoI Bug: Diagnostics Quality of Implementation type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

4 participants