@@ -8,7 +8,9 @@ import Decorators._
8
8
import util .Stats ._
9
9
import util .common ._
10
10
import Names ._
11
+ import NameOps ._
11
12
import Flags ._
13
+ import StdNames .tpnme
12
14
import util .Positions .Position
13
15
import config .Printers ._
14
16
import collection .mutable
@@ -108,6 +110,41 @@ class TypeApplications(val self: Type) extends AnyVal {
108
110
def uninstantiatedTypeParams (implicit ctx : Context ): List [TypeSymbol ] =
109
111
typeParams filter (tparam => self.member(tparam.name).symbol == tparam)
110
112
113
+ /** If type `tp` is equal, aliased-to, or upperbounded-by a type of the form
114
+ * `LambdaXYZ { ... }`, the class symbol of that type, otherwise NoSymbol.
115
+ * @param forcing if set, might force completion. If not, never forces
116
+ * but returns NoSymbol when it would have to otherwise.
117
+ */
118
+ def LambdaClass (forcing : Boolean )(implicit ctx : Context ): Symbol = ctx.traceIndented(i " LambdaClass( $self) " , hk) { self.stripTypeVar match {
119
+ case self : TypeRef =>
120
+ val sym = self.symbol
121
+ if (sym.isLambdaTrait) sym
122
+ else if (sym.isClass || sym.isCompleting && ! forcing) NoSymbol
123
+ else self.info.LambdaClass (forcing)
124
+ case self : TermRef =>
125
+ NoSymbol
126
+ case self : TypeProxy =>
127
+ self.underlying.LambdaClass (forcing)
128
+ case _ =>
129
+ NoSymbol
130
+ }}
131
+
132
+ /** Is type `tp` equal, aliased-to, or upperbounded-by a type of the form
133
+ * `LambdaXYZ { ... }`?
134
+ */
135
+ def isLambda (implicit ctx : Context ): Boolean =
136
+ LambdaClass (forcing = true ).exists
137
+
138
+ /** Same is `isLambda`, except that symbol denotations are not forced
139
+ * Symbols in completion count as not lambdas.
140
+ */
141
+ def isSafeLambda (implicit ctx : Context ): Boolean =
142
+ LambdaClass (forcing = false ).exists
143
+
144
+ /** Is type `tp` a Lambda with all Arg$ fields fully instantiated? */
145
+ def isInstantiatedLambda (tp : Type )(implicit ctx : Context ): Boolean =
146
+ tp.isSafeLambda && tp.typeParams.forall(_.name == tpnme.Apply )
147
+
111
148
/** Encode the type resulting from applying this type to given arguments */
112
149
final def appliedTo (args : List [Type ])(implicit ctx : Context ): Type = /* >|>*/ track(" appliedTo" ) /* <|<*/ {
113
150
0 commit comments