Skip to content

Commit f1fc2eb

Browse files
committed
Make etaExpandWithAsf more self-contained
1 parent 66722b9 commit f1fc2eb

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
@@ -322,19 +322,23 @@ class TypeApplications(val self: Type) extends AnyVal {
322322

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

339343
/** Maps [Ts] => C[Ts] to C */
340344
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
@@ -1200,7 +1200,7 @@ class Namer { typer: Typer =>
12001200
val forwarderName = checkNoConflict(alias.toTypeName, isPrivate = false, span)
12011201
var target = pathType.select(sym)
12021202
if target.typeParams.nonEmpty then
1203-
target = target.etaExpandWithAsf(pathType, sym.owner)
1203+
target = target.etaExpandWithAsf
12041204
newSymbol(
12051205
cls, forwarderName,
12061206
MandatoryExportTypeFlags | (sym.flags & RetainedExportTypeFlags),

0 commit comments

Comments
 (0)