Skip to content

Commit 8b0259f

Browse files
author
Adriaan Moors
committed
update docs for (partial) fun synth in uncurry
1 parent 314133f commit 8b0259f

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

src/compiler/scala/tools/nsc/transform/UnCurry.scala

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -225,38 +225,15 @@ abstract class UnCurry extends InfoTransform
225225
}
226226

227227

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
229229
*
230230
* class $anon() extends AbstractFunctionN[T_1, .., T_N, R] with Serializable {
231231
* def apply(x_1: T_1, ..., x_N: T_n): R = body
232232
* }
233233
* new $anon()
234234
*
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).
238236
*
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
260237
*/
261238
def transformFunction(fun: Function): Tree =
262239
deEta(fun) match {
@@ -300,6 +277,28 @@ abstract class UnCurry extends InfoTransform
300277

301278
}
302279

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+
*/
303302
def synthPartialFunction(fun: Function) = {
304303
if (!settings.XoldPatmat.value) debugwarn("Under the new pattern matching scheme, PartialFunction should have been synthesized during typers.")
305304

0 commit comments

Comments
 (0)