Looking at the new (Swift 5) @dynamicCallable feature, I was a bit surprised by this:
@dynamicCallable
struct Foo {
var x: Int
init() { self.x = 0 }
mutating func dynamicallyCall(withArguments args: [Int]) {
x += args.reduce(0, +)
print(x)
}
}
func test() {
var foo = Foo()
foo.dynamicallyCall(withArguments: [1, 2, 3]) // prints 6
foo(1, 2, 3) // ERROR: Cannot call value of non-function type 'Foo'
}
test()
The error says that Foo
is a non-function type, but if so I would expect an error at the definition of Foo
.
Is my mutating func intended to be accepted as a valid dynamicallyCall(withArguments:)
func or not?