Skip to content

Commit

Permalink
Move implementation into TypeApplications etaExpandWithAsf
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Nov 13, 2023
1 parent f7bf982 commit b0f9e16
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
16 changes: 16 additions & 0 deletions compiler/src/dotty/tools/dotc/core/TypeApplications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,22 @@ class TypeApplications(val self: Type) extends AnyVal {
}
}

// Like `target.etaExpand(target.typeParams)`
// except call `asSeenFrom` to fix class type parameter bounds
// e.g. in pos/i18569:
// given prefix `M2.type` and symbol `trait F`
// the result of `prefix.select(sym)` is `M2.F`
// however F's type parameter T is `<: M1#A` rather than `<: M2.A`
// so add a call to `asSeenFrom` with prefix `M2.type` and owner `trait M1`
def etaExpandWithAsf(prefix: Type, owner: Symbol)(using Context): Type =
val tparams = self.typeParams
HKTypeLambda(tparams.map(_.paramName))(
tl => tparams.map {
case p: Symbol => HKTypeLambda.toPInfo(tl.integrate(tparams, p.info.asSeenFrom(prefix, owner)))
case p => HKTypeLambda.toPInfo(tl.integrate(tparams, p.paramInfo))
},
tl => tl.integrate(tparams, self.appliedTo(tparams.map(_.paramRef))))

/** Maps [Ts] => C[Ts] to C */
def etaCollapse(using Context): Type = self match
case EtaExpansion(classType) => classType
Expand Down
18 changes: 2 additions & 16 deletions compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1196,22 +1196,8 @@ class Namer { typer: Typer =>
if mbr.isType then
val forwarderName = checkNoConflict(alias.toTypeName, isPrivate = false, span)
var target = pathType.select(sym)
val tparams = target.typeParams
if tparams.nonEmpty then
// like `target = target.etaExpand(target.typeParams)`
// except call `asSeenFrom` to fix class type parameter bounds
// e.g. in pos/i18569:
// `Test#F` should have `M2.A` or `Test.A` as bounds, not `M1#A`.
target = HKTypeLambda(tparams.map(_.paramName))(
tl => tparams.map {
case p: Symbol =>
val info = p.info.asSeenFrom(pathType, sym.owner)
HKTypeLambda.toPInfo(tl.integrate(tparams, info))
case p =>
val info = p.paramInfo
HKTypeLambda.toPInfo(tl.integrate(tparams, info))
},
tl => tl.integrate(tparams, target.appliedTo(tparams.map(_.paramRef))))
if target.typeParams.nonEmpty then
target = target.etaExpandWithAsf(pathType, sym.owner)
newSymbol(
cls, forwarderName,
Exported | Final,
Expand Down

0 comments on commit b0f9e16

Please sign in to comment.