@@ -38,7 +38,7 @@ object TypeApplications {
38
38
* contain the bounds of the type parameters of `C`. This is necessary to be able to
39
39
* contract the hk lambda to `C`.
40
40
*/
41
- private def weakerBounds (tp : HKTypeLambda , tparams : List [ ParamInfo ] )(using Context ): Boolean =
41
+ private def weakerBounds (tp : HKTypeLambda , fn : Type )(using Context ): Boolean =
42
42
val onlyEmptyBounds = tp.typeParams.forall(_.paramInfo == TypeBounds .empty)
43
43
onlyEmptyBounds
44
44
// Note: this pre-test helps efficiency. It is also necessary to workaround #9965 since in some cases
@@ -47,18 +47,21 @@ object TypeApplications {
47
47
// In this case, we can still return true if we know that the hk lambda bounds
48
48
// are empty anyway.
49
49
|| {
50
+ val tparams = fn.typeParams
50
51
val paramRefs = tparams.map(_.paramRef)
52
+ val prefix = fn match { case fn : TypeRef => fn.prefix case _ => NoPrefix }
53
+ val owner = fn match { case fn : TypeRef => fn.symbol.owner case _ => NoSymbol }
51
54
tp.typeParams.corresponds(tparams) { (param1, param2) =>
52
- param2.paramInfo frozen_<:< param1.paramInfo.substParams(tp, paramRefs)
55
+ param2.paramInfo.asSeenFrom(prefix, owner) frozen_<:< param1.paramInfo.substParams(tp, paramRefs)
53
56
}
54
57
}
55
58
56
59
def unapply (tp : Type )(using Context ): Option [Type ] = tp match
57
- case tp @ HKTypeLambda (tparams, AppliedType (fn : Type , args))
60
+ case tp @ HKTypeLambda (tparams, AppliedType (fn, args))
58
61
if fn.typeSymbol.isClass
59
62
&& tparams.hasSameLengthAs(args)
60
63
&& args.lazyZip(tparams).forall((arg, tparam) => arg == tparam.paramRef)
61
- && weakerBounds(tp, fn.typeParams ) => Some (fn)
64
+ && weakerBounds(tp, fn) => Some (fn)
62
65
case _ => None
63
66
64
67
end EtaExpansion
@@ -303,7 +306,6 @@ class TypeApplications(val self: Type) extends AnyVal {
303
306
val resType = self.appliedTo(tparams.map(_.paramRef))
304
307
self match
305
308
case self : TypeRef if tparams.nonEmpty && self.symbol.isClass =>
306
- val prefix = self.prefix
307
309
val owner = self.symbol.owner
308
310
// Calling asSeenFrom on the type parameter infos is important
309
311
// so that class type references within another prefix have
@@ -318,7 +320,7 @@ class TypeApplications(val self: Type) extends AnyVal {
318
320
// So we take the prefix M2.type and the F symbol's owner, M1,
319
321
// to call asSeenFrom on T's info.
320
322
HKTypeLambda (tparams.map(_.paramName))(
321
- tl => tparams.map(p => HKTypeLambda .toPInfo(tl.integrate(tparams, p.paramInfo.asSeenFrom(prefix, owner)))),
323
+ tl => tparams.map(p => HKTypeLambda .toPInfo(tl.integrate(tparams, p.paramInfo.asSeenFrom(self. prefix, owner)))),
322
324
tl => tl.integrate(tparams, resType))
323
325
case _ =>
324
326
HKTypeLambda .fromParams(tparams, resType)
0 commit comments