@@ -225,38 +225,15 @@ abstract class UnCurry extends InfoTransform
225
225
}
226
226
227
227
228
- /* Transform a function node (x_1,...,x_n) => body of type FunctionN[T_1, .., T_N, R] to
228
+ /** Transform a function node (x_1,...,x_n) => body of type FunctionN[T_1, .., T_N, R] to
229
229
*
230
230
* class $anon() extends AbstractFunctionN[T_1, .., T_N, R] with Serializable {
231
231
* def apply(x_1: T_1, ..., x_N: T_n): R = body
232
232
* }
233
233
* new $anon()
234
234
*
235
- * transform a function node (x => body) of type PartialFunction[T, R] where
236
- * body = expr match { case P_i if G_i => E_i }_i=1..n
237
- * to:
235
+ * If `settings.XoldPatmat.value`, also synthesized AbstractPartialFunction subclasses (see synthPartialFunction).
238
236
*
239
- //TODO: correct code template below
240
- * class $anon() extends AbstractPartialFunction[T, R] with Serializable {
241
- * def applyOrElse[A1 <: A, B1 >: B](x: A1, default: A1 => B1): B1 = (expr: @unchecked) match {
242
- * case P_1 if G_1 => E_1
243
- * ...
244
- * case P_n if G_n => E_n
245
- * case _ => default(expr)
246
- * }
247
- * def isDefinedAt(x: T): boolean = (x: @unchecked) match {
248
- * case P_1 if G_1 => true
249
- * ...
250
- * case P_n if G_n => true
251
- * case _ => false
252
- * }
253
- * }
254
- * new $anon()
255
- *
256
- * However, if one of the patterns P_i if G_i is a default pattern,
257
- * drop the last default clause in the definition of `apply` and generate for `_isDefinedAt` instead
258
- *
259
- * def isDefinedAtCurrent(x: T): boolean = true
260
237
*/
261
238
def transformFunction (fun : Function ): Tree =
262
239
deEta(fun) match {
@@ -300,6 +277,28 @@ abstract class UnCurry extends InfoTransform
300
277
301
278
}
302
279
280
+ /** Transform a function node (x => body) of type PartialFunction[T, R] where
281
+ * body = expr match { case P_i if G_i => E_i }_i=1..n
282
+ * to (assuming none of the cases is a default case):
283
+ *
284
+ * class $anon() extends AbstractPartialFunction[T, R] with Serializable {
285
+ * def applyOrElse[A1 <: A, B1 >: B](x: A1, default: A1 => B1): B1 = (expr: @unchecked) match {
286
+ * case P_1 if G_1 => E_1
287
+ * ...
288
+ * case P_n if G_n => E_n
289
+ * case _ => default(expr)
290
+ * }
291
+ * def isDefinedAt(x: T): boolean = (x: @unchecked) match {
292
+ * case P_1 if G_1 => true
293
+ * ...
294
+ * case P_n if G_n => true
295
+ * case _ => false
296
+ * }
297
+ * }
298
+ * new $anon()
299
+ *
300
+ * If there's a default case, the original match is used for applyOrElse, and isDefinedAt returns `true`
301
+ */
303
302
def synthPartialFunction (fun : Function ) = {
304
303
if (! settings.XoldPatmat .value) debugwarn(" Under the new pattern matching scheme, PartialFunction should have been synthesized during typers." )
305
304
0 commit comments