Skip to content
Prev Previous commit
Follow type aliases in widenAbstractTypes
SeklomType are already mapped over correctly, that is, as .info.
  • Loading branch information
OlivierBlanvillain committed May 16, 2019
commit 74ca923de5a5986e4be3944e73c178dc06f2f10c
15 changes: 12 additions & 3 deletions compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2150,11 +2150,20 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
case _ =>
cas
}
def widenAbstractTypes(tp: Type) = new TypeMap {
def widenAbstractTypes(tp: Type): Type = new TypeMap {
def apply(tp: Type) = tp match {
case tp: TypeRef if tp.symbol.isAbstractOrParamType | tp.symbol.isOpaqueAlias => WildcardType
case tp: TypeRef =>
if (tp.symbol.isAbstractOrParamType | tp.symbol.isOpaqueAlias)
WildcardType
else tp.info match {
case TypeAlias(alias) =>
val alias1 = widenAbstractTypes(alias)
if (alias1 ne alias) alias1 else tp
case _ => mapOver(tp)
}

case tp: TypeVar if !tp.isInstantiated => WildcardType
case _: SkolemType | _: TypeParamRef => WildcardType
case _: TypeParamRef => WildcardType
case _ => mapOver(tp)
}
}.apply(tp)
Expand Down
25 changes: 25 additions & 0 deletions tests/neg/6314.scala
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,28 @@ object Test3 {
def apply(fa: Bar[X & Foo]): Bar[Y & Foo] = fa
}
}

object Test4 {
type Bar[A] = A match {
case X => String
case Y => Int
}

trait XX {
type Foo
type FooAlias = Foo

val a: Bar[X & FooAlias] = "hello"
val b: Bar[Y & FooAlias] = 1 // error

def apply(fa: Bar[X & FooAlias]): Bar[Y & FooAlias]

def boom: Int = apply(a) // error
}

trait YY extends XX {
type Foo = X & Y

def apply(fa: Bar[X & FooAlias]): Bar[Y & FooAlias] = fa
}
}