Skip to content

Commit 74ca923

Browse files
Follow type aliases in widenAbstractTypes
SeklomType are already mapped over correctly, that is, as .info.
1 parent 96bd9db commit 74ca923

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

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

+12-3
Original file line numberDiff line numberDiff line change
@@ -2150,11 +2150,20 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
21502150
case _ =>
21512151
cas
21522152
}
2153-
def widenAbstractTypes(tp: Type) = new TypeMap {
2153+
def widenAbstractTypes(tp: Type): Type = new TypeMap {
21542154
def apply(tp: Type) = tp match {
2155-
case tp: TypeRef if tp.symbol.isAbstractOrParamType | tp.symbol.isOpaqueAlias => WildcardType
2155+
case tp: TypeRef =>
2156+
if (tp.symbol.isAbstractOrParamType | tp.symbol.isOpaqueAlias)
2157+
WildcardType
2158+
else tp.info match {
2159+
case TypeAlias(alias) =>
2160+
val alias1 = widenAbstractTypes(alias)
2161+
if (alias1 ne alias) alias1 else tp
2162+
case _ => mapOver(tp)
2163+
}
2164+
21562165
case tp: TypeVar if !tp.isInstantiated => WildcardType
2157-
case _: SkolemType | _: TypeParamRef => WildcardType
2166+
case _: TypeParamRef => WildcardType
21582167
case _ => mapOver(tp)
21592168
}
21602169
}.apply(tp)

tests/neg/6314.scala

+25
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,28 @@ object Test3 {
7171
def apply(fa: Bar[X & Foo]): Bar[Y & Foo] = fa
7272
}
7373
}
74+
75+
object Test4 {
76+
type Bar[A] = A match {
77+
case X => String
78+
case Y => Int
79+
}
80+
81+
trait XX {
82+
type Foo
83+
type FooAlias = Foo
84+
85+
val a: Bar[X & FooAlias] = "hello"
86+
val b: Bar[Y & FooAlias] = 1 // error
87+
88+
def apply(fa: Bar[X & FooAlias]): Bar[Y & FooAlias]
89+
90+
def boom: Int = apply(a) // error
91+
}
92+
93+
trait YY extends XX {
94+
type Foo = X & Y
95+
96+
def apply(fa: Bar[X & FooAlias]): Bar[Y & FooAlias] = fa
97+
}
98+
}

0 commit comments

Comments
 (0)