Skip to content

Commit b44edb5

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 de4ad2b commit b44edb5

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
@@ -1175,8 +1175,22 @@ class Namer { typer: Typer =>
11751175
if mbr.isType then
11761176
val forwarderName = checkNoConflict(alias.toTypeName, isPrivate = false, span)
11771177
var target = pathType.select(sym)
1178-
if target.typeParams.nonEmpty then
1179-
target = target.EtaExpand(target.typeParams)
1178+
val tparams = target.typeParams
1179+
if tparams.nonEmpty then
1180+
// like `target = target.EtaExpand(target.typeParams)`
1181+
// except call `asSeenFrom` to fix class type parameter bounds
1182+
// e.g. in pos/i18569:
1183+
// `Test#F` should have `M2.A` or `Test.A` as bounds, not `M1#A`.
1184+
target = HKTypeLambda(tparams.map(_.paramName))(
1185+
tl => tparams.map {
1186+
case p: Symbol =>
1187+
val info = p.info.asSeenFrom(pathType, sym.owner)
1188+
HKTypeLambda.toPInfo(tl.integrate(tparams, info))
1189+
case p =>
1190+
val info = p.paramInfo
1191+
HKTypeLambda.toPInfo(tl.integrate(tparams, info))
1192+
},
1193+
tl => tl.integrate(tparams, target.appliedTo(tparams.map(_.paramRef))))
11801194
newSymbol(
11811195
cls, forwarderName,
11821196
Exported | Final,

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)