Skip to content

Commit

Permalink
Merge pull request #11926 from dotty-staging/fix-11922
Browse files Browse the repository at this point in the history
Eta expand exported type constructors
  • Loading branch information
smarter authored Mar 29, 2021
2 parents 0982f66 + 8e9b006 commit e8cfbb3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
5 changes: 4 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1032,10 +1032,13 @@ class Namer { typer: Typer =>
val forwarder =
if mbr.isType then
val forwarderName = checkNoConflict(alias.toTypeName, isPrivate = false, span)
var target = path.tpe.select(sym)
if target.typeParams.nonEmpty then
target = target.EtaExpand(target.typeParams)
newSymbol(
cls, forwarderName,
Exported | Final,
TypeAlias(path.tpe.select(sym)),
TypeAlias(target),
coord = span)
// Note: This will always create unparameterzied aliases. So even if the original type is
// a parameterized class, say `C[X]` the alias will read `type C = d.C`. We currently do
Expand Down
17 changes: 17 additions & 0 deletions tests/pos/i11922.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
object example {
trait MyType[A]
type Alias[A, B] = MyType[B]
}

object bug {
export example.{MyType, Alias}
def bug[A](m: MyType[A]): MyType[A] = m
val bug2: MyType[String] => MyType[String] = m => m
def bug3[A, B](m: Alias[A, B]): MyType[B] = m
def bug4[A, B](m: Alias[A, B]): Alias[Int, B] = m

//it works when referencing the original type in the parameter position.
def thisWorks[A](m: example.MyType[A]): MyType[A] = m
val thisWorks2: example.MyType[String] => MyType[String] = m => m
val thisWorks3: MyType[String] = (??? : MyType[String])
}

0 comments on commit e8cfbb3

Please sign in to comment.