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-15054] Better handle multiple trailing closure ambiguity #57381

Open
hamishknight opened this issue Aug 11, 2021 · 1 comment
Open

[SR-15054] Better handle multiple trailing closure ambiguity #57381

hamishknight opened this issue Aug 11, 2021 · 1 comment
Labels
compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation improvement

Comments

@hamishknight
Copy link
Collaborator

Previous ID SR-15054
Radar rdar://problem/81799457
Original Reporter @hamishknight
Type Improvement
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Improvement, DiagnosticsQoI
Assignee None
Priority Medium

md5: 3bda7243ecd7fc86fe610362ca724486

Issue Description:

For the single trailing closure case, we offer specialized fix-its to disambiguate by argument label:

func foo(a: () -> Void) {}
func foo(b: () -> Void) {}
foo {}
// error: ambiguous use of 'foo' [ambiguous_decl_ref]
// foo {}
// ^
// note: use an explicit argument label instead of a trailing closure to call 'foo(a:)' [ambiguous_because_of_trailing_closure]
// foo {}
// ^  ~
//   (a:  )
// note: use an explicit argument label instead of a trailing closure to call 'foo(b:)' [ambiguous_because_of_trailing_closure]
// foo {}
// ^  ~
//   (b:  )

However we don't currently do the same for the multiple trailing closure case:

func foo(_ fn: () -> Void, a: () -> Void) {}
func foo(_ fn: () -> Void, b: () -> Void) {}
foo {} _: {}
//  error: no exact matches in call to global function 'foo' [no_overloads_match_exactly_in_call]
//  foo {} _: {}
//  ^
//  note: incorrect labels for candidate (have: '(_:_:)', expected: '(_:a:)') [candidate_expected_different_labels]
//  func foo(_ fn: () -> Void, a: () -> Void) {}
//       ^
//  note: incorrect labels for candidate (have: '(_:_:)', expected: '(_:b:)') [candidate_expected_different_labels]
//  func foo(_ fn: () -> Void, b: () -> Void) {}
//       ^

And same for when the ambiguity is with the first trailing closure. We could do a better job with this.

@typesanitizer
Copy link

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation improvement
Projects
None yet
Development

No branches or pull requests

2 participants