[swift-evolution] [Last second] Precedence of nil-coalescing operator seems too low

Erica Sadun erica at ericasadun.com
Sun Sep 4 00:20:19 CDT 2016


> On Sep 3, 2016, at 10:15 PM, Jacob Bandes-Storch <jtbandes at gmail.com> wrote:
> 
> Perhaps-conversely, what should this code do?
> 
>     let nextIndex = foundIndex ?? lastIndex + 1
> 
> Jacob

It's a good counter example. And there's no optional-associative option.

-- E

> 
> On Sat, Sep 3, 2016 at 9:05 PM, Erica Sadun via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
> Given: `let x = Optional(3)` then
> `let y = 5 + x ?? 2` will not compile
> but 
> `let y = 5 + (x ?? 2)` will.
> 
> Should NilCoalescingPrecedence be raised? The current operator precedence chain is:
> 
> BitwiseShiftPrecedence > MultiplicationPrecedence > AdditionPrecedence > RangeFormationPrecedence > CastingPrecedence > NilCoalescingPrecedence > ComparisonPrecedence > LogicalConjunctionPrecedence > LogicalDisjunctionPrecedence > TernaryPrecedence > AssignmentPrecedence > FunctionArrowPrecedence > [nothing]
> 
> It seems to me that `NilCoalescingPrecedence` should probably be higher than `MultiplicationPrecedence` and possibly higher `BitwiseShiftPrecedence` as its job is to produce an unwrapped value that can then be operated upon.
> 
> I think CastingPrecedence should be even higher because
> `expression as? T ?? fallback value`
> should be parsed as
> `(expression as? T) ?? (fallback value)`
> 
> I apologize profusely because I know this is beyond last minute,
> 
> -- E
> 
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
> 
> 

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


More information about the swift-evolution mailing list