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-2657] error: '(f: () -> ())' is not convertible to '(f: () -> ())' #45262

Closed
lilyball mannequin opened this issue Sep 15, 2016 · 6 comments
Closed

[SR-2657] error: '(f: () -> ())' is not convertible to '(f: () -> ())' #45262

lilyball mannequin opened this issue Sep 15, 2016 · 6 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

@lilyball
Copy link
Mannequin

lilyball mannequin commented Sep 15, 2016

Previous ID SR-2657
Radar None
Original Reporter @lilyball
Type Bug
Status Resolved
Resolution Done
Environment

Apple Swift version 3.0 (swiftlang-800.0.46.2 clang-800.0.38)

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

md5: 7a65e12153c1ff4a9c591acc187417a4

relates to:

  • SR-4014 Can't Call Overloaded Method Within Another Overloaded Method

Issue Description:

The following code produces a bad error:

private class Block<T> {
    let f: T
    init(f: T) { self.f = f }
}

func foo(block: () -> ()) {
    let b = Block<()->()>(f: block)
}

The error it produces is

unnamed.swift:7:26: error: '(f: () -> ())' is not convertible to '(f: () -> ())'
    let b = Block<()->()>(f: block)
                         ^~~~~~~~~~

If I change the code to say Block<()->()>.init(f: block) I get a much better error:

unnamed.swift:7:35: error: passing non-escaping parameter 'block' to function expecting an @escaping closure
    let b = Block<()->()>.init(f: block)
                                  ^

The original code should be producing this error as well.

@lilyball
Copy link
Mannequin Author

lilyball mannequin commented Sep 15, 2016

Similarly if I say

func foo(block: () -> ()) {
    let b: Block<()->()> = Block(f: block)
}

I get another unhelpful error:

unnamed.swift:7:28: error: cannot convert value of type 'Block<() -> ()>' to specified type 'Block<() -> ()>'
    let b: Block<()->()> = Block(f: block)
                           ^~~~~~~~~~~~~~~

@belkadan
Copy link
Contributor

cc @milseman

@milseman
Copy link
Mannequin

milseman mannequin commented Sep 23, 2016

This is a distinct problem, and not fixed by #4905

@CodaFi
Copy link
Member

CodaFi commented Jan 1, 2017

I have a partial solution that tackles the meat of this SR, but diagnosing the invalid type ascription is going to be gnarly and involve special-casing our escaping diagnostics to look into bound generic types.

@milseman
Copy link
Mannequin

milseman mannequin commented Jun 12, 2017

It's unlikely that I'll be able to address this any time soon. @rudkx, are you or Pavel able to hold onto this? Alternatively, CodaFi (JIRA User)?

@slavapestov
Copy link
Member

4.2 and master:

e.swift:7:30: error: passing non-escaping parameter 'block' to function expecting an @escaping closure
    let b = Block<()->()>(f: block)
                             ^
e.swift:6:10: note: parameter 'block' is implicitly non-escaping
func foo(block: () -> ()) {
         ^
                @escaping 

@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

3 participants