[swift-users] RawRepresentable bug or intended?
Jordan Rose
jordan_rose at apple.com
Thu Sep 29 12:19:36 CDT 2016
> On Sep 28, 2016, at 23:00, Adrian Zubarev via swift-users <swift-users at swift.org> wrote:
>
> struct B : RawRepresentable {
>
> let rawValue: Int
>
> // init?(rawValue: Int) {
> //
> // self.rawValue = rawValue
> // }
>
> static let c: B = B(rawValue: 0)
> static let d: B = B(rawValue: 1)
> }
> It seems to me that the memberwise initializer init(rawValue: Int) ignores the failable initializer init?(rawValue: Int) from RawRepresentable and is even able to satisfy RawRepresentable in that case.
>
Yep, that's correct. A non-failable initializer is considered a valid subtype of a failable initializer, in that you can always provide the former where the latter is expected. The compiler doesn't handle all forms of subtyping when it does protocol conformance checks (and there are bugs on this), but it does handle this one.
Jordan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160929/8559684e/attachment.html>
More information about the swift-users
mailing list