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-11378] Improve func callAsFunction diagnostics #53779

Closed
dan-zheng opened this issue Aug 27, 2019 · 1 comment
Closed

[SR-11378] Improve func callAsFunction diagnostics #53779

dan-zheng opened this issue Aug 27, 2019 · 1 comment
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

@dan-zheng
Copy link
Collaborator

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

md5: e0a97d278a6a15779fcdb86aed9abd58

Issue Description:

Callable values of user-defined nominal types was introduced in SE-0253 (implementation PR).
Methods named func callAsFunction act as call-syntax delegate methods.

Ideally, the diagnostics for sugared calls should exactly match the diagnostics for direct calls to callAsFunction, but this requires more work.

Examples

These examples are documented in test/Sema/call_as_function_simple.swift.

"Cannot use mutating member on immutable value."

struct Mutating {
  var x: Int
  mutating func callAsFunction() {
    x += 1
  }
}
func testMutating(_ x: Mutating, _ y: inout Mutating) {
  _ = x() // TODO: Improve diagnostic.
  _ = x.callAsFunction()
}
callable-diagnostics.swift:8:8: error: cannot call value of non-function type 'Mutating'
  _ = x() // TODO: Improve diagnostic.
      ~^~

callable-diagnostics.swift:8:7: error: cannot invoke 'x' with no arguments
  _ = x() // TODO: Improve diagnostic.
      ^
callable-diagnostics.swift:9:9: error: cannot use mutating member on immutable value: 'x' is a 'let' constant
  _ = x.callAsFunction()
      ~ ^

"Extra argument in call."

struct SimpleCallable {
  func callAsFunction(_ x: Float) -> Float {
    return x
  }
}

let foo = SimpleCallable()
_ = foo(1, 1) // TODO: Improve diagnostics.
_ = foo.callAsFunction(1, 1)
callable-diagnostics.swift:8:8: error: cannot call value of non-function type 'SimpleCallable'
_ = foo(1, 1) // TODO: Improve diagnostics.
    ~~~^
callable-diagnostics.swift:8:5: error: cannot invoke 'foo' with an argument list of type '(Int, Int)'
_ = foo(1, 1) // TODO: Improve diagnostics.
    ^
callable-diagnostics.swift:9:27: error: extra argument in call
_ = foo.callAsFunction(1, 1)
                          ^
@xedin
Copy link
Member

xedin commented Dec 10, 2019

Diagnostics are improved by #28630

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

No branches or pull requests

2 participants