From 1e740e2dffd2822c7c0910f237b3ef1390049f69 Mon Sep 17 00:00:00 2001 From: Szymon Rodziewicz Date: Fri, 12 Jan 2024 14:34:12 +0100 Subject: [PATCH] Review fixes --- tests/neg-deep-subtype/1828.scala | 11 ---- tests/neg-deep-subtype/3324b.scala | 11 ---- tests/neg-deep-subtype/3324f.scala | 11 ---- tests/neg-deep-subtype/3324g.scala | 21 ------- tests/neg-deep-subtype/JavaSeqLiteral.scala | 31 ---------- .../conditionalWarnings.scala | 15 ----- tests/neg-deep-subtype/gadt.scala | 15 ----- tests/neg-deep-subtype/html.scala | 20 ------- tests/neg-deep-subtype/or-type-trees.scala | 40 ------------- tests/neg-deep-subtype/refined-types.scala | 24 -------- tests/neg-deep-subtype/t2755.scala | 60 ------------------- tests/neg-deep-subtype/type-lambda.scala | 16 ----- tests/warn/opaque-match.scala | 2 +- 13 files changed, 1 insertion(+), 276 deletions(-) delete mode 100644 tests/neg-deep-subtype/1828.scala delete mode 100644 tests/neg-deep-subtype/3324b.scala delete mode 100644 tests/neg-deep-subtype/3324f.scala delete mode 100644 tests/neg-deep-subtype/3324g.scala delete mode 100644 tests/neg-deep-subtype/JavaSeqLiteral.scala delete mode 100644 tests/neg-deep-subtype/conditionalWarnings.scala delete mode 100644 tests/neg-deep-subtype/gadt.scala delete mode 100644 tests/neg-deep-subtype/html.scala delete mode 100644 tests/neg-deep-subtype/or-type-trees.scala delete mode 100644 tests/neg-deep-subtype/refined-types.scala delete mode 100644 tests/neg-deep-subtype/t2755.scala delete mode 100644 tests/neg-deep-subtype/type-lambda.scala diff --git a/tests/neg-deep-subtype/1828.scala b/tests/neg-deep-subtype/1828.scala deleted file mode 100644 index ae228a83e898..000000000000 --- a/tests/neg-deep-subtype/1828.scala +++ /dev/null @@ -1,11 +0,0 @@ -//> using options -Xfatal-warnings - -class Test { - def remove[S](a: S | Int, f: Int => S):S = a match { - case a: S => a // error - case a: Int => f(a) - } - - val t: Int | String = 5 - val t1 = remove[String](t, _.toString) -} diff --git a/tests/neg-deep-subtype/3324b.scala b/tests/neg-deep-subtype/3324b.scala deleted file mode 100644 index df0cc5432eff..000000000000 --- a/tests/neg-deep-subtype/3324b.scala +++ /dev/null @@ -1,11 +0,0 @@ -//> using options -Xfatal-warnings - -class C[T] { - val x: Any = ??? - if (x.isInstanceOf[List[String]]) // error: unchecked - if (x.isInstanceOf[T]) // error: unchecked - x match { - case x: List[String] => // error: unchecked - case x: T => // error: unchecked - } -} diff --git a/tests/neg-deep-subtype/3324f.scala b/tests/neg-deep-subtype/3324f.scala deleted file mode 100644 index 445da5cb25a0..000000000000 --- a/tests/neg-deep-subtype/3324f.scala +++ /dev/null @@ -1,11 +0,0 @@ -//> using options -Xfatal-warnings - -trait C[T] -class D[T] - -class Test { - def foo[T](x: C[T]) = x match { - case _: D[T] => // error - case _: C[Int] => // error - } -} \ No newline at end of file diff --git a/tests/neg-deep-subtype/3324g.scala b/tests/neg-deep-subtype/3324g.scala deleted file mode 100644 index a5b842e4e450..000000000000 --- a/tests/neg-deep-subtype/3324g.scala +++ /dev/null @@ -1,21 +0,0 @@ -//> using options -Xfatal-warnings - -class Test { - trait A[+T] - class B[T] extends A[T] - class C[T] extends B[Any] with A[T] - - def foo[T](c: C[T]): Unit = c match { - case _: B[T] => // error - } - - 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!! - } - - quux(new C[Int]) -} diff --git a/tests/neg-deep-subtype/JavaSeqLiteral.scala b/tests/neg-deep-subtype/JavaSeqLiteral.scala deleted file mode 100644 index 6003731ae657..000000000000 --- a/tests/neg-deep-subtype/JavaSeqLiteral.scala +++ /dev/null @@ -1,31 +0,0 @@ -//> using options -Xfatal-warnings - -object Test1 { - trait Tree[-T] - - class JavaSeqLiteral[T] extends Tree[T] - - trait Type - - class DummyTree extends JavaSeqLiteral[Any] - - def foo1(tree: Tree[Type]) = - tree.isInstanceOf[JavaSeqLiteral[Type]] // error - - foo1(new DummyTree) -} - -object Test2 { - trait Tree[-T] - - class JavaSeqLiteral[-T] extends Tree[T] - - trait Type - - class DummyTree extends JavaSeqLiteral[Any] - - def foo1(tree: Tree[Type]) = - tree.isInstanceOf[JavaSeqLiteral[Type]] - - foo1(new DummyTree) -} \ No newline at end of file diff --git a/tests/neg-deep-subtype/conditionalWarnings.scala b/tests/neg-deep-subtype/conditionalWarnings.scala deleted file mode 100644 index c4757cbb7546..000000000000 --- a/tests/neg-deep-subtype/conditionalWarnings.scala +++ /dev/null @@ -1,15 +0,0 @@ -//> using options -deprecation -Xfatal-warnings - -object Test { - @deprecated def foo = ??? - - given Conversion[String, Int] = _.length - - foo // error - - 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 -} diff --git a/tests/neg-deep-subtype/gadt.scala b/tests/neg-deep-subtype/gadt.scala deleted file mode 100644 index 661c04fef373..000000000000 --- a/tests/neg-deep-subtype/gadt.scala +++ /dev/null @@ -1,15 +0,0 @@ -//> using options -Xfatal-warnings - -class Test { - trait A[+T] - class B[T] extends A[T] - - class C - class D extends C - - def quux(a: A[C]): Unit = a match { - case _: B[C] => // error!! - } - - quux(new B[D]) -} \ No newline at end of file diff --git a/tests/neg-deep-subtype/html.scala b/tests/neg-deep-subtype/html.scala deleted file mode 100644 index f17cfb661505..000000000000 --- a/tests/neg-deep-subtype/html.scala +++ /dev/null @@ -1,20 +0,0 @@ -//> using options -Xfatal-warnings - -object HTML: - type AttrArg = AppliedAttr | Seq[AppliedAttr] - opaque type AppliedAttr = String - opaque type AppliedTag = StringBuilder - - case class Tag(name: String): - def apply(attrs: AttrArg*): AppliedTag = { - val sb = StringBuilder() - sb.append(s"<$name") - attrs.filter(_ != Nil).foreach{ - case s: Seq[AppliedAttr] => - s.foreach(sb.append(" ").append) - case s: Seq[Int] => // error - case e: AppliedAttr => - sb.append(" ").append(e) - } - sb - } diff --git a/tests/neg-deep-subtype/or-type-trees.scala b/tests/neg-deep-subtype/or-type-trees.scala deleted file mode 100644 index d0338ffe6066..000000000000 --- a/tests/neg-deep-subtype/or-type-trees.scala +++ /dev/null @@ -1,40 +0,0 @@ -//> using options -Xfatal-warnings - -object Test1 { - trait Tree - trait Context - - def foo1(myTree: Tree | (Context => Tree)) = - println(myTree.isInstanceOf[Tree]) - - def foo2(myTree: Tree | (Context => Tree)) = - myTree match - case treeFn: (Context => Tree) => // error - case _ => - - def foo3(myTree: Tree | (Context => Tree)) = - myTree match - case treeFn: (? => ?) => // ok - case _ => -} - -object Test2 { - trait Tree[-T] - trait Context - - trait Type - - def foo1(myTree: Tree[Type] | (Context => Tree[Type])) = - println(myTree.isInstanceOf[Tree[Type]]) // error - /* 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 _ => - - def foo3(myTree: Tree[Type] | (Context => Tree[Type])) = - myTree match - case treeFn: (? => ?) => // ok - case _ => -} \ No newline at end of file diff --git a/tests/neg-deep-subtype/refined-types.scala b/tests/neg-deep-subtype/refined-types.scala deleted file mode 100644 index 5f5cc5a45f04..000000000000 --- a/tests/neg-deep-subtype/refined-types.scala +++ /dev/null @@ -1,24 +0,0 @@ -//> using options -Xfatal-warnings - -class A -class B extends A -type AA = A { type T = Int } -type BA = B { type T = Int } -type AL = A { type T >: Int } -type BL = B { type T >: Int } -type AU = A { type T <: Int } -type BU = B { type T <: Int } - -def aa(x: AA) = x.isInstanceOf[BA] // was: the type test for BA cannot be checked at runtime -def al(x: AL) = x.isInstanceOf[BL] // was: the type test for BL cannot be checked at runtime -def au(x: AU) = x.isInstanceOf[BU] // was: the type test for BU cannot be checked at runtime - -// an alias leaves nothing unchecked when type testing against one bound: -def bl(x: AA) = x.isInstanceOf[BL] // was: the type test for BL cannot be checked at runtime -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 diff --git a/tests/neg-deep-subtype/t2755.scala b/tests/neg-deep-subtype/t2755.scala deleted file mode 100644 index ec3cb6aadefc..000000000000 --- a/tests/neg-deep-subtype/t2755.scala +++ /dev/null @@ -1,60 +0,0 @@ -//> using options -Xfatal-warnings - -// Test cases: the only place we can cut and paste without crying -// ourself to sleep. -object Test { - def f1(a: Any) = a match { - case x: Array[Int] => x(0) - case x: Array[Double] => 2 - case x: Array[Float] => x.sum.toInt - case x: Array[String] => x.size - case x: Array[AnyRef] => 5 - case x: Array[?] => 6 - case _ => 7 - } - def f2(a: Array[?]) = a match { - case x: Array[Int] => x(0) - case x: Array[Double] => 2 - case x: Array[Float] => x.sum.toInt - case x: Array[String] => x.size - case x: Array[AnyRef] => 5 - case x: Array[?] => 6 - case _ => 7 // error: only null is matched - } - def f3[T](a: Array[T]) = a match { - case x: Array[Int] => x(0) - case x: Array[Double] => 2 - case x: Array[Float] => x.sum.toInt - case x: Array[String] => x.size - case x: Array[AnyRef] => 5 - case x: Array[?] => 6 - case _ => 7 // error: only null is matched - } - - - def main(args: Array[String]): Unit = { - println(f1(Array(1, 2, 3))) - println(f1(Array(1.0, -2.0, 3.0, 1.0))) - println(f1(Array(1.0f, 2.0f, 3.0f, -3.0f))) - println(f1((1 to 4).toArray map (_.toString))) - println(f1(new Array[Any](10))) // should match as Array[AnyRef] - println(f1(Array(1L))) - println(f1(null)) - - println(f2(Array(1, 2, 3))) - println(f2(Array(1.0, -2.0, 3.0, 1.0))) - println(f2(Array(1.0f, 2.0f, 3.0f, -3.0f))) - println(f2((1 to 4).toArray map (_.toString))) - println(f2(new Array[Any](10))) // should match as Array[AnyRef] - println(f2(Array(1L))) - println(f2(null)) - - println(f3(Array(1, 2, 3))) - println(f3(Array(1.0, -2.0, 3.0, 1.0))) - println(f3(Array(1.0f, 2.0f, 3.0f, -3.0f))) - println(f3((1 to 4).toArray map (_.toString))) - println(f3(new Array[Any](10))) // should match as Array[AnyRef] - println(f3(Array(1L))) - println(f3(null)) - } -} diff --git a/tests/neg-deep-subtype/type-lambda.scala b/tests/neg-deep-subtype/type-lambda.scala deleted file mode 100644 index 4c4627fe1cf3..000000000000 --- a/tests/neg-deep-subtype/type-lambda.scala +++ /dev/null @@ -1,16 +0,0 @@ -//> using options -Xfatal-warnings - -trait A[T] -trait B[T] extends A[T] - -object Test { - def foo(x: ([X] =>> A[X])[Any]) = x match { - case x: ([X] =>> B[X])[Any] => - case _ => - } - - def bar(x: ([X] =>> A[X])[Any]) = x match { - case x: ([X] =>> B[Nothing])[Any] => // error - case _ => - } -} diff --git a/tests/warn/opaque-match.scala b/tests/warn/opaque-match.scala index 453d525bac2c..06cca835ab91 100644 --- a/tests/warn/opaque-match.scala +++ b/tests/warn/opaque-match.scala @@ -21,4 +21,4 @@ def Test[T] = (??? : Any) match case _: List[O.T @unchecked] => ??? // OK (??? : Any) match - case _: List[T] => ??? // warn \ No newline at end of file + case _: List[T] => ??? // warn