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-13239] non-specific diagnostic when returning the wrong type in a trailing closure #55680

Closed
marcrasi mannequin opened this issue Jul 17, 2020 · 3 comments
Closed
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 regression swift 5.3 type checker Area → compiler: Semantic analysis

Comments

@marcrasi
Copy link
Mannequin

marcrasi mannequin commented Jul 17, 2020

Previous ID SR-13239
Radar None
Original Reporter @marcrasi
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, 5.3Regression, DiagnosticsQoI, TypeChecker
Assignee None
Priority Medium

md5: 89a63abc4e2bb2e683761395433e4116

Issue Description:

func callit<T>(_ f: () -> T) -> T {
  f()
}

func test() -> Int {
  // Actual diagnostic:
  //   error: type of expression is ambiguous without more context
  //   callit {
  //   ^~~~~~~~

  // Desired diagnostic:
  //   error: cannot convert return expression of type '()' to return type 'Int'
  //   print("hello")
  //   ^~~~~~~~~~~~~~
  // (or anything similarly informative).
  callit {
    print("hello")
  }
}

Environment: swift-DEVELOPMENT-SNAPSHOT-2020-07-14-a-ubuntu20.04

@theblixguy
Copy link
Collaborator

cc @xedin @hborla This is also a regression, it might have the same cause as SR-13240.

@xedin
Copy link
Member

xedin commented Jul 20, 2020

@theblixguyluciano (JIRA User) If you want to take a look at this here is a hint - solver infers both `Int` and `Void` as possible types and it forms 3 solutions with fixes, we could either - try to attribute contextual mismatch to the same location - closure result, or teach `diagnoseAmbiguityWithFixes` that all three locators associated with fixes effectively point to the same place and diagnose either one.

@LucianoPAlmeida
Copy link
Collaborator

Fixed by #37896
@marcrasi Can you please verify on the next available main snapshot?

@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 regression swift 5.3 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

4 participants