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-15293] Bad diagnostic for var + func overload with mismatched call #57615

Closed
hamishknight opened this issue Oct 7, 2021 · 2 comments · Fixed by #60240
Closed

[SR-15293] Bad diagnostic for var + func overload with mismatched call #57615

hamishknight opened this issue Oct 7, 2021 · 2 comments · Fixed by #60240
Assignees
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

@hamishknight
Copy link
Collaborator

Previous ID SR-15293
Radar None
Original Reporter @hamishknight
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI, TypeChecker
Assignee @hamishknight
Priority Medium

md5: ad00afc1090ec27f18670e5009c04bf1

Issue Description:

The following gives an unhelpful diagnostic:

func foo(x: Int, y: Int) {}
var foo: Any = 0
foo(0, x: 0) // error: Cannot call value of non-function type 'Any'

It would be better if we diagnosed the labeling mismatch.

@AnthonyLatsis
Copy link
Collaborator

AnthonyLatsis commented Sep 6, 2022

This issue still reproduces in a local scope. I discovered this when I tried to wrap the test case in a do block whilst migrating the test suite to GitHub issues:

/// https://github.com/apple/swift/issues/57615
/// Bad diagnostic for `var` + `func` overload with mismatched call
// FIXME: Diagnostic still bad in local scope.
func f_57615(x: Int, y: Int) {}
var f_57615: Any = 0
f_57615(0, x: 0) // expected-error {{incorrect argument labels in call (have '_:x:', expected 'x:y:')}}

@xedin Is this a standalone, perhaps known, issue, or rather an oversight?

@hamishknight
Copy link
Collaborator Author

@AnthonyLatsis That's a different issue, we do not currently do overloading between local variables and local functions. For example, even if the function call is correct it still fails to compile:

do {
  var foo = 0
  func foo() {}
  foo() // error: Cannot call value of non-function type 'Int'
}

We always prefer the variable in this case because of how we model scoping in the AST lookup scopes. I'm pretty sure we have a bug for this somewhere but I can't immediately find it.

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

Successfully merging a pull request may close this issue.

2 participants