Skip to content

Commit e8cfbb3

Browse files
authored
Merge pull request #11926 from dotty-staging/fix-11922
Eta expand exported type constructors
2 parents 0982f66 + 8e9b006 commit e8cfbb3

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -1032,10 +1032,13 @@ class Namer { typer: Typer =>
10321032
val forwarder =
10331033
if mbr.isType then
10341034
val forwarderName = checkNoConflict(alias.toTypeName, isPrivate = false, span)
1035+
var target = path.tpe.select(sym)
1036+
if target.typeParams.nonEmpty then
1037+
target = target.EtaExpand(target.typeParams)
10351038
newSymbol(
10361039
cls, forwarderName,
10371040
Exported | Final,
1038-
TypeAlias(path.tpe.select(sym)),
1041+
TypeAlias(target),
10391042
coord = span)
10401043
// Note: This will always create unparameterzied aliases. So even if the original type is
10411044
// a parameterized class, say `C[X]` the alias will read `type C = d.C`. We currently do

tests/pos/i11922.scala

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
object example {
2+
trait MyType[A]
3+
type Alias[A, B] = MyType[B]
4+
}
5+
6+
object bug {
7+
export example.{MyType, Alias}
8+
def bug[A](m: MyType[A]): MyType[A] = m
9+
val bug2: MyType[String] => MyType[String] = m => m
10+
def bug3[A, B](m: Alias[A, B]): MyType[B] = m
11+
def bug4[A, B](m: Alias[A, B]): Alias[Int, B] = m
12+
13+
//it works when referencing the original type in the parameter position.
14+
def thisWorks[A](m: example.MyType[A]): MyType[A] = m
15+
val thisWorks2: example.MyType[String] => MyType[String] = m => m
16+
val thisWorks3: MyType[String] = (??? : MyType[String])
17+
}

0 commit comments

Comments
 (0)