summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/transform/UnCurry.scala
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@epfl.ch>2012-07-20 14:46:01 +0200
committerAdriaan Moors <adriaan.moors@epfl.ch>2012-07-20 14:46:01 +0200
commit8b0259f8f4f2773560efa985142eaf167f597a24 (patch)
tree7758adea55957fab3c59f2fbc7ca531cd96b55e5 /src/compiler/scala/tools/nsc/transform/UnCurry.scala
parent314133f98118d6d2f9f515fcc5aa7a2e7e9a4559 (diff)
downloadscala-8b0259f8f4f2773560efa985142eaf167f597a24.tar.gz
scala-8b0259f8f4f2773560efa985142eaf167f597a24.tar.bz2
scala-8b0259f8f4f2773560efa985142eaf167f597a24.zip
update docs for (partial) fun synth in uncurry
Diffstat (limited to 'src/compiler/scala/tools/nsc/transform/UnCurry.scala')
-rw-r--r--src/compiler/scala/tools/nsc/transform/UnCurry.scala49
1 files changed, 24 insertions, 25 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/UnCurry.scala b/src/compiler/scala/tools/nsc/transform/UnCurry.scala
index efc3d25ed0..2983c65e78 100644
--- a/src/compiler/scala/tools/nsc/transform/UnCurry.scala
+++ b/src/compiler/scala/tools/nsc/transform/UnCurry.scala
@@ -225,38 +225,15 @@ abstract class UnCurry extends InfoTransform
}
- /* Transform a function node (x_1,...,x_n) => body of type FunctionN[T_1, .., T_N, R] to
+ /** Transform a function node (x_1,...,x_n) => body of type FunctionN[T_1, .., T_N, R] to
*
* class $anon() extends AbstractFunctionN[T_1, .., T_N, R] with Serializable {
* def apply(x_1: T_1, ..., x_N: T_n): R = body
* }
* new $anon()
*
- * transform a function node (x => body) of type PartialFunction[T, R] where
- * body = expr match { case P_i if G_i => E_i }_i=1..n
- * to:
+ * If `settings.XoldPatmat.value`, also synthesized AbstractPartialFunction subclasses (see synthPartialFunction).
*
- //TODO: correct code template below
- * class $anon() extends AbstractPartialFunction[T, R] with Serializable {
- * def applyOrElse[A1 <: A, B1 >: B](x: A1, default: A1 => B1): B1 = (expr: @unchecked) match {
- * case P_1 if G_1 => E_1
- * ...
- * case P_n if G_n => E_n
- * case _ => default(expr)
- * }
- * def isDefinedAt(x: T): boolean = (x: @unchecked) match {
- * case P_1 if G_1 => true
- * ...
- * case P_n if G_n => true
- * case _ => false
- * }
- * }
- * new $anon()
- *
- * However, if one of the patterns P_i if G_i is a default pattern,
- * drop the last default clause in the definition of `apply` and generate for `_isDefinedAt` instead
- *
- * def isDefinedAtCurrent(x: T): boolean = true
*/
def transformFunction(fun: Function): Tree =
deEta(fun) match {
@@ -300,6 +277,28 @@ abstract class UnCurry extends InfoTransform
}
+ /** Transform a function node (x => body) of type PartialFunction[T, R] where
+ * body = expr match { case P_i if G_i => E_i }_i=1..n
+ * to (assuming none of the cases is a default case):
+ *
+ * class $anon() extends AbstractPartialFunction[T, R] with Serializable {
+ * def applyOrElse[A1 <: A, B1 >: B](x: A1, default: A1 => B1): B1 = (expr: @unchecked) match {
+ * case P_1 if G_1 => E_1
+ * ...
+ * case P_n if G_n => E_n
+ * case _ => default(expr)
+ * }
+ * def isDefinedAt(x: T): boolean = (x: @unchecked) match {
+ * case P_1 if G_1 => true
+ * ...
+ * case P_n if G_n => true
+ * case _ => false
+ * }
+ * }
+ * new $anon()
+ *
+ * If there's a default case, the original match is used for applyOrElse, and isDefinedAt returns `true`
+ */
def synthPartialFunction(fun: Function) = {
if (!settings.XoldPatmat.value) debugwarn("Under the new pattern matching scheme, PartialFunction should have been synthesized during typers.")