Skip to content

Commit

Permalink
Fix the tparam bounds of exported inherited classes
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dwijnand committed Oct 12, 2023
1 parent de4ad2b commit 640e6c8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
18 changes: 16 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1175,8 +1175,22 @@ class Namer { typer: Typer =>
if mbr.isType then
val forwarderName = checkNoConflict(alias.toTypeName, isPrivate = false, span)
var target = pathType.select(sym)
if target.typeParams.nonEmpty then
target = target.EtaExpand(target.typeParams)
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))))
newSymbol(
cls, forwarderName,
Exported | Final,
Expand Down
11 changes: 11 additions & 0 deletions tests/pos/i18569.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
trait M1:
trait A
trait F[T <: A]
type G[T <: A] = F[T]

object M2 extends M1

trait Test:
export M2.*
def y: F[A]
def z: G[A]

0 comments on commit 640e6c8

Please sign in to comment.