Skip to content

Commit

Permalink
Adjusted tests
Browse files Browse the repository at this point in the history
  • Loading branch information
szymon-rd committed Nov 2, 2023
1 parent 4aa8e40 commit dd9808a
Show file tree
Hide file tree
Showing 178 changed files with 1,020 additions and 805 deletions.
4 changes: 3 additions & 1 deletion tests/neg-deep-subtype/1828.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

class Test {
def remove[S](a: S | Int, f: Int => S):S = a match {
case a: S => a // error
case a: S => a // warn
case a: Int => f(a)
}

val t: Int | String = 5
val t1 = remove[String](t, _.toString)
}

// nopos-error: No warnings can be incurred under -Werror.
9 changes: 5 additions & 4 deletions tests/neg-deep-subtype/3324b.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

class C[T] {
val x: Any = ???
if (x.isInstanceOf[List[String]]) // error: unchecked
if (x.isInstanceOf[T]) // error: unchecked
if (x.isInstanceOf[List[String]]) // warn: unchecked
if (x.isInstanceOf[T]) // warn: unchecked
x match {
case x: List[String] => // error: unchecked
case x: T => // error: unchecked
case x: List[String] => // warn: unchecked
case x: T => // warn: unchecked
}
}
// nopos-error: No warnings can be incurred under -Werror.
7 changes: 4 additions & 3 deletions tests/neg-deep-subtype/3324f.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ class D[T]

class Test {
def foo[T](x: C[T]) = x match {
case _: D[T] => // error
case _: C[Int] => // error
case _: D[T] => // warn
case _: C[Int] => // warn
}
}
}
// nopos-error: No warnings can be incurred under -Werror.
5 changes: 3 additions & 2 deletions tests/neg-deep-subtype/3324g.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ class Test {
class C[T] extends B[Any] with A[T]

def foo[T](c: C[T]): Unit = c match {
case _: B[T] => // error
case _: B[T] => // warn
}

def bar[T](b: B[T]): Unit = b match {
case _: A[T] =>
}

def quux[T](a: A[T]): Unit = a match {
case _: B[T] => // error!!
case _: B[T] => // warn!!
}

quux(new C[Int])
}
// nopos-error: No warnings can be incurred under -Werror.
6 changes: 4 additions & 2 deletions tests/neg-deep-subtype/JavaSeqLiteral.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ object Test1 {
class DummyTree extends JavaSeqLiteral[Any]

def foo1(tree: Tree[Type]) =
tree.isInstanceOf[JavaSeqLiteral[Type]] // error
tree.isInstanceOf[JavaSeqLiteral[Type]] // warn

foo1(new DummyTree)
}
Expand All @@ -28,4 +28,6 @@ object Test2 {
tree.isInstanceOf[JavaSeqLiteral[Type]]

foo1(new DummyTree)
}
}

// nopos-error: No warnings can be incurred under -Werror.
5 changes: 3 additions & 2 deletions tests/neg-deep-subtype/conditionalWarnings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ object Test {

given Conversion[String, Int] = _.length

foo // error
foo // warn

val x: Int = "abc"
// OK, since -feature warnings are not enabled.
// The program compiles with final line
// there was 1 feature warning; re-run with -feature for details
// nopos-error
// nopos-warn
}
// nopos-error: No warnings can be incurred under -Werror.
6 changes: 4 additions & 2 deletions tests/neg-deep-subtype/gadt.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ class Test {
class D extends C

def quux(a: A[C]): Unit = a match {
case _: B[C] => // error!!
case _: B[C] => // warn
}

quux(new B[D])
}
}

// nopos-error: No warnings can be incurred under -Werror.
4 changes: 3 additions & 1 deletion tests/neg-deep-subtype/html.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ object HTML:
attrs.filter(_ != Nil).foreach{
case s: Seq[AppliedAttr] =>
s.foreach(sb.append(" ").append)
case s: Seq[Int] => // error
case s: Seq[Int] => // warn
case e: AppliedAttr =>
sb.append(" ").append(e)
}
sb
}

// nopos-error: No warnings can be incurred under -Werror.
4 changes: 3 additions & 1 deletion tests/neg-deep-subtype/i3324.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@

class Foo {
def foo(x: Any): Boolean =
x.isInstanceOf[List[String]] // error
x.isInstanceOf[List[String]] // warn
}

// nopos-error: No warnings can be incurred under -Werror.
11 changes: 6 additions & 5 deletions tests/neg-deep-subtype/i4297.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ class Test {
def test[X <: Option[Int]](x: X) = x.isInstanceOf[Some[Int]]
def test1[Y <: Int, X <: Option[Y]](x: X) = x.isInstanceOf[Some[Int]]
def test2(x: Any) = x.isInstanceOf[Function1[Nothing, _]]
def test3a(x: Any) = x.isInstanceOf[Function1[Any, _]] // error
def test3b(x: Any) = x.isInstanceOf[Function1[Int, _]] // error
def test4[Y <: Int, X <: Function1[Y, Unit]](x: X) = x.isInstanceOf[Function1[Int, _]] // error
def test5[Y <: Int, X <: Function1[Y, Unit]](x: X) = x.isInstanceOf[Function1[Int, Unit]] // error
def test6[Y <: Int, X <: Function1[Y, Unit]](x: X) = x.isInstanceOf[Function1[Int, Any]] // error
def test3a(x: Any) = x.isInstanceOf[Function1[Any, _]] // warn
def test3b(x: Any) = x.isInstanceOf[Function1[Int, _]] // warn
def test4[Y <: Int, X <: Function1[Y, Unit]](x: X) = x.isInstanceOf[Function1[Int, _]] // warn
def test5[Y <: Int, X <: Function1[Y, Unit]](x: X) = x.isInstanceOf[Function1[Int, Unit]] // warn
def test6[Y <: Int, X <: Function1[Y, Unit]](x: X) = x.isInstanceOf[Function1[Int, Any]] // warn
def test7[Y <: Int, X <: Function1[Y, Unit]](x: X) = x.isInstanceOf[Function1[_, Unit]]
}
// nopos-error: No warnings can be incurred under -Werror.
9 changes: 5 additions & 4 deletions tests/neg-deep-subtype/or-type-trees.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ object Test1 {

def foo2(myTree: Tree | (Context => Tree)) =
myTree match
case treeFn: (Context => Tree) => // error
case treeFn: (Context => Tree) => // warn
case _ =>

def foo3(myTree: Tree | (Context => Tree)) =
Expand All @@ -25,16 +25,17 @@ object Test2 {
trait Type

def foo1(myTree: Tree[Type] | (Context => Tree[Type])) =
println(myTree.isInstanceOf[Tree[Type]]) // error
println(myTree.isInstanceOf[Tree[Type]]) // warn
/* class DummyTree extends Tree[Nothing] with (Context => Tree[Type]) */

def foo2(myTree: Tree[Type] | (Context => Tree[Type])) =
myTree match
case treeFn: (Context => Tree[Type]) => // error
case treeFn: (Context => Tree[Type]) => // warn
case _ =>

def foo3(myTree: Tree[Type] | (Context => Tree[Type])) =
myTree match
case treeFn: (_ => _) => // ok
case _ =>
}
}
// nopos-error: No warnings can be incurred under -Werror.
9 changes: 5 additions & 4 deletions tests/neg-deep-subtype/refined-types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def bl(x: AA) = x.isInstanceOf[BL] // was: the type test for BL cannot be checke
def bu(x: AA) = x.isInstanceOf[BU] // was: the type test for BU cannot be checked at runtime

// but static knowledge of only one bound makes checking against an alias unchecked:
def al_ba(x: AL) = x.isInstanceOf[BA] // error: the type test for BA cannot be checked at runtime
def au_ba(x: AU) = x.isInstanceOf[BA] // error: the type test for BA cannot be checked at runtime
def al_bu(x: AL) = x.isInstanceOf[BU] // error: the type test for BU cannot be checked at runtime
def au_bl(x: AU) = x.isInstanceOf[BL] // error: the type test for BL cannot be checked at runtime
def al_ba(x: AL) = x.isInstanceOf[BA] // warn: the type test for BA cannot be checked at runtime
def au_ba(x: AU) = x.isInstanceOf[BA] // warn: the type test for BA cannot be checked at runtime
def al_bu(x: AL) = x.isInstanceOf[BU] // warn: the type test for BU cannot be checked at runtime
def au_bl(x: AU) = x.isInstanceOf[BL] // warn: the type test for BL cannot be checked at runtime
// nopos-error: No warnings can be incurred under -Werror.
5 changes: 3 additions & 2 deletions tests/neg-deep-subtype/t2755.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ object Test {
case x: Array[String] => x.size
case x: Array[AnyRef] => 5
case x: Array[_] => 6
case _ => 7 // error: only null is matched
case _ => 7 // warn: only null is matched
}
def f3[T](a: Array[T]) = a match {
case x: Array[Int] => x(0)
Expand All @@ -28,7 +28,7 @@ object Test {
case x: Array[String] => x.size
case x: Array[AnyRef] => 5
case x: Array[_] => 6
case _ => 7 // error: only null is matched
case _ => 7 // warn: only null is matched
}


Expand Down Expand Up @@ -58,3 +58,4 @@ object Test {
println(f3(null))
}
}
// nopos-error: No warnings can be incurred under -Werror.
4 changes: 3 additions & 1 deletion tests/neg-deep-subtype/type-lambda.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ object Test {
}

def bar(x: ([X] =>> A[X])[Any]) = x match {
case x: ([X] =>> B[Nothing])[Any] => // error
case x: ([X] =>> B[Nothing])[Any] => // warn
case _ =>
}
}

// nopos-error: No warnings can be incurred under -Werror.
17 changes: 9 additions & 8 deletions tests/neg/14034b.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
@deprecated trait Exp
@deprecated val exp = 1

def test1 = exp // error
def test2(a: Exp) = () // error
def test1 = exp // warn
def test2(a: Exp) = () // warn

type Foo0 = Exp // error
type Foo = Option[Exp] // error
type Bar = Option[exp.type] // error
type Baz = Exp | Int // error
type Foo0 = Exp // warn
type Foo = Option[Exp] // warn
type Bar = Option[exp.type] // warn
type Baz = Exp | Int // warn
type Quux = [X] =>> X match
case Exp => Int // error
type Quuz[A <: Exp] = Int // error
case Exp => Int // warn
type Quuz[A <: Exp] = Int // warn
// nopos-error: No warnings can be incurred under -Werror.
5 changes: 3 additions & 2 deletions tests/neg/15981.check
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
-- [E092] Pattern Match Error: tests/neg/15981.scala:4:45 --------------------------------------------------------------
4 | override def equals(any: Any): Boolean = any.isInstanceOf[PosInt] // error
-- [E092] Pattern Match Unchecked Warning: tests/neg/15981.scala:4:45 --------------------------------------------------
4 | override def equals(any: Any): Boolean = any.isInstanceOf[PosInt] // warn
| ^^^
| the type test for PosInt cannot be checked at runtime because it's a local class
|
| longer explanation available when compiling with `-explain`
No warnings can be incurred under -Werror.
3 changes: 2 additions & 1 deletion tests/neg/15981.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//> using options -Werror
val _ = locally{
sealed abstract class PosInt(val value: Int) {
override def equals(any: Any): Boolean = any.isInstanceOf[PosInt] // error
override def equals(any: Any): Boolean = any.isInstanceOf[PosInt] // warn
}
}
// nopos-error: No warnings can be incurred under -Werror.
13 changes: 7 additions & 6 deletions tests/neg/17284.check
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- [E187] Potential Issue Error: tests/neg/17284.scala:4:6 -------------------------------------------------------------
4 | 451.synchronized {} // error
-- [E187] Potential Issue Warning: tests/neg/17284.scala:4:6 -----------------------------------------------------------
4 | 451.synchronized {} // warn
| ^^^^^^^^^^^^^^^^
| Suspicious synchronized call on boxed class
|---------------------------------------------------------------------------------------------------------------------
Expand All @@ -8,8 +8,8 @@
| You called the synchronized method on a boxed primitive. This might not be what
| you intended.
---------------------------------------------------------------------------------------------------------------------
-- [E187] Potential Issue Error: tests/neg/17284.scala:8:4 -------------------------------------------------------------
8 | x.synchronized {} // error
-- [E187] Potential Issue Warning: tests/neg/17284.scala:8:4 -----------------------------------------------------------
8 | x.synchronized {} // warn
| ^^^^^^^^^^^^^^
| Suspicious synchronized call on boxed class
|---------------------------------------------------------------------------------------------------------------------
Expand All @@ -18,8 +18,8 @@
| You called the synchronized method on a boxed primitive. This might not be what
| you intended.
---------------------------------------------------------------------------------------------------------------------
-- [E187] Potential Issue Error: tests/neg/17284.scala:11:7 ------------------------------------------------------------
11 | true.synchronized {} // error
-- [E187] Potential Issue Warning: tests/neg/17284.scala:11:7 ----------------------------------------------------------
11 | true.synchronized {} // warn
| ^^^^^^^^^^^^^^^^^
| Suspicious synchronized call on boxed class
|--------------------------------------------------------------------------------------------------------------------
Expand All @@ -28,3 +28,4 @@
| You called the synchronized method on a boxed primitive. This might not be what
| you intended.
--------------------------------------------------------------------------------------------------------------------
No warnings can be incurred under -Werror.
7 changes: 4 additions & 3 deletions tests/neg/17284.scala
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
//> using options -Werror -explain

def test =
451.synchronized {} // error
451.synchronized {} // warn

def test2 =
val x: Integer = 451
x.synchronized {} // error
x.synchronized {} // warn

def test3 =
true.synchronized {} // error
true.synchronized {} // warn

def test4 =
true.hashCode() // success
// nopos-error: No warnings can be incurred under -Werror.
9 changes: 5 additions & 4 deletions tests/neg/18493.check
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
-- [E030] Match case Unreachable Error: tests/neg/18493.scala:6:9 ------------------------------------------------------
6 | case "abc" => // error
-- [E030] Match case Unreachable Warning: tests/neg/18493.scala:6:9 ----------------------------------------------------
6 | case "abc" => // warn
| ^^^^^
| Unreachable case
-- [E030] Match case Unreachable Error: tests/neg/18493.scala:12:9 -----------------------------------------------------
12 | case "abc" => // error
-- [E030] Match case Unreachable Warning: tests/neg/18493.scala:12:9 ---------------------------------------------------
12 | case "abc" => // warn
| ^^^^^
| Unreachable case
No warnings can be incurred under -Werror.
7 changes: 4 additions & 3 deletions tests/neg/18493.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ object PartialFunctionNoWarning {
// nice warning
"abc" match {
case "abc" =>
case "abc" => // error
case "abc" => // warn
}

// no warnings
val pf: PartialFunction[String, Unit] = {
case "abc" =>
case "abc" => // error
case "abc" => // warn
}
}
}
// nopos-error: No warnings can be incurred under -Werror.
4 changes: 3 additions & 1 deletion tests/neg/IsInstanceOfClassTag2.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ object IsInstanceOfClassTag {
}

def main(args: Array[String]): Unit = {
safeCast[List[String]](List[Int](1)) match { // error
safeCast[List[String]](List[Int](1)) match { // warn
case None =>
case Some(xs) =>
}
Expand All @@ -22,3 +22,5 @@ object IsInstanceOfClassTag {
}
}
}

// nopos-error: No warnings can be incurred under -Werror.
Loading

0 comments on commit dd9808a

Please sign in to comment.