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-2355] Typealias and escaping #44962

Closed
swift-ci opened this issue Aug 16, 2016 · 3 comments
Closed

[SR-2355] Typealias and escaping #44962

swift-ci opened this issue Aug 16, 2016 · 3 comments
Assignees

Comments

@swift-ci
Copy link
Collaborator

@swift-ci swift-ci commented Aug 16, 2016

Previous ID SR-2355
Radar None
Original Reporter diegosanchezr (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Environment

Swift 3 Xcode 8 b6

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee @slavapestov
Priority Medium

md5: 67bc4caa824a17d9c863a46912ed30bc

duplicates:

Issue Description:

Xcode b6:

typealias Completion = () -> Void

func myFunc(completion: Completion) {
    DispatchQueue.main.async {
        completion()
    }
}

myFunc {
    print("foo")
}

That seems to assume already that the closures scapes the function, while without the typealias I have to write

func myFunc(completion: @escaping () -> Void) {
    DispatchQueue.main.async {
        completion()
    }
}

I would like to write

func myFunc(completion: @escaping Completion) {
    DispatchQueue.main.async {
        completion()
    }
}

but that triggers the error "@escaping attribute applies only to function types"

Also, I see this syntax is supported:

typealias Completion = @escaping () -> Void

but it breaks quick lookup in Xcode (IMO @escaping shouldn't be allowed in typealias)

@nikolaykasyanov
Copy link

@nikolaykasyanov nikolaykasyanov commented Jan 25, 2019

I'm experiencing a similar issue in Xcode 10.2 beta, the following code doesn't compile:

public enum Outcome {
    case A
    case B
}


public protocol Runner {
    typealias Completion = (Outcome) -> ()


    func run<D>(input: D, completion: @escaping Completion)
}

It does compile if run function isn't generic though.

Should I report it separately?

@slavapestov
Copy link
Member

@slavapestov slavapestov commented Jan 25, 2019

Yes please, this looks like a separate bug.

@nikolaykasyanov
Copy link

@nikolaykasyanov nikolaykasyanov commented Jan 25, 2019

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

No branches or pull requests

3 participants