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-9738] Poor error message when calling @dynamicCallable with incorrect parameter types #52170

natecook1000 opened this issue Jan 23, 2019 · 4 comments


Copy link

@natecook1000 natecook1000 commented Jan 23, 2019

Previous ID SR-9738
Radar None
Original Reporter @natecook1000
Type Bug
Status Closed
Resolution Done

Toolchain: swift-5.0-DEVELOPMENT-SNAPSHOT-2018-12-28-a

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

md5: 93063d6e18bb5003b95809d72d784923

cloned to:

Issue Description:

If you call a dynamicCallable type as a function with the wrong type of parameters, it gives the message "Cannot call value of non-function type 'Foo'". The error message should be more akin to the message when you call a regular function with incorrect parameter types: "Cannot convert value of type 'String' to expected argument type 'Int'".

struct Foo {
  func dynamicallyCall(withArguments args: [Int]) -> Int {
    return args.count

let foo = Foo()
let c: Int = foo(1, 2, 3)     // ok
let d = foo("abc")            // Cannot call value of non-function type 'Foo'
// this error message is okay:
let e: String = foo(1, 2, 3)  // Cannot convert value of type 'Int' to specified type 'String'
Copy link

@belkadan belkadan commented Jan 24, 2019

Copy link

@dan-zheng dan-zheng commented Jan 24, 2019

This is a nice starter bug!

@dynamicCallable currently only has bare-bones diagnostics (see here). FailureDiagnosis::visitApplyExpr has a lot of machinery for producing good diagnostics for regular ApplyExprs though, one idea is to make use of that machinery for @dynamicCallable.

Copy link

@swift-ci swift-ci commented Jan 24, 2019

Comment by David Moore (JIRA)

Submitted a PR to improve this diagnostic: #22098.

Copy link

@swift-ci swift-ci commented Mar 8, 2020

Comment by Hassan ElDesouky (JIRA)

It has been fixed and Merged [here|#22098]

@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
None yet

No branches or pull requests

4 participants