Uploaded image for project: 'Swift'
  1. Swift
  2. SR-9738

Poor error message when calling @dynamicCallable with incorrect parameter types

    XMLWordPrintable

    Details

      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'".

      @dynamicCallable
      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'

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            nnnnnnnn Nate Cook
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: