File tree 4 files changed +63
-81
lines changed
compiler/src/dotty/tools/dotc/core
4 files changed +63
-81
lines changed Original file line number Diff line number Diff line change @@ -2409,34 +2409,6 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
2409
2409
case _ =>
2410
2410
cas
2411
2411
}
2412
- def widenAbstractTypes (tp : Type ): Type = new TypeMap {
2413
- var seen = Set [TypeParamRef ]()
2414
- def apply (tp : Type ) = tp match {
2415
- case tp : TypeRef =>
2416
- tp.info match {
2417
- case info : MatchAlias =>
2418
- mapOver(tp)
2419
- // TODO: We should follow the alias in this case, but doing so
2420
- // risks infinite recursion
2421
- case TypeBounds (lo, hi) =>
2422
- if (hi frozen_<:< lo) {
2423
- val alias = apply(lo)
2424
- if (alias ne lo) alias else mapOver(tp)
2425
- }
2426
- else WildcardType
2427
- case _ =>
2428
- mapOver(tp)
2429
- }
2430
- case tp : TypeLambda =>
2431
- val saved = seen
2432
- seen ++= tp.paramRefs
2433
- try mapOver(tp)
2434
- finally seen = saved
2435
- case tp : TypeVar if ! tp.isInstantiated => WildcardType
2436
- case tp : TypeParamRef if ! seen.contains(tp) => WildcardType
2437
- case _ => mapOver(tp)
2438
- }
2439
- }.apply(tp)
2440
2412
2441
2413
val defn .MatchCase (pat, body) = cas1
2442
2414
@@ -2451,8 +2423,6 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
2451
2423
body
2452
2424
}
2453
2425
}
2454
- else if (isSubType(widenAbstractTypes(scrut), widenAbstractTypes(pat)))
2455
- Some (NoType )
2456
2426
else if (provablyDisjoint(scrut, pat))
2457
2427
// We found a proof that `scrut` and `pat` are incompatible.
2458
2428
// The search continues.
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ object Test {
2
2
type L [X ] = X match {
3
3
case Int => L [X ]
4
4
}
5
- type LL [X ] = X match { // error: recursion limit exceeded
5
+ type LL [X ] = X match {
6
6
case Int => LL [LL [X ]]
7
7
}
8
8
def a : L [Boolean ] = ???
Original file line number Diff line number Diff line change
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
25
+ }
26
+ (new YY {}).boom // error
27
+ // object creation impossible, since def apply(fa: String):
28
+ // Int is not defined (Note that String does not match
29
+ // Test3.Bar[X & Object with Test3.YY {...}#Foo])
30
+
31
+ // So the apply in YY doesn't implements the one in XX, and
32
+ // everything is nice and sound.
33
+ }
34
+
35
+ object Test4 {
36
+ type Bar [A ] = A match {
37
+ case X => String
38
+ case Y => Int
39
+ }
40
+
41
+ trait XX {
42
+ type Foo
43
+ type FooAlias = Foo
44
+
45
+ val a : Bar [X & FooAlias ] = " hello"
46
+ val b : Bar [Y & FooAlias ] = 1
47
+
48
+ def apply (fa : Bar [X & FooAlias ]): Bar [Y & FooAlias ]
49
+
50
+ def boom : Int = apply(a)
51
+ }
52
+
53
+ trait YY extends XX {
54
+ type Foo = X & Y
55
+
56
+ def apply (fa : Bar [X & FooAlias ]): Bar [Y & FooAlias ] = fa
57
+ }
58
+ (new YY {}).boom // error
59
+ // object creation impossible, since def apply(fa: String):
60
+ // Int is not defined (Note that String does not match
61
+ // Test4.Bar[X & Object with Test4.YY {...}#FooAlias])
62
+ }
Original file line number Diff line number Diff line change @@ -46,53 +46,3 @@ object Test2 {
46
46
def right (fa : Bar [L ]): Int = fa // error
47
47
}
48
48
}
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
- }
You can’t perform that action at this time.
0 commit comments