Skip to content

Commit 959c5e7

Browse files
committed
SI-4043 Fix eta expansion of aliases with non trivial bounds
In the enclosed test case, which defines: trait PA[H1] { type Apply[A <: H1] = Any } The type selection `PA[Int]#Apply` was being eta expanded to `[A <: H1]Any`. After this commit, it is expanded to `[A' <: Int]Any`. This avoids a spurious kind conformance error in the test.
1 parent 65fa73d commit 959c5e7

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/reflect/scala/reflect/internal/Types.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2181,7 +2181,14 @@ trait Types
21812181
// must initialise symbol, see test/files/pos/ticket0137.scala
21822182
val tpars = initializedTypeParams
21832183
if (tpars.isEmpty) this
2184-
else typeFunAnon(tpars, copyTypeRef(this, pre, sym, tpars map (_.tpeHK))) // todo: also beta-reduce?
2184+
else {
2185+
val map = newAsSeenFromMap(pre, sym.owner)
2186+
val tpars1 = map.mapOver(tpars)
2187+
if (tpars eq tpars1)
2188+
typeFunAnon(tpars, copyTypeRef(this, pre, sym, tpars map (_.tpeHK)))
2189+
else
2190+
typeFunAnon(tpars1, copyTypeRef(this, pre, sym, tpars map (_.tpeHK.substSym(tpars, tpars1))))
2191+
} // todo: also beta-reduce?
21852192
}
21862193

21872194
// only need to rebind type aliases, as typeRef already handles abstract types

test/files/pos/t4043.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
object TypeParam {
2+
trait GC[K[_ <: H0], H0]
3+
4+
trait PA[H1] {
5+
type Apply[A <: H1] = Any
6+
}
7+
8+
// error:
9+
// kinds of the type arguments ([A <: H1]Any,Int) do not conform to the expected kinds of the type parameters (type K,type H0) in trait GC.
10+
// [A <: H1]Any's type parameters do not match type K's expected parameters:
11+
// type A's bounds >: Nothing <: H1 are stricter than type _'s declared bounds >: Nothing <: H0
12+
type a = GC[PA[Int]#Apply, Int]
13+
}

0 commit comments

Comments
 (0)