We discussed this in today's core team meeting, and we decided that it's a bug fix. Swift's pattern syntax intentionally blurs the line between expressions and pattern forms, with the idea that the difference should not be something users normally have to think about. There's also already precedent for subtyping rules in the pattern grammar with existentials; for instance, this:
protocol P {}
enum A: P { case a, b, c }
enum B: P { case x, y, z }
let p: P = A.a
switch p {
case A.a: ...
case B.z: ...
default: ...
}
is accepted, and the A.a
pattern behaves like .a as A
, performing the type check and then the enum case check in succession. In order to maintain consistency of behavior between pure patterns and patterns interpreted as expressions, we agree that it makes sense for a subtyping rule to apply to patterns matched against Optional as well.