[swift-evolution] Recent change makes Swift 4 less safe.

Robert Widmann rwidmann at apple.com
Mon Jul 31 12:17:59 CDT 2017


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 <swift-evolution at swift.org> 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
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

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


More information about the swift-evolution mailing list