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-4967] @escaping can not be used on function-type type aliases in protocols #47544

Closed
swift-ci opened this issue May 22, 2017 · 4 comments
Closed
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-4967
Radar None
Original Reporter thm (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Environment

OS X 10.11.6
Xcode Version 8.2.1 (8C1002) and command line
Swift 3.1 and 4 development snapshot 2017-05-12

Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: ede303f7483f4ebdc4bd34da3f042a5a

duplicates:

  • SR-9760 Can't add @escaping to an argument of generic function having typealiased function type

Issue Description:

Using a function-type type alias as an escaping parameter type fails to compile:

protocol Foo
{
    associatedtype Bar
    typealias Callback = (Bar) -> Void

    var currentValue: Bar { get }
}

// Error: @escaping attribute only applies to function types
func callBroken<T: Foo>(foo: T, callback: @escaping T.Callback) {
    DispatchQueue.main.async { callback(foo.currentValue) }
}

// Spelling it out works (of course).
func callWorks<T: Foo>(foo: T, callback: @escaping (T.Bar) -> Void) {
    DispatchQueue.main.async { callback(foo.currentValue) }
}

I know there is SR-2316 and several duplicates. Especially the comment by Jordan Rose addresses what I think is still broken:

The actual behavior we want here is that @escaping is a property of the parameter, not the function type, but we don't currently allow you to write @escaping on typealiases.

Later in the comments, David Grove added "fix confirmed" but he was probably referring to something else.

I tested this with swift-3.1-RELEASE.xctoolchain and swift-DEVELOPMENT-SNAPSHOT-2017-05-12-a.xctoolchain.

@belkadan
Copy link
Contributor

I suspect we aren't properly resolving the typealias here—it works if it's not on a generic parameter (and doesn't mention Bar, of course). @slavapestov, any insights?

@swift-ci
Copy link
Collaborator Author

swift-ci commented Apr 3, 2019

Comment by Ky (JIRA)

This was marked as resolved. In what version of Swift was it implemented? Can I expect to take advantage of this in production today?

@belkadan
Copy link
Contributor

belkadan commented Apr 3, 2019

It's marked as a duplicate, so you have to look at the duplicate to see where it was fixed.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Apr 3, 2019

Comment by Ky (JIRA)

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

No branches or pull requests

2 participants