Skip to content

Commit

Permalink
Revert Unsuppress unchecked warnings
Browse files Browse the repository at this point in the history
This reverts commit 9045834 due to introduced regression
  • Loading branch information
WojciechMazur committed Oct 9, 2024
1 parent ebf5ae1 commit caae26a
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 98 deletions.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/reporting/Message.scala
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ abstract class Message(val errorId: ErrorMessageID)(using Context) { self =>
override def canExplain = true

/** Override with `true` for messages that should always be shown even if their
* position overlaps another message of a different class. On the other hand
* position overlaps another messsage of a different class. On the other hand
* multiple messages of the same class with overlapping positions will lead
* to only a single message of that class to be issued.
*/
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ object TypeTestsCasts {
}.apply(tp)

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

def underlyingLambda(tp: Type): TypeLambda = tp.ensureLambdaSub match {
Expand Down Expand Up @@ -161,7 +161,7 @@ object TypeTestsCasts {
val tparams = x.typeParams
if tparams.isEmpty then x else x.appliedTo(tparams.map(_ => WildcardType))
TypeComparer.provablyDisjoint(xApplied, tpe.derivedAppliedType(tycon, targs.map(_ => WildcardType)))
|| typeArgsDeterminable(X, tpe)
|| typeArgsTrivial(X, tpe)
||| i"its type arguments can't be determined from $X"
}
case AndType(tp1, tp2) => recur(X, tp1) && recur(X, tp2)
Expand Down
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/transform/patmat/Space.scala
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ object SpaceEngine {
project(pat)

case Typed(_, tpt) =>
Typ(erase(tpt.tpe.stripAnnots, isValue = true, isTyped = true), decomposed = false)
Typ(erase(tpt.tpe.stripAnnots, isValue = true), decomposed = false)

case This(_) =>
Typ(pat.tpe.stripAnnots, decomposed = false)
Expand Down Expand Up @@ -455,13 +455,13 @@ object SpaceEngine {
tp.derivedAppliedType(erase(tycon, inArray, isValue = false), args2)

case tp @ OrType(tp1, tp2) =>
OrType(erase(tp1, inArray, isValue, isTyped), erase(tp2, inArray, isValue, isTyped), tp.isSoft)
OrType(erase(tp1, inArray, isValue), erase(tp2, inArray, isValue), tp.isSoft)

case AndType(tp1, tp2) =>
AndType(erase(tp1, inArray, isValue, isTyped), erase(tp2, inArray, isValue, isTyped))
AndType(erase(tp1, inArray, isValue), erase(tp2, inArray, isValue))

case tp @ RefinedType(parent, _, _) =>
erase(parent, inArray, isValue, isTyped)
erase(parent, inArray, isValue)

case tref: TypeRef if tref.symbol.isPatternBound =>
if inArray then erase(tref.underlying, inArray, isValue, isTyped)
Expand Down
24 changes: 24 additions & 0 deletions tests/pending/neg/i16451.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
-- Error: tests/neg/i16451.scala:13:9 ----------------------------------------------------------------------------------
13 | case x: Wrapper[Color.Red.type] => Some(x) // error
| ^
|the type test for Wrapper[(Color.Red : Color)] cannot be checked at runtime because its type arguments can't be determined from Wrapper[Color]
-- Error: tests/neg/i16451.scala:21:9 ----------------------------------------------------------------------------------
21 | case x: Wrapper[Color.Red.type] => Some(x) // error
| ^
|the type test for Wrapper[(Color.Red : Color)] cannot be checked at runtime because its type arguments can't be determined from Any
-- Error: tests/neg/i16451.scala:25:9 ----------------------------------------------------------------------------------
25 | case x: Wrapper[Color.Red.type] => Some(x) // error
| ^
|the type test for Wrapper[(Color.Red : Color)] cannot be checked at runtime because its type arguments can't be determined from Wrapper[Color]
-- Error: tests/neg/i16451.scala:29:9 ----------------------------------------------------------------------------------
29 | case x: Wrapper[Color.Red.type] => Some(x) // error
| ^
|the type test for Wrapper[(Color.Red : Color)] cannot be checked at runtime because its type arguments can't be determined from A1
-- Error: tests/neg/i16451.scala:34:11 ---------------------------------------------------------------------------------
34 | case x: Wrapper[Color.Red.type] => x // error
| ^
|the type test for Wrapper[(Color.Red : Color)] cannot be checked at runtime because its type arguments can't be determined from Wrapper[Color]
-- Error: tests/neg/i16451.scala:39:11 ---------------------------------------------------------------------------------
39 | case x: Wrapper[Color.Red.type] => x // error
| ^
|the type test for Wrapper[(Color.Red : Color)] cannot be checked at runtime because its type arguments can't be determined from Wrapper[Color]
22 changes: 9 additions & 13 deletions tests/warn/i16451.scala → tests/pending/neg/i16451.scala
Original file line number Diff line number Diff line change
@@ -1,42 +1,38 @@
//
//> using options -Werror
enum Color:
case Red, Green
//sealed trait Color
//object Color:
// case object Red extends Color
// case object Green extends Color

case class Wrapper[A](value: A)

object Test:
def test_correct(x: Wrapper[Color]): Option[Wrapper[Color.Red.type]] = x match
case x: Wrapper[Color.Red.type] => Some(x) // warn: unchecked
case x: Wrapper[Color.Green.type] => None // warn: unreachable // also: unchecked (hidden)
case x: Wrapper[Color.Red.type] => Some(x) // error
case null => None

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

def test_any(x: Any): Option[Wrapper[Color.Red.type]] = x match
case x: Wrapper[Color.Red.type] => Some(x) // warn: unchecked
case x: Wrapper[Color.Green.type] => None // warn: unreachable // also: unchecked (hidden)
case x: Wrapper[Color.Red.type] => Some(x) // error
case _ => None

def test_wrong(x: Wrapper[Color]): Option[Wrapper[Color.Red.type]] = x match
case x: Wrapper[Color.Red.type] => Some(x) // warn: unchecked
case x: Wrapper[Color.Red.type] => Some(x) // error
case null => None

def t2[A1 <: Wrapper[Color]](x: A1): Option[Wrapper[Color.Red.type]] = x match
case x: Wrapper[Color.Red.type] => Some(x) // warn: unchecked
case x: Wrapper[Color.Red.type] => Some(x) // error
case null => None

def test_wrong_seq(xs: Seq[Wrapper[Color]]): Seq[Wrapper[Color.Red.type]] =
xs.collect {
case x: Wrapper[Color.Red.type] => x // warn: unchecked
case x: Wrapper[Color.Red.type] => x // error
}

def test_wrong_seq2(xs: Seq[Wrapper[Color]]): Seq[Wrapper[Color.Red.type]] =
xs.collect { x => x match
case x: Wrapper[Color.Red.type] => x // warn: unchecked
case x: Wrapper[Color.Red.type] => x // error
}

def main(args: Array[String]): Unit =
Expand Down
14 changes: 0 additions & 14 deletions tests/warn/enum-approx2.check

This file was deleted.

10 changes: 0 additions & 10 deletions tests/warn/enum-approx2.scala

This file was deleted.

3 changes: 3 additions & 0 deletions tests/warn/i11178.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ object Test1 {
def test[A](bar: Bar[A]) =
bar match {
case _: Bar[Boolean] => ??? // warn
case _ => ???
}
}

Expand All @@ -22,6 +23,7 @@ object Test2 {
def test[A](bar: Bar[A]) =
bar match {
case _: Bar[Boolean] => ??? // warn
case _ => ???
}
}

Expand All @@ -32,5 +34,6 @@ object Test3 {
def test[A](bar: Bar[A]) =
bar match {
case _: Bar[Boolean] => ??? // warn
case _ => ???
}
}
44 changes: 0 additions & 44 deletions tests/warn/i16451.check

This file was deleted.

12 changes: 6 additions & 6 deletions tests/warn/i5826.check
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@
|the type test for List[Int] cannot be checked at runtime because its type arguments can't be determined from List[String]
|
| longer explanation available when compiling with `-explain`
-- [E092] Pattern Match Unchecked Warning: tests/warn/i5826.scala:16:9 -------------------------------------------------
16 | case ls: A[X] => 4 // warn
-- [E092] Pattern Match Unchecked Warning: tests/warn/i5826.scala:17:9 -------------------------------------------------
17 | case ls: A[X] => 4 // warn
| ^
|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]
|
| longer explanation available when compiling with `-explain`
-- [E092] Pattern Match Unchecked Warning: tests/warn/i5826.scala:21:9 -------------------------------------------------
21 | case ls: List[Int] => ls.head // warn, List extends Int => T
-- [E092] Pattern Match Unchecked Warning: tests/warn/i5826.scala:22:9 -------------------------------------------------
22 | case ls: List[Int] => ls.head // warn, List extends Int => T
| ^
|the type test for List[Int] cannot be checked at runtime because its type arguments can't be determined from A => Int
|
| longer explanation available when compiling with `-explain`
-- [E092] Pattern Match Unchecked Warning: tests/warn/i5826.scala:27:54 ------------------------------------------------
27 | def test5[T](x: A[T] | B[T] | Option[T]): Boolean = x.isInstanceOf[C[String]] // warn
-- [E092] Pattern Match Unchecked Warning: tests/warn/i5826.scala:28:54 ------------------------------------------------
28 | def test5[T](x: A[T] | B[T] | Option[T]): Boolean = x.isInstanceOf[C[String]] // warn
| ^
|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]
|
Expand Down
1 change: 1 addition & 0 deletions tests/warn/i5826.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Foo {

def test2: List[Int] | List[String] => Int = {
case ls: List[Int] => ls.head // warn: unchecked
case _ => 0
}

trait A[T]
Expand Down
2 changes: 1 addition & 1 deletion tests/warn/i8932.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Dummy extends Bar[Nothing] with Foo[String]
def bugReport[A](foo: Foo[A]): Foo[A] =
foo match {
case bar: Bar[A] => bar // warn: unchecked
case dummy: Dummy => ??? // warn: unreachable
case dummy: Dummy => ???
}

def test = bugReport(new Dummy: Foo[String])
6 changes: 3 additions & 3 deletions tests/warn/suppressed-type-test-warnings.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
object Test {
sealed trait Foo[A, B]
final case class Bar[X](x: X) extends Foo[X, X]

def foo[A, B](value: Foo[A, B], a: A => Int): B = value match {
case Bar(x) => a(x); x
}

def bar[A, B](value: Foo[A, B], a: A => Int): B = value match {
case b: Bar[a] => b.x
}
Expand All @@ -18,10 +16,12 @@ object Test {
def err2[A, B](value: Foo[A, B], a: A => Int): B = value match {
case b: Bar[B] => // spurious // warn
b.x
case _ => ??? // avoid fatal inexhaustivity warnings suppressing the uncheckable warning
}

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

0 comments on commit caae26a

Please sign in to comment.