From 726905918ace4523746fe6b90a52fbe69093b725 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Sat, 6 Apr 2019 16:33:19 +0200 Subject: [PATCH] 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). --- .../src/dotty/tools/dotc/core/TypeApplications.scala | 2 ++ tests/pos/hkRefAlias.scala | 10 ++++++++++ 2 files changed, 12 insertions(+) create mode 100644 tests/pos/hkRefAlias.scala diff --git a/compiler/src/dotty/tools/dotc/core/TypeApplications.scala b/compiler/src/dotty/tools/dotc/core/TypeApplications.scala index 45c5ce8586bc..85c24a7dbe10 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeApplications.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeApplications.scala @@ -129,6 +129,8 @@ object TypeApplications { def apply(t: Type): Type = t match { case t @ AppliedType(tycon, args1) if tycon.typeSymbol.isClass => t.derivedAppliedType(apply(tycon), args1.mapConserve(applyArg)) + case t @ RefinedType(parent, name, TypeAlias(info)) => + t.derivedRefinedType(apply(parent), name, applyArg(info).bounds) case p: TypeParamRef if p.binder == tycon => args(p.paramNum) match { case TypeBounds(lo, hi) => diff --git a/tests/pos/hkRefAlias.scala b/tests/pos/hkRefAlias.scala new file mode 100644 index 000000000000..58ec787def1c --- /dev/null +++ b/tests/pos/hkRefAlias.scala @@ -0,0 +1,10 @@ +class Bar +class X +class Y extends X + +object Test { + type G[X] = Bar { type R = X } + + implicitly[G[_] =:= (Bar { type R })] + implicitly[G[_ >: Y <: X] =:= (Bar { type R >: Y <: X })] +}