blob: 35983fe92b62929b3eb98d59b52c8b15a8c0c1bb (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
import scala.annotation.unchecked.uncheckedVariance
class Outer {
// A final class gets no outer ref, so we expect to see warnings where an outer ref check should be performed
final case class Inner(val s: String) // unchecked warning
def belongs(a: Any): Unit = a match {
case Inner(s) => // unchecked warning
case _ =>
}
def belongsStaticSameOuter(a: Inner): Unit = a match {
case Inner(s) => // no need for outer check
// match is exhaustive, no default case needed
}
def belongsOtherOuter(a: Outer#Inner): Unit = a match {
case Inner(s) => // unchecked warning
case O.Inner(s) => // unchecked warning
case _ =>
}
}
object O extends Outer {
def belongsStaticSameOuter2(a: Inner): Unit = a match {
case Inner(s) => // no need for outer check
// match is exhaustive, no default case needed
}
def belongsStaticSameOuter3(a: Inner): Unit = a match {
case _: Inner => // no need for outer check
// match is exhaustive, no default case needed
}
def belongsStaticSameOuter4(a: Inner): Unit = a match {
case _: (Inner @uncheckedVariance) => // no need for outer check
// match is exhaustive, no default case needed
}
def belongsOtherOuter2(a: Outer#Inner): Unit = a match {
case Inner(s) => // unchecked warning
case _ =>
}
def belongsOtherOuter3(a: Outer#Inner): Unit = a match {
case _: Inner => // unchecked warning
case _ =>
}
def belongsOtherOuter4(a: Outer#Inner): Unit = a match {
case _: (Inner @unchecked) => // warning supressed
case _ =>
}
def belongsOtherOuter5(a: Outer#Inner): Unit = a match {
case _: (Inner @uncheckedVariance) => // unchecked warning
case _ =>
}
def nested: Unit = {
final case class I(s: String)
def check1(a: Any): Unit = a match {
case I(s) => // no need for outer check
case _ =>
}
def check2(a: I): Unit = a match {
case I(s) => // no need for outer check
// match is exhaustive, no default case needed
}
}
}
class O2 {
def nested: Unit = {
final case class I(s: String)
def check1(a: Any): Unit = a match {
case I(s) => // no need for outer check (is this correct?)
case _ =>
}
def check2(a: I): Unit = a match {
case I(s) => // no need for outer check (is this correct?)
// match is exhaustive, no default case needed
}
}
}
package p {
object T {
case class C(x: Int)
}
}
object U {
val T = p.T
}
class Test {
def m(a: Any) = a match {
case U.T.C(1) => 1 // used to warn
case _ => 1
}
}
|