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-12880] Autocomplete for multiple trailing closures produces invalid results #55327

Closed
jshier opened this issue May 26, 2020 · 4 comments
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@jshier
Copy link
Contributor

jshier commented May 26, 2020

Previous ID SR-12880
Radar rdar://problem/63627617
Original Reporter @jshier
Type Bug

Attachment: Download

Environment

Swift 5.3 toolchain from 5/19, Xcode 11.5.

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

md5: 17f28578e5367659b43e96dc75a4fa99

Issue Description:

New API is being built for Alamofire involving multiple closures, so it was designed with multiple trailing closure syntax in mind.

func withAllRequests(completingOn queue: DispatchQueue = .main,
                     perform action: @escaping (Request) -> Void,
                     completion: (() -> Void)? = nil)

Xcode 11.5 with the latest 5.3 toolchain offers the completions shown in the attached screenshot:

  • The full function definition, with all parameters, which completes well (though there should be more combinations available).

  • The second, which appears to suggest only the non-defaulted closure argument.

Accepting the second suggestion inserts the following:

session.withAllRequests { (<#Request#>) in
            <#code#>
        }

Due to the parameter the compiler considers this invalid, as the single closure syntax is only compatible with the last closure. The only way to enter the non-defaulted closure by itself is with the full function syntax.

Tagging @benlangmuir since he appeared to be working on the autocomplete during the review thread.

@jshier
Copy link
Contributor Author

jshier commented May 26, 2020

This also appears to apply if I try to complete just the action closure after deleting the other parameters. It completes into single trailing closure syntax, which is incorrect.

@benlangmuir
Copy link
Member

This is caused by the separation between code-completion and placeholder expansion. When we go to expand the placeholder there is no syntactic reason we cannot produce a trailing closure.

@benlangmuir
Copy link
Member

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@bnbarham
Copy link
Contributor

Not sure when this was fixed, but we now provide the following completions:

key.sourcetext: "withAllRequests(completingOn: <#T##DispatchQueue#>, perform: <#T##(Request) -> Void#>, completion: <#T##(() -> Void)?##(() -> Void)?##() -> Void#>)",
key.sourcetext: "withAllRequests(perform: <#T##(Request) -> Void#>)",

Expanding either placeholder in the first case will expand to multiple trailing closures:

  withAllRequests(completingOn: <#T##DispatchQueue#>) { <#Request#> in
    <#code#>
  } completion: {
    <#code#>
  }

Expanding perform in the second case expands just to the single trailing closure:

  withAllRequests { <#Request#> in
    <#code#>
  }

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

No branches or pull requests

3 participants