/ swift Public
[SR-7131] You cannot assign an operator without parens the way you can use an operator in map #49679
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
The Swift compiler in itself
Bug: Diagnostics Quality of Implementation
Area → compiler: The legacy C++ parser
Additional Detail from JIRA
This is legal:
let (x, y) = ("Hello.", "There.")
This is not:
public typealias Fooquatable = (Foo, Foo) -> Bool
let c: Fooquatable = == // unary operator cannot be separated from its operand
To compile you must surround the == with parens
let c: Fooquatable = (==)
The fixit is inappropriate (it just deletes the new line and any trailing comment), and the reason appears to be the way assignment tokens expect unary operators to operate, even though this is an infix operator:
if (OperEndLoc == Tok.getLoc())
It is not overly burdensome to use parens, but it should be made clear that this is the necessary use, not just in direct assignment but when creating collections of operators, for example:
let j: [Fooquatable] = [<=, ==, >=] // expected expression after unary operator
whereas parenthesizing each operator works properly.
I'd also like to see documentation that explains that operator implementations are sugar and are not static members. They do not appear in a mirror reflecting SomeType.self.
The text was updated successfully, but these errors were encountered: