File tree 1 file changed +40
-1
lines changed
compiler/src/dotty/tools/dotc/transform
1 file changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -56,8 +56,47 @@ class ExpandSAMs extends MiniPhase {
56
56
tree
57
57
}
58
58
59
+ /** A partial function literal:
60
+ *
61
+ * ```
62
+ * val x: PartialFunction[A, B] = { case C1 => E1; ...; case Cn => En }
63
+ * ```
64
+ *
65
+ * which desugars to:
66
+ *
67
+ * ```
68
+ * val x: PartialFunction[A, B] = {
69
+ * def $anonfun(x: A): B = x match { case C1 => E1; ...; case Cn => En }
70
+ * closure($anonfun: PartialFunction[A, B])
71
+ * }
72
+ * ```
73
+ *
74
+ * is expanded to an anomymous class:
75
+ *
76
+ * ```
77
+ * val x: PartialFunction[A, B] = {
78
+ * class $anon extends AbstractPartialFunction[A, B] {
79
+ * final def isDefinedAt(x: A): Boolean = x match {
80
+ * case C1 => true
81
+ * ...
82
+ * case Cn => true
83
+ * case _ => false
84
+ * }
85
+ *
86
+ * final def applyOrElse[A1 <: A, B1 >: B](x: A1, default: A1 => B1): B1 = x match {
87
+ * case C1 => E1
88
+ * ...
89
+ * case Cn => En
90
+ * case _ => default(x)
91
+ * }
92
+ * }
93
+ *
94
+ * new $anon
95
+ * }
96
+ * ```
97
+ */
59
98
private def toPartialFunction (tree : Block , tpe : Type )(implicit ctx : Context ): Tree = {
60
- // / ** An extractor for match, either contained in a block or standalone. */
99
+ /** An extractor for match, either contained in a block or standalone. */
61
100
object PartialFunctionRHS {
62
101
def unapply (tree : Tree ): Option [Match ] = tree match {
63
102
case Block (Nil , expr) => unapply(expr)
You can’t perform that action at this time.
0 commit comments