Skip to content

Commit f7bf982

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 8cb4945 commit f7bf982

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
@@ -1196,8 +1196,22 @@ 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-
if target.typeParams.nonEmpty then
1200-
target = target.etaExpand(target.typeParams)
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))))
12011215
newSymbol(
12021216
cls, forwarderName,
12031217
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)