File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed
Sources/SwiftOperatorPrecedence
Tests/SwiftOperatorPrecedenceTest Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -80,7 +80,11 @@ extension OperatorPrecedence {
80
80
return " CastingPrecedence "
81
81
}
82
82
83
- // FIXME: Handle all of the language-defined precedence relationships.
83
+ // The arrow operator has fixed precedence.
84
+ if expr. is ( ArrowExprSyntax . self) {
85
+ return " FunctionArrowPrecedence "
86
+ }
87
+
84
88
return nil
85
89
}
86
90
@@ -155,6 +159,16 @@ extension OperatorPrecedence {
155
159
)
156
160
}
157
161
162
+ // An arrow expression (->).
163
+ if let arrowExpr = op. as ( ArrowExprSyntax . self) {
164
+ return ExprSyntax (
165
+ InfixOperatorExprSyntax (
166
+ leftOperand: lhs,
167
+ operatorOperand: ExprSyntax ( arrowExpr) ,
168
+ rightOperand: rhs)
169
+ )
170
+ }
171
+
158
172
// FIXME: Fallback that we should never need
159
173
fatalError ( " Unknown binary operator " )
160
174
}
Original file line number Diff line number Diff line change @@ -130,6 +130,14 @@ public class OperatorPrecedenceTests: XCTestCase {
130
130
try opPrecedence. assertExpectedFold ( " a as c == nil " , " ((a as c) == nil) " )
131
131
}
132
132
133
+ func testArrowExpr( ) throws {
134
+ let opPrecedence = OperatorPrecedence . standardOperators
135
+ try opPrecedence. assertExpectedFold (
136
+ " a = b -> c -> d " ,
137
+ " (a = (b -> (c -> d))) "
138
+ )
139
+ }
140
+
133
141
func testParsedLogicalExprs( ) throws {
134
142
let logicalOperatorSources =
135
143
"""
You can’t perform that action at this time.
0 commit comments