Skip to content

Commit ef5c96d

Browse files
committed
Fix type lambda reductions involving refinements
Given: type F[X] = Foo[X] We've always been able to reduce `F[_]` to `Foo[_]` if `Foo` is a class. This commit does something similar for refinements, given: type G[X] = Bla { type R = X } We can reduce `G[_]` to `Bar { type R }` (previously we reduced it to `Bar { type R = Any }` which is incorrect).
1 parent 449008e commit ef5c96d

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

compiler/src/dotty/tools/dotc/core/TypeApplications.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ object TypeApplications {
129129
def apply(t: Type): Type = t match {
130130
case t @ AppliedType(tycon, args1) if tycon.typeSymbol.isClass =>
131131
t.derivedAppliedType(apply(tycon), args1.mapConserve(applyArg))
132+
case t @ RefinedType(parent, name, TypeAlias(info)) =>
133+
t.derivedRefinedType(apply(parent), name, applyArg(info).bounds)
132134
case p: TypeParamRef if p.binder == tycon =>
133135
args(p.paramNum) match {
134136
case TypeBounds(lo, hi) =>

tests/pos/hkRefAlias.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Bar
2+
class X
3+
class Y extends X
4+
5+
object Test {
6+
type G[X] = Bar { type R = X }
7+
8+
implicitly[G[_] =:= (Bar { type R })]
9+
implicitly[G[_ >: Y <: X] =:= (Bar { type R >: Y <: X })]
10+
}

0 commit comments

Comments
 (0)