I see a little confusing thing:
-5.9.rounded(.down) // -5
(-5.9).rounded(.down) // -6
It seems that -5.9.rounded(.down) is treated as -(5.9.rounded(.down)).
Is it expected?
Yes, but in opinion it is not expected and natural. Is there any robust arguments for such rules? Should I report a bug at Issues · apple/swift · GitHub? @xwu
scanon
(Steve Canon)
4
This is how ~every roughly similar language’s grammar works, FWIW. It might have been interesting to do it otherwise in Swift 1, but it would have been swimming against the weight of precedent from other languages then, and would be source-breaking today.
Requiring parentheses to disambiguate prefix/postfix expressions would be interesting to explore.
2 Likes
Saying ''Requiring parentheses to disambiguate prefix/postfix expressions" you mean a warning, requiring to write either -(5.9.rounded(.down)) or (-5.9).rounded(.down) ?
scanon
(Steve Canon)
6
An error rather than a warning, but yes.