@@ -36,7 +36,7 @@ object TypeApplications {
36
36
37
37
def apply (tycon : Type )(using Context ): Type =
38
38
assert(tycon.typeParams.nonEmpty, tycon)
39
- tycon.EtaExpand (tycon.typeParamSymbols)
39
+ tycon.etaExpand (tycon.typeParamSymbols)
40
40
41
41
/** Test that the parameter bounds in a hk type lambda `[X1,...,Xn] => C[X1, ..., Xn]`
42
42
* contain the bounds of the type parameters of `C`. This is necessary to be able to
@@ -71,7 +71,7 @@ object TypeApplications {
71
71
*/
72
72
def EtaExpandIfHK (tparams : List [TypeParamInfo ], args : List [Type ])(using Context ): List [Type ] =
73
73
if (tparams.isEmpty) args
74
- else args.zipWithConserve(tparams)((arg, tparam) => arg.EtaExpandIfHK (tparam.paramInfoOrCompleter))
74
+ else args.zipWithConserve(tparams)((arg, tparam) => arg.etaExpandIfHK (tparam.paramInfoOrCompleter))
75
75
76
76
/** A type map that tries to reduce (part of) the result type of the type lambda `tycon`
77
77
* with the given `args`(some of which are wildcard arguments represented by type bounds).
@@ -245,7 +245,7 @@ class TypeApplications(val self: Type) extends AnyVal {
245
245
def topType (using Context ): Type =
246
246
if self.hasSimpleKind then
247
247
defn.AnyType
248
- else EtaExpand (self.typeParams) match
248
+ else etaExpand (self.typeParams) match
249
249
case tp : HKTypeLambda =>
250
250
tp.derivedLambdaType(resType = tp.resultType.topType)
251
251
case _ =>
@@ -302,7 +302,7 @@ class TypeApplications(val self: Type) extends AnyVal {
302
302
/** Convert a type constructor `TC` which has type parameters `X1, ..., Xn`
303
303
* to `[X1, ..., Xn] -> TC[X1, ..., Xn]`.
304
304
*/
305
- def EtaExpand (tparams : List [TypeParamInfo ])(using Context ): Type =
305
+ def etaExpand (tparams : List [TypeParamInfo ])(using Context ): Type =
306
306
HKTypeLambda .fromParams(tparams, self.appliedTo(tparams.map(_.paramRef)))
307
307
// .ensuring(res => res.EtaReduce =:= self, s"res = $res, core = ${res.EtaReduce}, self = $self, hc = ${res.hashCode}")
308
308
@@ -311,7 +311,7 @@ class TypeApplications(val self: Type) extends AnyVal {
311
311
if (isLambdaSub) self else EtaExpansion (self)
312
312
313
313
/** Eta expand if `self` is a (non-lambda) class reference and `bound` is a higher-kinded type */
314
- def EtaExpandIfHK (bound : Type )(using Context ): Type = {
314
+ def etaExpandIfHK (bound : Type )(using Context ): Type = {
315
315
val hkParams = bound.hkTypeParams
316
316
if (hkParams.isEmpty) self
317
317
else self match {
@@ -321,6 +321,22 @@ class TypeApplications(val self: Type) extends AnyVal {
321
321
}
322
322
}
323
323
324
+ /** Maps [Ts] => C[Ts] to C */
325
+ def etaCollapse (using Context ): Type = self match
326
+ case EtaExpansion (classType) => classType
327
+ case _ => self
328
+
329
+ /** Like dealias, except for
330
+ * type A[X] = C[X]
331
+ * where `A` is expanded to `C`. Dealias would expand `A to [X] =>> C[X]`
332
+ */
333
+ def dealiasAcrossEtaExpansions (using Context ): Type = self match
334
+ case self : TypeRef =>
335
+ self.info match
336
+ case TypeAlias (EtaExpansion (alias)) => alias
337
+ case _ => self
338
+ case _ => self
339
+
324
340
/** The type representing
325
341
*
326
342
* T[U1, ..., Un]
0 commit comments