Skip to content

Commit 0ef2192

Browse files
Simplify MT reduction algorithm
By removing the widenAbstractTypes step, which is subsumed by the provably empty test.
1 parent 67625b0 commit 0ef2192

File tree

3 files changed

+57
-80
lines changed

3 files changed

+57
-80
lines changed

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

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2757,34 +2757,6 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
27572757
case _ =>
27582758
cas
27592759
}
2760-
def widenAbstractTypes(tp: Type): Type = new TypeMap {
2761-
var seen = Set[TypeParamRef]()
2762-
def apply(tp: Type) = tp match {
2763-
case tp: TypeRef =>
2764-
tp.info match {
2765-
case info: MatchAlias =>
2766-
mapOver(tp)
2767-
// TODO: We should follow the alias in this case, but doing so
2768-
// risks infinite recursion
2769-
case TypeBounds(lo, hi) =>
2770-
if (hi frozen_<:< lo) {
2771-
val alias = apply(lo)
2772-
if (alias ne lo) alias else mapOver(tp)
2773-
}
2774-
else WildcardType
2775-
case _ =>
2776-
mapOver(tp)
2777-
}
2778-
case tp: TypeLambda =>
2779-
val saved = seen
2780-
seen ++= tp.paramRefs
2781-
try mapOver(tp)
2782-
finally seen = saved
2783-
case tp: TypeVar if !tp.isInstantiated => WildcardType
2784-
case tp: TypeParamRef if !seen.contains(tp) => WildcardType
2785-
case _ => mapOver(tp)
2786-
}
2787-
}.apply(tp)
27882760

27892761
val defn.MatchCase(pat, body) = cas1
27902762

@@ -2799,8 +2771,6 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
27992771
body
28002772
}
28012773
}
2802-
else if (isSubType(widenAbstractTypes(scrut), widenAbstractTypes(pat)))
2803-
Some(NoType)
28042774
else if (provablyDisjoint(scrut, pat))
28052775
// We found a proof that `scrut` and `pat` are incompatible.
28062776
// The search continues.

tests/neg/6314-6.scala

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
final class X
2+
final class Y
3+
4+
object Test3 {
5+
type Bar[A] = A match {
6+
case X => String
7+
case Y => Int
8+
}
9+
10+
trait XX {
11+
type Foo
12+
13+
val a: Bar[X & Foo] = "hello"
14+
val b: Bar[Y & Foo] = 1
15+
16+
def apply(fa: Bar[X & Foo]): Bar[Y & Foo]
17+
18+
def boom: Int = apply(a)
19+
}
20+
21+
trait YY extends XX {
22+
type Foo = X & Y
23+
24+
def apply(fa: Bar[X & Foo]): Bar[Y & Foo] = fa // error
25+
// overriding method apply in trait XX of type (fa: String): Int;
26+
// method apply of type (fa: String): String has incompatible type
27+
}
28+
(new YY {}).boom
29+
}
30+
31+
object Test4 {
32+
type Bar[A] = A match {
33+
case X => String
34+
case Y => Int
35+
}
36+
37+
trait XX {
38+
type Foo
39+
type FooAlias = Foo
40+
41+
val a: Bar[X & FooAlias] = "hello"
42+
val b: Bar[Y & FooAlias] = 1
43+
44+
def apply(fa: Bar[X & FooAlias]): Bar[Y & FooAlias]
45+
46+
def boom: Int = apply(a)
47+
}
48+
49+
trait YY extends XX {
50+
type Foo = X & Y
51+
52+
def apply(fa: Bar[X & FooAlias]): Bar[Y & FooAlias] = fa // error
53+
// overriding method apply in trait XX of type (fa: String): Int;
54+
// method apply of type (fa: String): String has incompatible type
55+
}
56+
(new YY {}).boom
57+
}

tests/neg/6314.scala

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -46,53 +46,3 @@ object Test2 {
4646
def right(fa: Bar[L]): Int = fa // error
4747
}
4848
}
49-
50-
51-
object Test3 {
52-
type Bar[A] = A match {
53-
case X => String
54-
case Y => Int
55-
}
56-
57-
trait XX {
58-
type Foo
59-
60-
val a: Bar[X & Foo] = "hello"
61-
val b: Bar[Y & Foo] = 1 // error
62-
63-
def apply(fa: Bar[X & Foo]): Bar[Y & Foo]
64-
65-
def boom: Int = apply(a) // error
66-
}
67-
68-
trait YY extends XX {
69-
type Foo = X & Y
70-
71-
def apply(fa: Bar[X & Foo]): Bar[Y & Foo] = fa
72-
}
73-
}
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)