In the following snippet, I expect to be able to discard the return value after invoking bar, but the compiler even allows me to discard a reference to the function, which makes no sense to me.
@discardableResult func baz() -> Int {
return 0
}
class Foo {
@discardableResult func bar() -> Int {
return 0
}
func test() {
self.bar()
self.bar // I'd expect an error here
baz()
baz // I do get an error here as expected
}
}
This is also inconsistent with non-method functions: for the free function baz, the compiler generates an error: