[swift-evolution] [Idea] Remove optional pattern binding

Jacob Bandes-Storch jtbandes at gmail.com
Sun May 1 13:57:06 CDT 2016


Generally I'm in favor of something like this.

But if "case" is removed, doesn't that introduce an ambiguity? In an
admittedly contrived pathological case, you could have an "=" operator
which returns a Bool; then "if .someCase = myvar" would be ambiguous.

Jacob

On Sun, May 1, 2016 at 1:12 AM, Антон Жилин <swift-evolution at swift.org>
wrote:

> Generally, pattern binding in `if` looks like this:
>
> if case *pattern* = *expression* { ... }
>
> Pattern binding for optionals is currently usable as both of:
>
> if case let .some(x) = y { ... }
> if case let x? = y { ... }
>
> Now, there is also an older optional-specific hack:
>
> if let x = y { ... }
>
> In terms of pattern binding, it should always be true, and it's illogical
> inside `if`.
>
> I suggest:
> 1) Remove optional pattern binding
> 2) Remove `case` in `if` pattern binding
>
> Really, `case` should be an attribute of `switch`, not `if`.
>
> Pattern binding for optionals will look like:
>
> if let x? = y { ... }
>
> It will become more explicit and consistent with the rest of the language.
>
> We need to hurry until Swift 3 lands!
>
> - Anton
>
> _______________________________________________
> 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/20160501/8b967d56/attachment.html>


More information about the swift-evolution mailing list