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-11389] Confusing error message when missing an overload #53790

Open
swift-ci opened this issue Aug 29, 2019 · 4 comments
Open

[SR-11389] Confusing error message when missing an overload #53790

swift-ci opened this issue Aug 29, 2019 · 4 comments
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 type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-11389
Radar None
Original Reporter apaszke (JIRA User)
Type Bug
Environment

Apple Swift version 5.1 (swiftlang-1100.0.257.2 clang-1100.0.31.3)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI, TypeChecker
Assignee None
Priority Medium

md5: 85ecbb6649272e11d56e10a5e3aecbec

relates to:

  • SR-1528 Swift compiler requires closures without parameter lists to reference all arguments

Issue Description:

An attempt to compile this code (which is incorrect, because perform does not have an overload for [Int]):

func perform(operation op: (Int) -> Int?, on: Int) {}
func perform(operation op: (Int) -> Int?, on: Float) {}

func count(from: Int) -> () -> Int {
  var counter = -1
  return { counter += 1; return counter }
}

func something(_ x: [Int]) -> [Int] {
  let counter = count(from: 1)
  return perform(operation: { counter() }, on: x)
}

produces the following error, which is misleading because the closure is not really escaping:

error.swift:12:10: error: cannot invoke 'perform' with an argument list of type '(operation: @escaping () -> Int, on: [Int])'
  return perform(operation: { counter() }, on: x)
         ^
error.swift:12:10: note: overloads for 'perform' exist with these partially matching parameter lists: (operation: (Int) -> Int?, on: Float), (operation: (Int) -> Int?, on: Int)
  return perform(operation: { counter() }, on: x)
         ^
@belkadan
Copy link
Contributor

cc @hborla, @xedin

@xedin
Copy link
Member

xedin commented Sep 8, 2019

Ah, this is really unfortunate. I just want to note for posterity that this is a solver issue related and not a diagnostic one - we should accept this code even though parameter is not used in the body of the closure. In order to do that, we need to delay type generation for closure expressions like that.

/cc @DougGregor

@belkadan
Copy link
Contributor

belkadan commented Sep 9, 2019

That would be a language change, even if it's a language change we're pretty sure we want to take. See SR-1528.

@xedin
Copy link
Member

xedin commented Sep 9, 2019

I agree that we'd have to go though evolution for this but I think it should probably be a warning instead of an error.

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

No branches or pull requests

3 participants