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