[swift-evolution] /*Let it be*/ func() -> @discardable Bool {} /*Rather Than*/ @discardableResult func() -> Bool {}

Mike Kluev mike.kluev at gmail.com
Thu Oct 19 01:02:15 CDT 2017


On 19 October 2017 at 05:04, Xiaodi Wu <xiaodi.wu at gmail.com> wrote:

>
> d) Does a class that override a `@discardable` type inherit that
> annotation? If not, they it's kind of a weird exception to the inheritance
> thing, no? If so, then we'd need a @nondiscardable annotation to do
> type-level overrides of @discardable.
>
>
the very current form of @discardableResult as a function attribute leads
to these type of questions in the first place. if it was a type modifier -
there would be no doubt:

class A {
    func foo() -> Bool {
        ...
    }

    func bar() -> discardable Bool {
        ...
    }
}

class B: A {
    override func foo() -> discardable Bool { // ok, types compatible
       ...
    }

    override func bar() -> Bool { // error. types mismatch
        ...
    }
}

Mike
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20171019/b0a54233/attachment.html>


More information about the swift-evolution mailing list