Skip to content

Commit 6428333

Browse files
committed
Make etaExpandWithAsf more self-contained
1 parent b0f9e16 commit 6428333

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

compiler/src/dotty/tools/dotc/core/TypeApplications.scala

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -323,19 +323,23 @@ class TypeApplications(val self: Type) extends AnyVal {
323323

324324
// Like `target.etaExpand(target.typeParams)`
325325
// except call `asSeenFrom` to fix class type parameter bounds
326-
// e.g. in pos/i18569:
327-
// given prefix `M2.type` and symbol `trait F`
328-
// the result of `prefix.select(sym)` is `M2.F`
329-
// however F's type parameter T is `<: M1#A` rather than `<: M2.A`
330-
// so add a call to `asSeenFrom` with prefix `M2.type` and owner `trait M1`
331-
def etaExpandWithAsf(prefix: Type, owner: Symbol)(using Context): Type =
332-
val tparams = self.typeParams
333-
HKTypeLambda(tparams.map(_.paramName))(
334-
tl => tparams.map {
335-
case p: Symbol => HKTypeLambda.toPInfo(tl.integrate(tparams, p.info.asSeenFrom(prefix, owner)))
336-
case p => HKTypeLambda.toPInfo(tl.integrate(tparams, p.paramInfo))
337-
},
338-
tl => tl.integrate(tparams, self.appliedTo(tparams.map(_.paramRef))))
326+
// e.g. from pos/i18569:
327+
// trait M1:
328+
// trait A
329+
// trait F[T <: A]
330+
// object M2 extends M1
331+
// Type parameter T in M2.F has an upper bound of M1#A instead of M2.A
332+
// So we take the prefix M2.type and the F symbol's owner, M1,
333+
// to call asSeenFrom on T's info.
334+
def etaExpandWithAsf(using Context): Type = self match
335+
case self: TypeRef if self.symbol.isClass =>
336+
val tparams = self.symbol.typeParams
337+
val prefix = self.prefix
338+
val owner = self.symbol.owner
339+
HKTypeLambda(tparams.map(_.paramName))(
340+
tl => tparams.map(p => HKTypeLambda.toPInfo(tl.integrate(tparams, p.info.asSeenFrom(prefix, owner)))),
341+
tl => tl.integrate(tparams, self.appliedTo(tparams.map(_.paramRef))))
342+
case _ => etaExpand(typeParams)
339343

340344
/** Maps [Ts] => C[Ts] to C */
341345
def etaCollapse(using Context): Type = self match

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1197,7 +1197,7 @@ class Namer { typer: Typer =>
11971197
val forwarderName = checkNoConflict(alias.toTypeName, isPrivate = false, span)
11981198
var target = pathType.select(sym)
11991199
if target.typeParams.nonEmpty then
1200-
target = target.etaExpandWithAsf(pathType, sym.owner)
1200+
target = target.etaExpandWithAsf
12011201
newSymbol(
12021202
cls, forwarderName,
12031203
Exported | Final,

0 commit comments

Comments
 (0)