Skip to content

Commit eabdf44

Browse files
committed
Fix the tparam bounds of exported inherited classes
When trying to export M2.F, seeing M1#F from the prefix M2 doesn't change the bounds of F's T type parameter, which still refers to M1.this.A, rather than M2.A. So, we run asSeenFrom against that info, when eta-expanding the class into a hk type lambda.
1 parent 98efdab commit eabdf44

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

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

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

tests/pos/i18569.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
trait M1:
2+
trait A
3+
trait F[T <: A]
4+
type G[T <: A] = F[T]
5+
6+
object M2 extends M1
7+
8+
trait Test:
9+
export M2.*
10+
def y: F[A]
11+
def z: G[A]

0 commit comments

Comments
 (0)