[swift-dev] console error
clattner at apple.com
Sat Jan 9 13:17:43 CST 2016
> On Jan 9, 2016, at 2:21 AM, Greg Parker via swift-dev <swift-dev at swift.org> wrote:
> That's right. Swift's operators are whitespace-sensitive. The rules are:
> * Whitespace on both sides: infix operator
> * Whitespace on neither side: infix operator
> * Whitespace on only one side: prefix or postfix operator
> Therefore the expression `i =3` uses prefix operator = . There is no such operator, and it's reserved so you can't write your own.
> `i = 3` and `i=3` and `i = 3` are both the ordinary infix operator = .
> Obligatory open-source opportunity: add a compiler fix-it for this. (Perhaps just the prefix/postfix = case specifically, perhaps the more general case where the requested operator does not exist but an operator with different fixity does.)
Swift 2.2 produces a better error message for this:
error: '=' must have consistent whitespace on both sides
var i =3
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-dev