On Sun, Jun 12 2016 at 02:01:17 AM, Andrey Fidrya via swift-evolution 
<swift-evolution@swift.org> wrote:
> Nil coalescing operator has very low precedence and it's very easy to forget 
> the parentheses.
> It's tempting to write something like this:
>
> let result = v1 ?? 0 + v2 ?? 0
>
> Which will resolve to
>
> let result = v1 ?? (0 + v2 ?? 0)

This is how I would expected the operator to work.

> This seems to be a source of errors in other languages as well, for example:
> http://www.codeproject.com/Tips/721145/Beware-The-null-coalescing-operator-is-low-in-the
>
> I propose to consider raising it's precedence or requiring parentheses if ?? 
> is used with multiple statements.

I like the idea of requiring parenthesis (or at least having a warning)
on ambiguous lines with two `??`.

--
Roth

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to