Skip to content

Commit 000c52d

Browse files
committed
Revert Unsuppress unchecked warnings + restore warn/i21218
1 parent 8d3b319 commit 000c52d

File tree

13 files changed

+55
-99
lines changed

13 files changed

+55
-99
lines changed

compiler/src/dotty/tools/dotc/reporting/Message.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ abstract class Message(val errorId: ErrorMessageID)(using Context) { self =>
374374
override def canExplain = true
375375

376376
/** Override with `true` for messages that should always be shown even if their
377-
* position overlaps another message of a different class. On the other hand
377+
* position overlaps another messsage of a different class. On the other hand
378378
* multiple messages of the same class with overlapping positions will lead
379379
* to only a single message of that class to be issued.
380380
*/

compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ object TypeTestsCasts {
7474
}.apply(tp)
7575

7676
/** Returns true if the type arguments of `P` can be determined from `X` */
77-
def typeArgsDeterminable(X: Type, P: AppliedType)(using Context) = inContext(ctx.fresh.setExploreTyperState().setFreshGADTBounds) {
77+
def typeArgsTrivial(X: Type, P: AppliedType)(using Context) = inContext(ctx.fresh.setExploreTyperState().setFreshGADTBounds) {
7878
val AppliedType(tycon, _) = P
7979

8080
def underlyingLambda(tp: Type): TypeLambda = tp.ensureLambdaSub match {
@@ -155,7 +155,7 @@ object TypeTestsCasts {
155155
case x =>
156156
// always false test warnings are emitted elsewhere
157157
TypeComparer.provablyDisjoint(x, tpe.derivedAppliedType(tycon, targs.map(_ => WildcardType)))
158-
|| typeArgsDeterminable(X, tpe)
158+
|| typeArgsTrivial(X, tpe)
159159
||| i"its type arguments can't be determined from $X"
160160
}
161161
case AndType(tp1, tp2) => recur(X, tp1) && recur(X, tp2)

compiler/src/dotty/tools/dotc/transform/patmat/Space.scala

+5-5
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ object SpaceEngine {
379379
project(pat)
380380

381381
case Typed(_, tpt) =>
382-
Typ(erase(tpt.tpe.stripAnnots, isValue = true, isTyped = true), decomposed = false)
382+
Typ(erase(tpt.tpe.stripAnnots, isValue = true), decomposed = false)
383383

384384
case This(_) =>
385385
Typ(pat.tpe.stripAnnots, decomposed = false)
@@ -464,13 +464,13 @@ object SpaceEngine {
464464
tp.derivedAppliedType(erase(tycon, inArray, isValue = false), args2)
465465

466466
case tp @ OrType(tp1, tp2) =>
467-
OrType(erase(tp1, inArray, isValue, isTyped), erase(tp2, inArray, isValue, isTyped), tp.isSoft)
467+
OrType(erase(tp1, inArray, isValue), erase(tp2, inArray, isValue), tp.isSoft)
468468

469469
case AndType(tp1, tp2) =>
470-
AndType(erase(tp1, inArray, isValue, isTyped), erase(tp2, inArray, isValue, isTyped))
470+
AndType(erase(tp1, inArray, isValue), erase(tp2, inArray, isValue))
471471

472472
case tp @ RefinedType(parent, _, _) =>
473-
erase(parent, inArray, isValue, isTyped)
473+
erase(parent, inArray, isValue)
474474

475475
case tref: TypeRef if tref.symbol.isPatternBound =>
476476
if inArray then erase(tref.underlying, inArray, isValue, isTyped)
@@ -905,7 +905,7 @@ object SpaceEngine {
905905
def checkMatch(m: Match)(using Context): Unit =
906906
checkMatchExhaustivityOnly(m)
907907
if reachabilityCheckable(m.selector) then checkReachability(m)
908-
908+
909909
def checkMatchExhaustivityOnly(m: Match)(using Context): Unit =
910910
if exhaustivityCheckable(m.selector) then checkExhaustivity(m)
911911
}

tests/pending/neg/i16451.check

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
-- Error: tests/neg/i16451.scala:13:9 ----------------------------------------------------------------------------------
2+
13 | case x: Wrapper[Color.Red.type] => Some(x) // error
3+
| ^
4+
|the type test for Wrapper[(Color.Red : Color)] cannot be checked at runtime because its type arguments can't be determined from Wrapper[Color]
5+
-- Error: tests/neg/i16451.scala:21:9 ----------------------------------------------------------------------------------
6+
21 | case x: Wrapper[Color.Red.type] => Some(x) // error
7+
| ^
8+
|the type test for Wrapper[(Color.Red : Color)] cannot be checked at runtime because its type arguments can't be determined from Any
9+
-- Error: tests/neg/i16451.scala:25:9 ----------------------------------------------------------------------------------
10+
25 | case x: Wrapper[Color.Red.type] => Some(x) // error
11+
| ^
12+
|the type test for Wrapper[(Color.Red : Color)] cannot be checked at runtime because its type arguments can't be determined from Wrapper[Color]
13+
-- Error: tests/neg/i16451.scala:29:9 ----------------------------------------------------------------------------------
14+
29 | case x: Wrapper[Color.Red.type] => Some(x) // error
15+
| ^
16+
|the type test for Wrapper[(Color.Red : Color)] cannot be checked at runtime because its type arguments can't be determined from A1
17+
-- Error: tests/neg/i16451.scala:34:11 ---------------------------------------------------------------------------------
18+
34 | case x: Wrapper[Color.Red.type] => x // error
19+
| ^
20+
|the type test for Wrapper[(Color.Red : Color)] cannot be checked at runtime because its type arguments can't be determined from Wrapper[Color]
21+
-- Error: tests/neg/i16451.scala:39:11 ---------------------------------------------------------------------------------
22+
39 | case x: Wrapper[Color.Red.type] => x // error
23+
| ^
24+
|the type test for Wrapper[(Color.Red : Color)] cannot be checked at runtime because its type arguments can't be determined from Wrapper[Color]

tests/warn/i16451.scala renamed to tests/pending/neg/i16451.scala

+9-13
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,38 @@
1-
//
1+
//> using options -Werror
22
enum Color:
33
case Red, Green
4-
//sealed trait Color
5-
//object Color:
6-
// case object Red extends Color
7-
// case object Green extends Color
84

95
case class Wrapper[A](value: A)
106

117
object Test:
128
def test_correct(x: Wrapper[Color]): Option[Wrapper[Color.Red.type]] = x match
13-
case x: Wrapper[Color.Red.type] => Some(x) // warn: unchecked
14-
case x: Wrapper[Color.Green.type] => None // warn: unreachable // also: unchecked (hidden)
9+
case x: Wrapper[Color.Red.type] => Some(x) // error
10+
case null => None
1511

1612
def test_different(x: Wrapper[Color]): Option[Wrapper[Color]] = x match
1713
case x @ Wrapper(_: Color.Red.type) => Some(x)
1814
case x @ Wrapper(_: Color.Green.type) => None
1915

2016
def test_any(x: Any): Option[Wrapper[Color.Red.type]] = x match
21-
case x: Wrapper[Color.Red.type] => Some(x) // warn: unchecked
22-
case x: Wrapper[Color.Green.type] => None // warn: unreachable // also: unchecked (hidden)
17+
case x: Wrapper[Color.Red.type] => Some(x) // error
18+
case _ => None
2319

2420
def test_wrong(x: Wrapper[Color]): Option[Wrapper[Color.Red.type]] = x match
25-
case x: Wrapper[Color.Red.type] => Some(x) // warn: unchecked
21+
case x: Wrapper[Color.Red.type] => Some(x) // error
2622
case null => None
2723

2824
def t2[A1 <: Wrapper[Color]](x: A1): Option[Wrapper[Color.Red.type]] = x match
29-
case x: Wrapper[Color.Red.type] => Some(x) // warn: unchecked
25+
case x: Wrapper[Color.Red.type] => Some(x) // error
3026
case null => None
3127

3228
def test_wrong_seq(xs: Seq[Wrapper[Color]]): Seq[Wrapper[Color.Red.type]] =
3329
xs.collect {
34-
case x: Wrapper[Color.Red.type] => x // warn: unchecked
30+
case x: Wrapper[Color.Red.type] => x // error
3531
}
3632

3733
def test_wrong_seq2(xs: Seq[Wrapper[Color]]): Seq[Wrapper[Color.Red.type]] =
3834
xs.collect { x => x match
39-
case x: Wrapper[Color.Red.type] => x // warn: unchecked
35+
case x: Wrapper[Color.Red.type] => x // error
4036
}
4137

4238
def main(args: Array[String]): Unit =

tests/warn/enum-approx2.check

-14
This file was deleted.

tests/warn/enum-approx2.scala

-10
This file was deleted.

tests/warn/i11178.scala

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ object Test1 {
1212
def test[A](bar: Bar[A]) =
1313
bar match {
1414
case _: Bar[Boolean] => ??? // warn
15+
case _ => ???
1516
}
1617
}
1718

@@ -22,6 +23,7 @@ object Test2 {
2223
def test[A](bar: Bar[A]) =
2324
bar match {
2425
case _: Bar[Boolean] => ??? // warn
26+
case _ => ???
2527
}
2628
}
2729

@@ -32,5 +34,6 @@ object Test3 {
3234
def test[A](bar: Bar[A]) =
3335
bar match {
3436
case _: Bar[Boolean] => ??? // warn
37+
case _ => ???
3538
}
3639
}

tests/warn/i16451.check

-44
This file was deleted.

tests/warn/i5826.check

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@
1010
|the type test for List[Int] cannot be checked at runtime because its type arguments can't be determined from List[String]
1111
|
1212
| longer explanation available when compiling with `-explain`
13-
-- [E092] Pattern Match Unchecked Warning: tests/warn/i5826.scala:16:9 -------------------------------------------------
14-
16 | case ls: A[X] => 4 // warn
13+
-- [E092] Pattern Match Unchecked Warning: tests/warn/i5826.scala:17:9 -------------------------------------------------
14+
17 | case ls: A[X] => 4 // warn
1515
| ^
1616
|the type test for Foo.this.A[X] cannot be checked at runtime because its type arguments can't be determined from Foo.this.B[X]
1717
|
1818
| longer explanation available when compiling with `-explain`
19-
-- [E092] Pattern Match Unchecked Warning: tests/warn/i5826.scala:21:9 -------------------------------------------------
20-
21 | case ls: List[Int] => ls.head // warn, List extends Int => T
19+
-- [E092] Pattern Match Unchecked Warning: tests/warn/i5826.scala:22:9 -------------------------------------------------
20+
22 | case ls: List[Int] => ls.head // warn, List extends Int => T
2121
| ^
2222
|the type test for List[Int] cannot be checked at runtime because its type arguments can't be determined from A => Int
2323
|
2424
| longer explanation available when compiling with `-explain`
25-
-- [E092] Pattern Match Unchecked Warning: tests/warn/i5826.scala:27:54 ------------------------------------------------
26-
27 | def test5[T](x: A[T] | B[T] | Option[T]): Boolean = x.isInstanceOf[C[String]] // warn
25+
-- [E092] Pattern Match Unchecked Warning: tests/warn/i5826.scala:28:54 ------------------------------------------------
26+
28 | def test5[T](x: A[T] | B[T] | Option[T]): Boolean = x.isInstanceOf[C[String]] // warn
2727
| ^
2828
|the type test for Foo.this.C[String] cannot be checked at runtime because its type arguments can't be determined from Foo.this.A[T]
2929
|

tests/warn/i5826.scala

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class Foo {
66

77
def test2: List[Int] | List[String] => Int = {
88
case ls: List[Int] => ls.head // warn: unchecked
9+
case _ => 0
910
}
1011

1112
trait A[T]

tests/warn/i8932.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Dummy extends Bar[Nothing] with Foo[String]
66
def bugReport[A](foo: Foo[A]): Foo[A] =
77
foo match {
88
case bar: Bar[A] => bar // warn: unchecked
9-
case dummy: Dummy => ??? // warn: unreachable
9+
case dummy: Dummy => ???
1010
}
1111

1212
def test = bugReport(new Dummy: Foo[String])

tests/warn/suppressed-type-test-warnings.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
object Test {
22
sealed trait Foo[A, B]
33
final case class Bar[X](x: X) extends Foo[X, X]
4-
54
def foo[A, B](value: Foo[A, B], a: A => Int): B = value match {
65
case Bar(x) => a(x); x
76
}
8-
97
def bar[A, B](value: Foo[A, B], a: A => Int): B = value match {
108
case b: Bar[a] => b.x
119
}
@@ -18,10 +16,12 @@ object Test {
1816
def err2[A, B](value: Foo[A, B], a: A => Int): B = value match {
1917
case b: Bar[B] => // spurious // warn
2018
b.x
19+
case _ => ??? // avoid fatal inexhaustivity warnings suppressing the uncheckable warning
2120
}
2221

2322
def fail[A, B](value: Foo[A, B], a: A => Int): B = value match {
2423
case b: Bar[Int] => // warn
2524
b.x
25+
case _ => ??? // avoid fatal inexhaustivity warnings suppressing the uncheckable warning
2626
}
27-
}
27+
}

0 commit comments

Comments
 (0)