Skip to content

Commit b0f9e16

Browse files
committed
Move implementation into TypeApplications etaExpandWithAsf
1 parent f7bf982 commit b0f9e16

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,22 @@ class TypeApplications(val self: Type) extends AnyVal {
321321
}
322322
}
323323

324+
// Like `target.etaExpand(target.typeParams)`
325+
// 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))))
339+
324340
/** Maps [Ts] => C[Ts] to C */
325341
def etaCollapse(using Context): Type = self match
326342
case EtaExpansion(classType) => classType

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

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,22 +1196,8 @@ class Namer { typer: Typer =>
11961196
if mbr.isType then
11971197
val forwarderName = checkNoConflict(alias.toTypeName, isPrivate = false, span)
11981198
var target = pathType.select(sym)
1199-
val tparams = target.typeParams
1200-
if tparams.nonEmpty then
1201-
// like `target = target.etaExpand(target.typeParams)`
1202-
// except call `asSeenFrom` to fix class type parameter bounds
1203-
// e.g. in pos/i18569:
1204-
// `Test#F` should have `M2.A` or `Test.A` as bounds, not `M1#A`.
1205-
target = HKTypeLambda(tparams.map(_.paramName))(
1206-
tl => tparams.map {
1207-
case p: Symbol =>
1208-
val info = p.info.asSeenFrom(pathType, sym.owner)
1209-
HKTypeLambda.toPInfo(tl.integrate(tparams, info))
1210-
case p =>
1211-
val info = p.paramInfo
1212-
HKTypeLambda.toPInfo(tl.integrate(tparams, info))
1213-
},
1214-
tl => tl.integrate(tparams, target.appliedTo(tparams.map(_.paramRef))))
1199+
if target.typeParams.nonEmpty then
1200+
target = target.etaExpandWithAsf(pathType, sym.owner)
12151201
newSymbol(
12161202
cls, forwarderName,
12171203
Exported | Final,

0 commit comments

Comments
 (0)