I don’t agree with your assertions that this makes Swift “less safe” - if
anything the bug that this fixed was anything but. When performing a pattern
match, we expect the pattern to match the “shape” of the declaration itself.
If ‘()’ was not part of that declaration, then you have no reason to indicate
this as part of a pattern. Consider a slightly more extreme case that was
allowed before we fixed this bug (and, for compatibility reasons, is still
allowed in Swift 3 mode)
enum E {
case A, B, C, D
}
func testE(e: E) {
switch e {
case .A(let x): print(x)
default: break
}
}
Assuming this survives SILGen, which it often doesn’t, what do you feel a
reasonable value for “x” should be? Our compiler thinks (thought?) ‘Void’.
~Robert Widmann
> On Jul 28, 2017, at 2:23 PM, Amir Michail via swift-evolution
> <[email protected]> wrote:
>
> The latest beta doesn’t allow you to append “()” to an enum name with no
> associated value in a switch case.
>
> This makes Swift less safe because appending that “()” is an excellent way to
> indicate that you are not ignoring the associated value in the swift case
> because there isn’t any.
>
> Suppose that you later add an associated value. Then the switch case with the
> “()” will give a compile error, which is better than silently introducing a
> bug into your code.
>
> _______________________________________________
> swift-evolution mailing list
> [email protected]
> https://lists.swift.org/mailman/listinfo/swift-evolution
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution