From 5bec32520946c732f525149d224d517534476424 Mon Sep 17 00:00:00 2001 From: Szymon Rodziewicz Date: Mon, 11 Dec 2023 16:42:43 +0100 Subject: [PATCH] Move warn tests from tests/neg to tests/warn: Batch 2 --- tests/neg/14034b.scala | 15 - tests/neg/17284.scala | 14 - tests/neg/18493.check | 8 - tests/neg/adhoc-extension/B.scala | 11 +- tests/neg/avoid-warn-deprecation.scala | 11 - tests/neg/capt-wf.scala | 11 +- .../neg/classtag-typetest/3_1-migration.scala | 3 +- tests/neg/classtag-typetest/3_1.scala | 3 +- tests/neg/i10247.scala | 28 -- tests/neg/i10930.scala | 15 - tests/neg/i10994.scala | 4 - tests/neg/i11022.check | 20 -- tests/neg/i11022.scala | 13 - tests/neg/i11097.scala | 15 - tests/neg/i11225b.check | 6 + tests/neg/i11225b.scala | 3 +- tests/neg/i11333.check | 30 -- tests/neg/i11333.scala | 14 - tests/neg/i11344.scala | 8 - tests/neg/i11963a.scala | 3 - tests/neg/i11963b.scala | 3 - tests/neg/i11963c.scala | 8 - tests/neg/i12188/Test.scala | 6 +- tests/neg/i12253.check | 13 - tests/neg/i12253.scala | 30 -- tests/neg/i12597.scala | 7 - tests/neg/i13011.scala | 23 -- tests/neg/i13440.check | 15 - tests/neg/i13440.scala | 9 - tests/neg/i13542.scala | 52 --- tests/neg/i13946/BadPrinter.scala | 3 +- tests/neg/i14386.scala | 5 +- tests/neg/i14705.scala | 5 - tests/neg/i14721.scala | 9 - tests/neg/i15474.scala | 18 - tests/neg/i15479.scala | 18 - tests/neg/i15503a.scala | 268 --------------- tests/neg/i15503b.scala | 144 -------- tests/neg/i15503c.scala | 57 ---- tests/neg/i15503d.scala | 30 -- tests/neg/i15503e.scala | 71 ---- tests/neg/i15503f.scala | 14 - tests/neg/i15503g.scala | 23 -- tests/neg/i15503h.scala | 20 -- tests/neg/i15503i.scala | 315 ------------------ tests/neg/i15503j.scala | 59 ---- tests/neg/i15662.scala | 16 - tests/neg/i15893.scala | 63 ---- tests/neg/i16639a.scala | 207 ------------ tests/neg/i16649-refutable.check | 8 - tests/neg/i16649-refutable.scala | 9 - tests/neg/i16728.check | 6 - tests/neg/i16728.scala | 34 -- tests/neg/i16876/Test.scala | 5 +- tests/neg/i16930.scala | 22 -- tests/neg/i17266.check | 98 ------ tests/neg/i17266.scala | 144 -------- tests/neg/i17314b.scala | 14 - tests/neg/i17612a.check | 32 -- tests/neg/i17612a.scala | 42 --- tests/neg/i17612b.check | 33 +- tests/neg/i17612b/i17612b.scala | 11 +- tests/neg/i17613a.check | 28 -- tests/neg/i17613a.scala | 23 -- tests/neg/i17613b.check | 67 ++-- tests/neg/i17613b/i17613b.scala | 39 ++- tests/neg/i18722.check | 44 --- tests/neg/i18722.scala | 9 - tests/neg/i18862-3.4.check | 5 - tests/neg/i18862-3.4.scala | 6 - tests/neg/i18862-future-migration.scala | 6 - tests/neg/i18867-3.4.scala | 7 - tests/neg/i18867.check | 6 - tests/neg/i18867.scala | 5 - tests/neg/i2333.scala | 11 - tests/neg/i2673.scala | 6 - tests/neg/i2673b.scala | 6 - tests/neg/i2673c.scala | 8 - tests/neg/i3561.scala | 18 - tests/neg/i4008.check | 40 --- tests/neg/i4008.scala | 50 --- tests/neg/i4364.scala | 11 - tests/neg/i4812.check | 42 --- tests/neg/i4812.scala | 119 ------- tests/neg/i4936b.scala | 3 - tests/neg/i4986b.check | 40 --- tests/neg/i4986b.scala | 22 -- tests/neg/i4986d.scala | 5 +- tests/neg/i5013.scala | 11 - tests/neg/i5013b.scala | 18 - tests/neg/i5077.scala | 33 -- tests/neg/i6190b.check | 4 - tests/neg/i6190b.scala | 5 - tests/neg/i7314.scala | 11 - tests/neg/i7821.scala | 26 -- tests/neg/i7821b.scala | 13 - tests/neg/i8427.scala | 9 - tests/neg/i8681.scala | 3 +- tests/neg/i8711.check | 17 +- tests/neg/i8711.scala | 4 +- tests/neg/i8781b.scala | 7 - tests/neg/i8922b.scala | 78 ----- tests/neg/i9166.scala | 7 - tests/neg/i9241.scala | 43 --- tests/neg/i9266.check | 5 - tests/neg/i9266.scala | 5 - tests/neg/i9408a.check | 24 -- tests/neg/i9408a.scala | 88 ----- tests/neg/i9408b.check | 5 +- tests/neg/i9408b/Test_2.scala | 4 +- tests/neg/i9740.check | 12 - tests/neg/i9740.scala | 17 - tests/neg/i9740b.scala | 20 -- tests/neg/i9740c.scala | 17 - tests/neg/i9740d.scala | 13 - tests/neg/i9751.scala | 11 - tests/neg/i9776.scala | 61 ---- tests/neg/i9880.scala | 32 -- tests/neg/impl-conv/A.scala | 2 +- tests/neg/impl-conv/B.scala | 3 +- tests/neg/implicit-conversions-old.scala | 25 -- tests/neg/implicit-conversions.scala | 31 -- tests/neg/indentLeft.scala | 3 +- tests/neg/indentRight.scala | 14 +- tests/neg/infix.check | 30 ++ tests/neg/infix.scala | 4 +- tests/neg/inline-givens.scala | 16 - tests/neg/main-functions-nameclash.scala | 5 - tests/neg/manifest-summoning-b.scala | 4 - tests/neg/matchable.scala | 29 -- tests/neg/missing-targetName.scala | 7 +- tests/neg/old-syntax.scala | 5 - tests/neg/ovlazy.scala | 8 - tests/neg/private-this-3.4.scala | 7 - tests/neg/private-this-future-migration.scala | 7 - tests/neg/pureStatement.scala | 11 +- tests/neg/quote-simple-hole.scala | 17 - tests/neg/refinements-this.scala | 5 - .../refutable-pattern-binding-messages.check | 12 +- .../refutable-pattern-binding-messages.scala | 8 +- tests/neg/rewrite-messages.scala | 8 - tests/neg/strict-pattern-bindings-3.2.scala | 37 -- tests/neg/structural-2.scala | 3 +- tests/neg/symbolic-packages.scala | 13 - tests/neg/unchecked-patterns.scala | 17 +- tests/neg/warn-value-discard.check | 20 -- .../with-type-operator-future-migration.scala | 5 - tests/warn/14034b.scala | 15 + tests/{neg => warn}/15981.check | 4 +- tests/{neg => warn}/15981.scala | 4 +- tests/{neg => warn}/17284.check | 12 +- tests/warn/17284.scala | 14 + tests/warn/1828.scala | 11 + tests/warn/18493.check | 8 + tests/{neg => warn}/18493.scala | 6 +- tests/warn/3324b.scala | 11 + tests/warn/3324f.scala | 11 + tests/warn/3324g.scala | 21 ++ .../{neg => warn}/IsInstanceOfClassTag2.scala | 5 +- tests/warn/JavaSeqLiteral.scala | 31 ++ tests/warn/avoid-warn-deprecation.scala | 11 + tests/warn/conditionalWarnings.scala | 15 + tests/{neg => warn}/convertible.scala | 11 +- tests/{neg => warn}/deprecated-override.scala | 7 +- tests/{neg => warn}/feature-shadowing.scala | 4 +- .../gadt-contradictory-pattern.scala | 8 +- tests/warn/gadt.scala | 15 + tests/warn/html.scala | 20 ++ tests/warn/main-functions-nameclash.scala | 5 + .../{neg => warn}/manifest-summoning-b.check | 8 +- tests/warn/manifest-summoning-b.scala | 4 + tests/warn/matchable.scala | 28 ++ tests/{neg => warn}/newline-braces.scala | 5 +- tests/{neg => warn}/nonunit-statement.scala | 47 +-- tests/warn/old-syntax.scala | 5 + tests/{neg => warn}/opaque-match.scala | 14 +- tests/warn/or-type-trees.scala | 40 +++ tests/warn/ovlazy.scala | 9 + tests/{neg => warn}/private-this-3.4.check | 8 +- tests/warn/private-this-3.4.scala | 5 + .../warn/private-this-future-migration.scala | 5 + tests/warn/quote-simple-hole.scala | 17 + tests/warn/refined-types.scala | 24 ++ tests/warn/refinements-this.scala | 6 + tests/{neg => warn}/rewrite-messages.check | 8 +- tests/warn/rewrite-messages.scala | 8 + .../scala2-t11681.scala | 11 +- tests/warn/strict-pattern-bindings-3.2.scala | 37 ++ tests/{neg => warn}/supertraits-b.scala | 12 +- tests/{neg => warn}/switches.scala | 16 +- tests/{neg => warn}/symbolic-packages.check | 16 +- tests/warn/symbolic-packages.scala | 13 + tests/warn/t2755.scala | 60 ++++ tests/{neg => warn}/t3235-minimal.check | 16 +- tests/{neg => warn}/t3235-minimal.scala | 12 +- tests/{neg => warn}/t5830.scala | 4 +- tests/warn/type-lambda.scala | 16 + tests/{neg => warn}/type-test-paths-2.scala | 12 +- tests/{neg => warn}/type-test-paths.scala | 4 +- .../{neg => warn}/type-test-syntesize-b.scala | 10 +- tests/{neg => warn}/uninitialized-3.4.check | 4 +- tests/{neg => warn}/uninitialized-3.4.scala | 4 +- .../uninitialized-future-migration.scala | 4 +- tests/warn/warn-value-discard.check | 20 ++ tests/{neg => warn}/warn-value-discard.scala | 14 +- .../wildcard-type-syntax-3.4.scala | 4 +- ...ildcard-type-syntax-future-migration.scala | 4 +- .../with-type-operator-future-migration.check | 4 +- .../with-type-operator-future-migration.scala | 6 + tests/{neg => warn}/xfatalWarnings.scala | 6 +- 210 files changed, 857 insertions(+), 3731 deletions(-) delete mode 100644 tests/neg/14034b.scala delete mode 100644 tests/neg/17284.scala delete mode 100644 tests/neg/18493.check delete mode 100644 tests/neg/avoid-warn-deprecation.scala delete mode 100644 tests/neg/i10247.scala delete mode 100644 tests/neg/i10930.scala delete mode 100644 tests/neg/i10994.scala delete mode 100644 tests/neg/i11022.check delete mode 100644 tests/neg/i11022.scala delete mode 100644 tests/neg/i11097.scala create mode 100644 tests/neg/i11225b.check delete mode 100644 tests/neg/i11333.check delete mode 100644 tests/neg/i11333.scala delete mode 100644 tests/neg/i11344.scala delete mode 100644 tests/neg/i11963a.scala delete mode 100644 tests/neg/i11963b.scala delete mode 100644 tests/neg/i11963c.scala delete mode 100644 tests/neg/i12253.check delete mode 100644 tests/neg/i12253.scala delete mode 100644 tests/neg/i12597.scala delete mode 100644 tests/neg/i13011.scala delete mode 100644 tests/neg/i13440.check delete mode 100644 tests/neg/i13440.scala delete mode 100644 tests/neg/i13542.scala delete mode 100644 tests/neg/i14705.scala delete mode 100644 tests/neg/i14721.scala delete mode 100644 tests/neg/i15474.scala delete mode 100644 tests/neg/i15479.scala delete mode 100644 tests/neg/i15503a.scala delete mode 100644 tests/neg/i15503b.scala delete mode 100644 tests/neg/i15503c.scala delete mode 100644 tests/neg/i15503d.scala delete mode 100644 tests/neg/i15503e.scala delete mode 100644 tests/neg/i15503f.scala delete mode 100644 tests/neg/i15503g.scala delete mode 100644 tests/neg/i15503h.scala delete mode 100644 tests/neg/i15503i.scala delete mode 100644 tests/neg/i15503j.scala delete mode 100644 tests/neg/i15662.scala delete mode 100644 tests/neg/i15893.scala delete mode 100644 tests/neg/i16639a.scala delete mode 100644 tests/neg/i16649-refutable.check delete mode 100644 tests/neg/i16649-refutable.scala delete mode 100644 tests/neg/i16728.check delete mode 100644 tests/neg/i16728.scala delete mode 100644 tests/neg/i16930.scala delete mode 100644 tests/neg/i17266.check delete mode 100644 tests/neg/i17266.scala delete mode 100644 tests/neg/i17314b.scala delete mode 100644 tests/neg/i17612a.check delete mode 100644 tests/neg/i17612a.scala delete mode 100644 tests/neg/i17613a.check delete mode 100644 tests/neg/i17613a.scala delete mode 100644 tests/neg/i18722.check delete mode 100644 tests/neg/i18722.scala delete mode 100644 tests/neg/i18862-3.4.check delete mode 100644 tests/neg/i18862-3.4.scala delete mode 100644 tests/neg/i18862-future-migration.scala delete mode 100644 tests/neg/i18867-3.4.scala delete mode 100644 tests/neg/i18867.check delete mode 100644 tests/neg/i18867.scala delete mode 100644 tests/neg/i2333.scala delete mode 100644 tests/neg/i2673.scala delete mode 100644 tests/neg/i2673b.scala delete mode 100644 tests/neg/i2673c.scala delete mode 100644 tests/neg/i3561.scala delete mode 100644 tests/neg/i4008.check delete mode 100644 tests/neg/i4008.scala delete mode 100644 tests/neg/i4364.scala delete mode 100644 tests/neg/i4812.check delete mode 100644 tests/neg/i4812.scala delete mode 100644 tests/neg/i4936b.scala delete mode 100644 tests/neg/i4986b.check delete mode 100644 tests/neg/i4986b.scala delete mode 100644 tests/neg/i5013.scala delete mode 100644 tests/neg/i5013b.scala delete mode 100644 tests/neg/i5077.scala delete mode 100644 tests/neg/i6190b.check delete mode 100644 tests/neg/i6190b.scala delete mode 100644 tests/neg/i7314.scala delete mode 100644 tests/neg/i7821.scala delete mode 100644 tests/neg/i7821b.scala delete mode 100644 tests/neg/i8427.scala delete mode 100644 tests/neg/i8781b.scala delete mode 100644 tests/neg/i8922b.scala delete mode 100644 tests/neg/i9166.scala delete mode 100644 tests/neg/i9241.scala delete mode 100644 tests/neg/i9266.check delete mode 100644 tests/neg/i9266.scala delete mode 100644 tests/neg/i9408a.check delete mode 100644 tests/neg/i9408a.scala delete mode 100644 tests/neg/i9740.check delete mode 100644 tests/neg/i9740.scala delete mode 100644 tests/neg/i9740b.scala delete mode 100644 tests/neg/i9740c.scala delete mode 100644 tests/neg/i9740d.scala delete mode 100644 tests/neg/i9751.scala delete mode 100644 tests/neg/i9776.scala delete mode 100644 tests/neg/i9880.scala delete mode 100644 tests/neg/implicit-conversions-old.scala delete mode 100644 tests/neg/implicit-conversions.scala create mode 100644 tests/neg/infix.check delete mode 100644 tests/neg/inline-givens.scala delete mode 100644 tests/neg/main-functions-nameclash.scala delete mode 100644 tests/neg/manifest-summoning-b.scala delete mode 100644 tests/neg/matchable.scala delete mode 100644 tests/neg/old-syntax.scala delete mode 100644 tests/neg/ovlazy.scala delete mode 100644 tests/neg/private-this-3.4.scala delete mode 100644 tests/neg/private-this-future-migration.scala delete mode 100644 tests/neg/quote-simple-hole.scala delete mode 100644 tests/neg/refinements-this.scala delete mode 100644 tests/neg/rewrite-messages.scala delete mode 100644 tests/neg/strict-pattern-bindings-3.2.scala delete mode 100644 tests/neg/symbolic-packages.scala delete mode 100644 tests/neg/warn-value-discard.check delete mode 100644 tests/neg/with-type-operator-future-migration.scala create mode 100644 tests/warn/14034b.scala rename tests/{neg => warn}/15981.check (68%) rename tests/{neg => warn}/15981.scala (76%) rename tests/{neg => warn}/17284.check (86%) create mode 100644 tests/warn/17284.scala create mode 100644 tests/warn/1828.scala create mode 100644 tests/warn/18493.check rename tests/{neg => warn}/18493.scala (68%) create mode 100644 tests/warn/3324b.scala create mode 100644 tests/warn/3324f.scala create mode 100644 tests/warn/3324g.scala rename tests/{neg => warn}/IsInstanceOfClassTag2.scala (80%) create mode 100644 tests/warn/JavaSeqLiteral.scala create mode 100644 tests/warn/avoid-warn-deprecation.scala create mode 100644 tests/warn/conditionalWarnings.scala rename tests/{neg => warn}/convertible.scala (60%) rename tests/{neg => warn}/deprecated-override.scala (52%) rename tests/{neg => warn}/feature-shadowing.scala (77%) rename tests/{neg => warn}/gadt-contradictory-pattern.scala (54%) create mode 100644 tests/warn/gadt.scala create mode 100644 tests/warn/html.scala create mode 100644 tests/warn/main-functions-nameclash.scala rename tests/{neg => warn}/manifest-summoning-b.check (73%) create mode 100644 tests/warn/manifest-summoning-b.scala create mode 100644 tests/warn/matchable.scala rename tests/{neg => warn}/newline-braces.scala (55%) rename tests/{neg => warn}/nonunit-statement.scala (80%) create mode 100644 tests/warn/old-syntax.scala rename tests/{neg => warn}/opaque-match.scala (63%) create mode 100644 tests/warn/or-type-trees.scala create mode 100644 tests/warn/ovlazy.scala rename tests/{neg => warn}/private-this-3.4.check (74%) create mode 100644 tests/warn/private-this-3.4.scala create mode 100644 tests/warn/private-this-future-migration.scala create mode 100644 tests/warn/quote-simple-hole.scala create mode 100644 tests/warn/refined-types.scala create mode 100644 tests/warn/refinements-this.scala rename tests/{neg => warn}/rewrite-messages.check (76%) create mode 100644 tests/warn/rewrite-messages.scala rename tests/{neg/i15503-scala2 => warn}/scala2-t11681.scala (90%) create mode 100644 tests/warn/strict-pattern-bindings-3.2.scala rename tests/{neg => warn}/supertraits-b.scala (69%) rename tests/{neg => warn}/switches.scala (77%) rename tests/{neg => warn}/symbolic-packages.check (65%) create mode 100644 tests/warn/symbolic-packages.scala create mode 100644 tests/warn/t2755.scala rename tests/{neg => warn}/t3235-minimal.check (75%) rename tests/{neg => warn}/t3235-minimal.scala (51%) rename tests/{neg => warn}/t5830.scala (63%) create mode 100644 tests/warn/type-lambda.scala rename tests/{neg => warn}/type-test-paths-2.scala (61%) rename tests/{neg => warn}/type-test-paths.scala (88%) rename tests/{neg => warn}/type-test-syntesize-b.scala (74%) rename tests/{neg => warn}/uninitialized-3.4.check (75%) rename tests/{neg => warn}/uninitialized-3.4.scala (60%) rename tests/{neg => warn}/uninitialized-future-migration.scala (62%) create mode 100644 tests/warn/warn-value-discard.check rename tests/{neg => warn}/warn-value-discard.scala (84%) rename tests/{neg => warn}/wildcard-type-syntax-3.4.scala (52%) rename tests/{neg => warn}/wildcard-type-syntax-future-migration.scala (53%) rename tests/{neg => warn}/with-type-operator-future-migration.check (61%) create mode 100644 tests/warn/with-type-operator-future-migration.scala rename tests/{neg => warn}/xfatalWarnings.scala (69%) diff --git a/tests/neg/14034b.scala b/tests/neg/14034b.scala deleted file mode 100644 index 84f9ab3579c8..000000000000 --- a/tests/neg/14034b.scala +++ /dev/null @@ -1,15 +0,0 @@ -//> using options -Xfatal-warnings -deprecation - -@deprecated trait Exp -@deprecated val exp = 1 - -def test1 = exp // error -def test2(a: Exp) = () // error - -type Foo0 = Exp // error -type Foo = Option[Exp] // error -type Bar = Option[exp.type] // error -type Baz = Exp | Int // error -type Quux = [X] =>> X match - case Exp => Int // error -type Quuz[A <: Exp] = Int // error diff --git a/tests/neg/17284.scala b/tests/neg/17284.scala deleted file mode 100644 index 8f588233245a..000000000000 --- a/tests/neg/17284.scala +++ /dev/null @@ -1,14 +0,0 @@ -//> using options -Werror -explain - -def test = - 451.synchronized {} // error - -def test2 = - val x: Integer = 451 - x.synchronized {} // error - -def test3 = - true.synchronized {} // error - -def test4 = - true.hashCode() // success diff --git a/tests/neg/18493.check b/tests/neg/18493.check deleted file mode 100644 index 79a2872e71e8..000000000000 --- a/tests/neg/18493.check +++ /dev/null @@ -1,8 +0,0 @@ --- [E030] Match case Unreachable Error: tests/neg/18493.scala:6:9 ------------------------------------------------------ -6 | case "abc" => // error - | ^^^^^ - | Unreachable case --- [E030] Match case Unreachable Error: tests/neg/18493.scala:12:9 ----------------------------------------------------- -12 | case "abc" => // error - | ^^^^^ - | Unreachable case diff --git a/tests/neg/adhoc-extension/B.scala b/tests/neg/adhoc-extension/B.scala index 2343a9bc0060..efa783f87178 100644 --- a/tests/neg/adhoc-extension/B.scala +++ b/tests/neg/adhoc-extension/B.scala @@ -1,10 +1,11 @@ //> using options -source future -feature -Xfatal-warnings package adhoc -class B extends A // error: adhoc-extension (under -strict -feature -Xfatal-warnings) -class C extends A // error +class B extends A // warn: adhoc-extension (under -strict -feature -Xfatal-warnings) +class C extends A // warn object O { - val a = new A {} // error - object E extends A // error -} \ No newline at end of file + val a = new A {} // warn + object E extends A // warn +} +// nopos-error: No warnings can be incurred under -Werror. \ No newline at end of file diff --git a/tests/neg/avoid-warn-deprecation.scala b/tests/neg/avoid-warn-deprecation.scala deleted file mode 100644 index 45baf7addb86..000000000000 --- a/tests/neg/avoid-warn-deprecation.scala +++ /dev/null @@ -1,11 +0,0 @@ -//> using options -Xfatal-warnings -feature - -object A { - @deprecated("use bar instead of this one", "0.2.3") - def foo: Int = 3 -} - -object B { - A.foo -} -// nopos-error there was 1 deprecation warning; re-run with -deprecation for details diff --git a/tests/neg/capt-wf.scala b/tests/neg/capt-wf.scala index fbd334726e55..61dde899a585 100644 --- a/tests/neg/capt-wf.scala +++ b/tests/neg/capt-wf.scala @@ -13,12 +13,12 @@ def test(c: Cap, other: String): Unit = val x3a: () -> String = s1 val s2 = () => if x1 == null then "" else "abc" val x4: C^{s2} = ??? // OK - val x5: C^{c, c} = ??? // error: redundant // error: redundant + val x5: C^{c, c} = ??? // warn: redundant // warn: redundant // val x6: C^{c}^{c} = ??? // would be syntax error - val x7: Cap^{c} = ??? // error: redundant + val x7: Cap^{c} = ??? // warn: redundant // val x8: C^{c}^{cap} = ??? // would be syntax error - val x9: C^{c, cap} = ??? // error: redundant - val x10: C^{cap, c} = ??? // error: redundant + val x9: C^{c, cap} = ??? // warn: redundant + val x10: C^{cap, c} = ??? // warn: redundant def even(n: Int): Boolean = if n == 0 then true else odd(n - 1) def odd(n: Int): Boolean = if n == 1 then true else even(n - 1) @@ -34,4 +34,5 @@ def test(c: Cap, other: String): Unit = if n == 0 then true else od(n - 1) val y3: String^{ev} = ??? // error cs is empty - () \ No newline at end of file + () +// nopos-error: No warnings can be incurred under -Werror. \ No newline at end of file diff --git a/tests/neg/classtag-typetest/3_1-migration.scala b/tests/neg/classtag-typetest/3_1-migration.scala index 41e0537a6dc1..fb8f3beedc48 100644 --- a/tests/neg/classtag-typetest/3_1-migration.scala +++ b/tests/neg/classtag-typetest/3_1-migration.scala @@ -5,4 +5,5 @@ import scala.reflect.ClassTag def f3_1m[T: ClassTag](x: Any): Unit = x match - case _: T => // error + case _: T => // warn +// nopos-error: No warnings can be incurred under -Werror. diff --git a/tests/neg/classtag-typetest/3_1.scala b/tests/neg/classtag-typetest/3_1.scala index d9101ff2ae57..798489bb90fa 100644 --- a/tests/neg/classtag-typetest/3_1.scala +++ b/tests/neg/classtag-typetest/3_1.scala @@ -5,4 +5,5 @@ import scala.reflect.ClassTag def f3_1[T: ClassTag](x: Any): Unit = x match - case _: T => // error + case _: T => // warn +// nopos-error: No warnings can be incurred under -Werror. diff --git a/tests/neg/i10247.scala b/tests/neg/i10247.scala deleted file mode 100644 index fc6268720a6d..000000000000 --- a/tests/neg/i10247.scala +++ /dev/null @@ -1,28 +0,0 @@ -//> using options -Xfatal-warnings -deprecation - -def usered = Color.Red // error: value Red is deprecated - -object DeprecatedContainer { - @deprecated("no foo", "0.1") val foo = 23 -} - -enum Day { - - @deprecated("no more Mondays!", "0.1") case Monday - -} - -enum Color { - - @deprecated("no Red", "0.1") case Red - - @deprecated("no Generic", "0.1") case Generic(rgb: Int) - - def useFoo1 = DeprecatedContainer.foo // error // check that only enum cases are avoided - def useMonday = Day.Monday // error // check that enum cases are declared in this enum - -} - -object Color { - def useFoo2 = DeprecatedContainer.foo // error // check that only enum cases are avoided -} diff --git a/tests/neg/i10930.scala b/tests/neg/i10930.scala deleted file mode 100644 index 5f8a0ca1ba76..000000000000 --- a/tests/neg/i10930.scala +++ /dev/null @@ -1,15 +0,0 @@ -//> using options -Xfatal-warnings - -import language.future -@main def Test = - type LeafElem[X] = X match - case String => Char - case Array[t] => LeafElem[t] - case Iterable[t] => LeafElem[t] - case AnyVal => X - - def leafElem[X](x: X): LeafElem[X] = x match - case x: String => x.charAt(0) // error - case x: Array[t] => leafElem(x(1)) // error - case x: Iterable[t] => leafElem(x.head) // error - case x: AnyVal => x // error diff --git a/tests/neg/i10994.scala b/tests/neg/i10994.scala deleted file mode 100644 index f5f237f22dd6..000000000000 --- a/tests/neg/i10994.scala +++ /dev/null @@ -1,4 +0,0 @@ -//> using options -Xfatal-warnings - -def foo = true match - case (b: Boolean): Boolean => () // error diff --git a/tests/neg/i11022.check b/tests/neg/i11022.check deleted file mode 100644 index 55bdb0526264..000000000000 --- a/tests/neg/i11022.check +++ /dev/null @@ -1,20 +0,0 @@ --- Error: tests/neg/i11022.scala:10:7 ---------------------------------------------------------------------------------- -10 |val a: CaseClass = CaseClass(42) // error: deprecated type // error: deprecated apply method - | ^^^^^^^^^ - | class CaseClass is deprecated: no CaseClass --- Error: tests/neg/i11022.scala:10:19 --------------------------------------------------------------------------------- -10 |val a: CaseClass = CaseClass(42) // error: deprecated type // error: deprecated apply method - | ^^^^^^^^^ - | class CaseClass is deprecated: no CaseClass --- Error: tests/neg/i11022.scala:11:7 ---------------------------------------------------------------------------------- -11 |val b: CaseClass = new CaseClass(42) // error: deprecated type // error: deprecated class - | ^^^^^^^^^ - | class CaseClass is deprecated: no CaseClass --- Error: tests/neg/i11022.scala:11:23 --------------------------------------------------------------------------------- -11 |val b: CaseClass = new CaseClass(42) // error: deprecated type // error: deprecated class - | ^^^^^^^^^ - | class CaseClass is deprecated: no CaseClass --- Error: tests/neg/i11022.scala:12:14 --------------------------------------------------------------------------------- -12 |val c: Unit = CaseClass(42).magic() // error: deprecated apply method - | ^^^^^^^^^ - | class CaseClass is deprecated: no CaseClass diff --git a/tests/neg/i11022.scala b/tests/neg/i11022.scala deleted file mode 100644 index 14bc600666f9..000000000000 --- a/tests/neg/i11022.scala +++ /dev/null @@ -1,13 +0,0 @@ -//> using options -Xfatal-warnings -deprecation - -@deprecated("no CaseClass") -case class CaseClass(rgb: Int): - def magic(): Unit = () - -object CaseClass: - def notDeprecated(): Unit = () - -val a: CaseClass = CaseClass(42) // error: deprecated type // error: deprecated apply method -val b: CaseClass = new CaseClass(42) // error: deprecated type // error: deprecated class -val c: Unit = CaseClass(42).magic() // error: deprecated apply method -val d: Unit = CaseClass.notDeprecated() // compiles diff --git a/tests/neg/i11097.scala b/tests/neg/i11097.scala deleted file mode 100644 index 149fe89249c8..000000000000 --- a/tests/neg/i11097.scala +++ /dev/null @@ -1,15 +0,0 @@ -//> using options -Xfatal-warnings - -@main def test: Unit = { - class C { type T1; type T2 } - - def pmatch(s: C): s.T2 = s match { - case p: (C { type T1 = Int; type T2 >: T1 } & s.type) => // error - (3: p.T1): p.T2 - case p: (C { type T1 = String; type T2 >: T1 } & s.type) => // error - ("this branch should be matched": p.T1): p.T2 - } - - // ClassCastException: class java.lang.Integer cannot be cast to class java.lang.String - val x = pmatch(new C { type T1 = String; type T2 = String }) -} \ No newline at end of file diff --git a/tests/neg/i11225b.check b/tests/neg/i11225b.check new file mode 100644 index 000000000000..12ec80515e6f --- /dev/null +++ b/tests/neg/i11225b.check @@ -0,0 +1,6 @@ +-- Error: tests/neg/i11225b.scala:6:26 --------------------------------------------------------------------------------- +6 | private var cached: A = _ // error + | ^ + | `= _` has been deprecated; use `= uninitialized` instead. + | `uninitialized` can be imported with `scala.compiletime.uninitialized`. + | This construct can be rewritten automatically under -rewrite -source 3.4-migration. diff --git a/tests/neg/i11225b.scala b/tests/neg/i11225b.scala index a9dd1d3d2227..c2b94571e06c 100644 --- a/tests/neg/i11225b.scala +++ b/tests/neg/i11225b.scala @@ -1,4 +1,4 @@ -//> using options -source future -deprecation -Xfatal-warnings +//> using options -source future -deprecation import compiletime.uninitialized @@ -10,3 +10,4 @@ class Memo[A](x: => A): known = true cached = x cached + diff --git a/tests/neg/i11333.check b/tests/neg/i11333.check deleted file mode 100644 index ba5723488899..000000000000 --- a/tests/neg/i11333.check +++ /dev/null @@ -1,30 +0,0 @@ --- [E167] Lossy Conversion Error: tests/neg/i11333.scala:4:19 ---------------------------------------------------------- -4 | val f1: Float = 123456789 // error - | ^^^^^^^^^ - | Widening conversion from Int to Float loses precision. - | Write `.toFloat` instead. --- [E167] Lossy Conversion Error: tests/neg/i11333.scala:5:19 ---------------------------------------------------------- -5 | val d1: Double = 1234567890123456789L // error - | ^^^^^^^^^^^^^^^^^^^^ - | Widening conversion from Long to Double loses precision. - | Write `.toDouble` instead. --- [E167] Lossy Conversion Error: tests/neg/i11333.scala:6:19 ---------------------------------------------------------- -6 | val f2: Float = 123456789L // error - | ^^^^^^^^^^ - | Widening conversion from Long to Float loses precision. - | Write `.toFloat` instead. --- [E167] Lossy Conversion Error: tests/neg/i11333.scala:12:21 --------------------------------------------------------- -12 | val f1_b: Float = i1 // error - | ^^ - | Widening conversion from Int to Float loses precision. - | Write `.toFloat` instead. --- [E167] Lossy Conversion Error: tests/neg/i11333.scala:13:21 --------------------------------------------------------- -13 | val d1_b: Double = l1 // error - | ^^ - | Widening conversion from Long to Double loses precision. - | Write `.toDouble` instead. --- [E167] Lossy Conversion Error: tests/neg/i11333.scala:14:21 --------------------------------------------------------- -14 | val f2_b: Float = l2 // error - | ^^ - | Widening conversion from Long to Float loses precision. - | Write `.toFloat` instead. diff --git a/tests/neg/i11333.scala b/tests/neg/i11333.scala deleted file mode 100644 index bbdcceaf7e1e..000000000000 --- a/tests/neg/i11333.scala +++ /dev/null @@ -1,14 +0,0 @@ -//> using options -Xfatal-warnings - -class C: - val f1: Float = 123456789 // error - val d1: Double = 1234567890123456789L // error - val f2: Float = 123456789L // error - - inline val i1 = 123456789 - inline val l1 = 1234567890123456789L - inline val l2 = 123456789L - - val f1_b: Float = i1 // error - val d1_b: Double = l1 // error - val f2_b: Float = l2 // error diff --git a/tests/neg/i11344.scala b/tests/neg/i11344.scala deleted file mode 100644 index 0602fe14a995..000000000000 --- a/tests/neg/i11344.scala +++ /dev/null @@ -1,8 +0,0 @@ -//> using options -Xfatal-warnings -deprecation - -trait Pet(val name: String, rest: Int): - def f(suffix: String) = s"$name$suffix$rest" - -class Birdie(override val name: String) extends Pet("huh", 1) // error - - diff --git a/tests/neg/i11963a.scala b/tests/neg/i11963a.scala deleted file mode 100644 index 0eb2f557624f..000000000000 --- a/tests/neg/i11963a.scala +++ /dev/null @@ -1,3 +0,0 @@ -//> using options -Xfatal-warnings - -open trait Foo // error diff --git a/tests/neg/i11963b.scala b/tests/neg/i11963b.scala deleted file mode 100644 index 76097b225896..000000000000 --- a/tests/neg/i11963b.scala +++ /dev/null @@ -1,3 +0,0 @@ -//> using options -Xfatal-warnings - -open abstract class Foo // error diff --git a/tests/neg/i11963c.scala b/tests/neg/i11963c.scala deleted file mode 100644 index f58f68c72368..000000000000 --- a/tests/neg/i11963c.scala +++ /dev/null @@ -1,8 +0,0 @@ -//> using options -Xfatal-warnings - -object Test { - def foo: Any = { - open class Bar // error - new Bar - } -} diff --git a/tests/neg/i12188/Test.scala b/tests/neg/i12188/Test.scala index 66864438694e..9bbbf6431b13 100644 --- a/tests/neg/i12188/Test.scala +++ b/tests/neg/i12188/Test.scala @@ -7,5 +7,7 @@ case class PC2(b: Int) extends P def Test = MatchTest.test(PC2(10): P) def foo(x: P): Unit = - x match // error - case _: PC1 => \ No newline at end of file + x match // warn + case _: PC1 => + +// nopos-error: No warnings can be incurred under -Werror. \ No newline at end of file diff --git a/tests/neg/i12253.check b/tests/neg/i12253.check deleted file mode 100644 index 75a698249dee..000000000000 --- a/tests/neg/i12253.check +++ /dev/null @@ -1,13 +0,0 @@ --- [E092] Pattern Match Error: tests/neg/i12253.scala:13:10 ------------------------------------------------------------ -13 | case extractors.InlinedLambda(_, Select(_, name)) => Expr(name) // error // error - | ^ - |the type test for extractors.q2.reflect.Term cannot be checked at runtime because it refers to an abstract type member or type parameter - | - | longer explanation available when compiling with `-explain` --- [E092] Pattern Match Error: tests/neg/i12253.scala:13:38 ------------------------------------------------------------ -13 | case extractors.InlinedLambda(_, Select(_, name)) => Expr(name) // error // error - | ^ - |the type test for q1.reflect.Select cannot be checked at runtime because it refers to an abstract type member or type parameter - | - | longer explanation available when compiling with `-explain` -there was 1 deprecation warning; re-run with -deprecation for details diff --git a/tests/neg/i12253.scala b/tests/neg/i12253.scala deleted file mode 100644 index 540ff8ef6d5b..000000000000 --- a/tests/neg/i12253.scala +++ /dev/null @@ -1,30 +0,0 @@ -//> using options -Xfatal-warnings - -import scala.quoted.{given, *} -import deriving.*, compiletime.* - -object MacroUtils: - transparent inline def extractNameFromSelector[To, T](inline code: To => T) = ${extractNameFromSelectorImpl('code)} - - def extractNameFromSelectorImpl[To: Type, T: Type](code: Expr[To => T])(using q1: Quotes): Expr[String] = - import quotes.reflect.* - val extractors = new Extractors - code.asTerm match - case extractors.InlinedLambda(_, Select(_, name)) => Expr(name) // error // error - case t => report.throwError(s"Illegal argument to extractor: ${code.show}, in tasty: $t") - - class Extractors(using val q2: Quotes): - //attempt to strip away consecutive inlines in AST and extract only final lambda - import quotes.reflect.* - - object InlinedLambda: - def unapply(arg: Term): Option[(List[ValDef], Term)] = - arg match - case Inlined(_, _, Lambda(vals, term)) => Some((vals, term)) - case Inlined(_, _, nested) => InlinedLambda.unapply(nested) - case t => None - end InlinedLambda - - end Extractors -end MacroUtils -// nopos-error diff --git a/tests/neg/i12597.scala b/tests/neg/i12597.scala deleted file mode 100644 index b8859a0ae991..000000000000 --- a/tests/neg/i12597.scala +++ /dev/null @@ -1,7 +0,0 @@ -//> using options -Xfatal-warnings -deprecation - -@main def Test = - val a: IArray[Int] = IArray(2) - val b: IArray[Any] = a - val c = b.toArray // error: deprecated - c(0) = "" diff --git a/tests/neg/i13011.scala b/tests/neg/i13011.scala deleted file mode 100644 index c0541aeb7f8e..000000000000 --- a/tests/neg/i13011.scala +++ /dev/null @@ -1,23 +0,0 @@ -//> using options -Xfatal-warnings - -class i13011 { - lazy implicit val simple1: String = simple1 // error - def f: Unit = { - lazy val simple2: String = simple2 // error - } - - lazy val simple3: String = if true then this.simple3 else "a" // error - - def firstDigitIsEven(n: Int): Boolean = if n % 10 == n then n % 2 == 0 else firstDigitIsEven(n / 10) - - lazy val simple4: String = if firstDigitIsEven(22) then this.simple4 else "a" // ok - - lazy val simple5: String = identity(this.simple5) // error - - lazy val simple6: String = { // error - this.simple6 - "aa" - } - - lazy val simple7: Function0[Any] = () => this.simple7 // Ok -} diff --git a/tests/neg/i13440.check b/tests/neg/i13440.check deleted file mode 100644 index 277d3dce0bf0..000000000000 --- a/tests/neg/i13440.check +++ /dev/null @@ -1,15 +0,0 @@ --- Error: tests/neg/i13440.scala:5:4 ----------------------------------------------------------------------------------- -5 |def given = 42 // error - | ^ - | given is now a keyword, write `given` instead of given to keep it as an identifier - | This can be rewritten automatically under -rewrite -source 3.0-migration. --- Error: tests/neg/i13440.scala:7:13 ---------------------------------------------------------------------------------- -7 |case class C(enum: List[Int] = Nil) { // error - | ^ - | enum is now a keyword, write `enum` instead of enum to keep it as an identifier - | This can be rewritten automatically under -rewrite -source 3.0-migration. --- Error: tests/neg/i13440.scala:8:11 ---------------------------------------------------------------------------------- -8 | val s = s"$enum" // error - | ^ - | enum is now a keyword, write `enum` instead of enum to keep it as an identifier - | This can be rewritten automatically under -rewrite -source 3.0-migration. diff --git a/tests/neg/i13440.scala b/tests/neg/i13440.scala deleted file mode 100644 index 443215c621ef..000000000000 --- a/tests/neg/i13440.scala +++ /dev/null @@ -1,9 +0,0 @@ -//> using options -Xfatal-warnings - -import language.`3.0-migration` - -def given = 42 // error - -case class C(enum: List[Int] = Nil) { // error - val s = s"$enum" // error -} diff --git a/tests/neg/i13542.scala b/tests/neg/i13542.scala deleted file mode 100644 index c0feb88b556d..000000000000 --- a/tests/neg/i13542.scala +++ /dev/null @@ -1,52 +0,0 @@ -//> using options -Xfatal-warnings - -import scala.language.implicitConversions - -case class Foo(i: Int) extends AnyVal: - def toFoo = this - -case class Bar(i: Int) extends AnyVal - -class BarOps(bar: Bar): - def toFoo = Foo(bar.i) - -implicit def augmentBar(bar: Bar): BarOps = BarOps(bar) - -def lazyIdentity[T](x: => T): T = x -def repIdentity[T](x: T*): T = x(0) - -val x1 = - implicit def barToFoo(bar: Bar): Foo = bar.toFoo // error: infinite loop in function body - val foo: Foo = Bar(1) - -val x2 = - implicit def barToFoo2(bar: Bar): Foo = - identity(bar.toFoo) // error - val foo: Foo = Bar(1) - -val x3 = - implicit def barToFoo3(bar: Bar): Foo = - lazyIdentity(bar.toFoo) // OK - val foo: Foo = Bar(1) - -val x4 = - implicit def barToFoo4(bar: Bar): Foo = - repIdentity(bar.toFoo) // error - val foo: Foo = Bar(1) - -val x5 = - implicit def barToFoo4(bar: Bar): Foo = - val y = bar.toFoo // error - y - val foo: Foo = Bar(1) - -val x6 = - implicit def barToFoo4(bar: Bar): Foo = - lazy val y = bar.toFoo - if false then y else ??? - val foo: Foo = Bar(1) - - - - - diff --git a/tests/neg/i13946/BadPrinter.scala b/tests/neg/i13946/BadPrinter.scala index 46913d2c2805..39e8a921d498 100644 --- a/tests/neg/i13946/BadPrinter.scala +++ b/tests/neg/i13946/BadPrinter.scala @@ -2,5 +2,6 @@ // in BadPrinter.scala import language.future -class BadPrinter extends Printer: // error +class BadPrinter extends Printer: // warn override def print(s: String): Unit = println("Bad!!!") +// nopos-error: No warnings can be incurred under -Werror. diff --git a/tests/neg/i14386.scala b/tests/neg/i14386.scala index be0b2497ed5f..d9647da49525 100644 --- a/tests/neg/i14386.scala +++ b/tests/neg/i14386.scala @@ -42,7 +42,8 @@ def braced() = s"""begin ${ val level = 10 - val msg = "hello, world" // error he lets me off with a warning - log(level, msg) // error + val msg = "hello, world" // warn he lets me off with a warning + log(level, msg) // warn } end""" +// nopos-error: No warnings can be incurred under -Werror. \ No newline at end of file diff --git a/tests/neg/i14705.scala b/tests/neg/i14705.scala deleted file mode 100644 index 9ffb4443416e..000000000000 --- a/tests/neg/i14705.scala +++ /dev/null @@ -1,5 +0,0 @@ -//> using options -Xfatal-warnings - -val n = Nil -val b = n.head.isInstanceOf[String] // error - diff --git a/tests/neg/i14721.scala b/tests/neg/i14721.scala deleted file mode 100644 index 46786f04558b..000000000000 --- a/tests/neg/i14721.scala +++ /dev/null @@ -1,9 +0,0 @@ -//> using options -Xfatal-warnings - -class C: - def op: Unit = println("op") - def handler: Unit = println("handler") - def test: Unit = - try op - catch case _: NullPointerException => - handler // error diff --git a/tests/neg/i15474.scala b/tests/neg/i15474.scala deleted file mode 100644 index 8edf97a1e55a..000000000000 --- a/tests/neg/i15474.scala +++ /dev/null @@ -1,18 +0,0 @@ -//> using options -Xfatal-warnings - -import scala.language.implicitConversions - -object Test1: - given c: Conversion[ String, Int ] with - def apply(from: String): Int = from.toInt // error - -object Test2: - given c: Conversion[ String, Int ] = _.toInt // loop not detected, could be used as a fallback to avoid the warning. - -object Prices { - opaque type Price = BigDecimal - - object Price{ - given Ordering[Price] = summon[Ordering[BigDecimal]] // error - } -} \ No newline at end of file diff --git a/tests/neg/i15479.scala b/tests/neg/i15479.scala deleted file mode 100644 index d4f306a12368..000000000000 --- a/tests/neg/i15479.scala +++ /dev/null @@ -1,18 +0,0 @@ -//> using options -source future -deprecation -Xfatal-warnings - -package deptest { - @deprecated("Not used any more", since="7") - object DeprecatedThing { - val oldValue = 42 - } -} - -package depuser { - import deptest.DeprecatedThing.* // error - - object DepUser { - def main(args: Array[String]): Unit = println { - oldValue - } - } -} \ No newline at end of file diff --git a/tests/neg/i15503a.scala b/tests/neg/i15503a.scala deleted file mode 100644 index b5f17a1e2f52..000000000000 --- a/tests/neg/i15503a.scala +++ /dev/null @@ -1,268 +0,0 @@ -//> using options -Xfatal-warnings -Wunused:imports - - -object FooUnused: - import collection.mutable.Set // error - import collection.mutable.{Map => MutMap} // error - import collection.mutable._ // error - -object FooWildcardUnused: - import collection.mutable._ // error - -object Foo: - import collection.mutable.Set // OK - import collection.mutable.{Map => MutMap} // OK - - val bar = Set() // OK - val baz = MutMap() // OK - -object FooWildcard: - import collection.mutable._ // OK - - val bar = Set() // OK - -object FooNestedUnused: - import collection.mutable.Set // error - object Nested: - def hello = 1 - -object FooNested: - import collection.mutable.Set // OK - object Nested: - def hello = Set() - -object FooGivenUnused: - import SomeGivenImports.given // error - -object FooGiven: - import SomeGivenImports.given // OK - import SomeGivenImports._ // error - - val foo = summon[Int] - -/** - * Import used as type name are considered - * as used. - * - * Import here are only used as types, not as - * Term - */ -object FooTypeName: - import collection.mutable.Set // OK - import collection.mutable.Map // OK - import collection.mutable.Seq // OK - import collection.mutable.ArrayBuilder // OK - import collection.mutable.ListBuffer // error - - def checkImplicit[A](using Set[A]) = () - def checkParamType[B](a: Map[B,B]): Seq[B] = ??? - def checkTypeParam[A] = () - - checkTypeParam[ArrayBuilder[Int]] - - -object InlineChecks: - object InlineFoo: - import collection.mutable.Set // ok - import collection.mutable.Map // error - inline def getSet = Set(1) - - object InlinedBar: - import collection.mutable.Set // ok - import collection.mutable.Map // error - val a = InlineFoo.getSet - -object MacroChecks: - object StringInterpol: - import collection.mutable.Set // OK - import collection.mutable.Map // OK - println(s"This is a mutableSet : ${Set[Map[Int,Int]]()}") - - -object InnerMostCheck: - import collection.mutable.* // error - def check = - import collection.mutable.* //OK - val a = Set(1) - -object IgnoreExclusion: - import collection.mutable.{Set => _} // OK - import collection.mutable.{Map => _} // OK - import collection.mutable.{ListBuffer} // error - def check = - val a = Set(1) - val b = Map(1 -> 2) -/** - * Some given values for the test - */ -object SomeGivenImports: - given Int = 0 - given String = "foo" - -/* BEGIN : Check on packages*/ -package testsamepackageimport: - package p { - class C - } - - package p { - import p._ // error - package q { - class U { - def f = new C - } - } - } -// ----------------------- - -package testpackageimport: - package a: - val x: Int = 0 - - package b: - import a._ // error - - -/* END : Check on packages*/ - -/* BEGIN : tests on meta-language features */ -object TestGivenCoversionScala2: - /* note: scala3 Conversion[U,T] do not require an import */ - import language.implicitConversions // OK - - implicit def doubleToInt(d:Double):Int = d.toInt - - def idInt(i:Int):Int = i - val someInt = idInt(1.0) - -object TestTailrecImport: - import annotation.tailrec // OK - @tailrec - def fac(x:Int, acc:Int = 1): Int = - if x == 0 then acc else fac(x - 1, acc * x) -/* END : tests on meta-language features */ - -/* BEGIN : tests on given import order */ -object GivenImportOrderAtoB: - class X - class Y extends X - object A { implicit val x: X = new X } - object B { implicit val y: Y = new Y } - class C { - import A._ // error - import B._ // OK - def t = implicitly[X] - } - -object GivenImportOrderBtoA: - class X - class Y extends X - object A { implicit val x: X = new X } - object B { implicit val y: Y = new Y } - class C { - import B._ // OK - import A._ // error - def t = implicitly[X] - } -/* END : tests on given import order */ - -/* Scala 2 implicits */ -object Scala2ImplicitsGiven: - object A: - implicit val x: Int = 1 - object B: - import A.given // OK - val b = summon[Int] - object C: - import A.given // error - val b = 1 - object D: - import A._ // OK - val b = summon[Int] - object E: - import A._ // error - val b = 1 - object F: - import A.x // OK - val b = summon[Int] - object G: - import A.x // error - val b = 1 - -// ------------------------------------- -object TestNewKeyword: - object Foo: - class Aa[T](val x: T) - object Bar: - import Foo.Aa // OK - val v = 1 - val a = new Aa(v) - -// ------------------------------------- -object testAnnotatedType: - import annotation.switch // OK - val a = (??? : @switch) match - case _ => ??? - - -//------------------------------------- -package testImportsInImports: - package a: - package b: - val x = 1 - package c: - import a.b // OK - import b.x // OK - val y = x - -//------------------------------------- -package testOnOverloadedMethodsImports: - package a: - trait A - trait B - trait C: - def foo(x: A):A = ??? - def foo(x: B):B = ??? - package b: - object D extends a.C - package c: - import b.D.foo // error - package d: - import b.D.foo // OK - def bar = foo((??? : a.A)) - package e: - import b.D.foo // OK - def bar = foo((??? : a.B)) - package f: - import b.D.foo // OK - def bar = foo((??? : a.A)) - def baz = foo((??? : a.B)) - -//------------------------------------- -package foo.testing.rename.imports: - import collection.mutable.{Set => MutSet1} // OK - import collection.mutable.{Set => MutSet2} // OK - import collection.mutable.{Set => MutSet3} // error - type A[X] = MutSet1[X] - val a = MutSet2(1) - -//------------------------------------- -package foo.testing.imports.precedence: - import scala.collection.immutable.{BitSet => _, _} // error - import scala.collection.immutable.BitSet // OK - def t = BitSet.empty - -package foo.test.enums: - enum A: // OK - case B extends A // OK - case C extends A // OK - -package foo.test.typeapply.hklamdba.i16680: - package foo: - trait IO[A] - - package bar: - import foo.IO // OK - - def f[F[_]]: String = "hello" - def go = f[IO] \ No newline at end of file diff --git a/tests/neg/i15503b.scala b/tests/neg/i15503b.scala deleted file mode 100644 index 4dc10e12606d..000000000000 --- a/tests/neg/i15503b.scala +++ /dev/null @@ -1,144 +0,0 @@ -//> using options -Xfatal-warnings -Wunused:locals - -val a = 1 // OK - -var cs = 3 // OK - -val b = // OK - var e3 = 2 // error - val e1 = 1 // error - def e2 = 2 // error - 1 - -val c = // OK - var e1 = 1 // error not set - def e2 = e1 // OK - val e3 = e2 // OK - e3 - -val g = // OK - var e1 = 1 // OK - def e2 = e1 // OK - val e3 = e2 // OK - e1 = e3 // OK - e3 - -def d = 1 // OK - -def e = // OK - val e1 = 1 // error - def e2 = 2 // error - var e3 = 4 // error - 1 - -def f = // OK - val f1 = 1 // OK - var f2 = f1 // error not set - def f3 = f2 // OK - f3 - -def h = // OK - val f1 = 1 // OK - var f2 = f1 // OK - def f3 = f2 // OK - f2 = f3 // OK - f2 - -class Foo { - val a = 1 // OK - - var cs = 3 // OK - - val b = // OK - var e3 = 2 // error - val e1 = 1 // error - def e2 = 2 // error - 1 - - val c = // OK - var e1 = 1 // error not set - def e2 = e1 // OK - val e3 = e2 // OK - e3 - - val g = // OK - var e1 = 1 // OK - def e2 = e1 // OK - val e3 = e2 // OK - e1 = e3 // OK - e3 - - def d = 1 // OK - - def e = // OK - val e1 = 1 // error - def e2 = 2 // error - var e3 = 4 // error - 1 - - def f = // OK - val f1 = 1 // OK - var f2 = f1 // error not set - def f3 = f2 // OK - f3 - - def h = // OK - val f1 = 1 // OK - var f2 = f1 // OK - def f3 = f2 // OK - f2 = f3 // OK - f2 -} - -// ---- SCALA 2 tests ---- - -package foo.scala2.tests: - class Outer { - class Inner - } - - trait Locals { - def f0 = { - var x = 1 // error - var y = 2 // OK - y = 3 - y + y - } - def f1 = { - val a = new Outer // OK - val b = new Outer // error - new a.Inner - } - def f2 = { - var x = 100 // error not set - x - } - } - - object Types { - def l1() = { - object HiObject { def f = this } // OK - class Hi { // error - def f1: Hi = new Hi - def f2(x: Hi) = x - } - class DingDongDoobie // error - class Bippy // OK - type Something = Bippy // OK - type OtherThing = String // error - (new Bippy): Something - } - } - -package test.foo.twisted.i16682: - def myPackage = - object IntExtractor: // OK - def unapply(s: String): Option[Int] = s.toIntOption - - def isInt(s: String) = s match { // OK - case IntExtractor(i) => println(s"Number $i") - case _ => println("NaN") - } - isInt - - def f = myPackage("42") diff --git a/tests/neg/i15503c.scala b/tests/neg/i15503c.scala deleted file mode 100644 index 040dae43a2c9..000000000000 --- a/tests/neg/i15503c.scala +++ /dev/null @@ -1,57 +0,0 @@ -//> using options -Xfatal-warnings -Wunused:privates -source:3.3 -trait C -class A: - self: C => // OK - class B: - private[A] val a = 1 // OK - private[B] val b = 1 // OK - private[this] val c = 1 // error - private val d = 1 // error - - private[A] val e = 1 // OK - private[this] val f = e // OK - private val g = f // OK - - private[A] var h = 1 // OK - private[this] var i = h // error not set - private var j = i // error not set - - private[this] var k = 1 // OK - private var l = 2 // OK - private val m = // error - k = l - l = k - l - - private def fac(x: Int): Int = // error - if x == 0 then 1 else x * fac(x - 1) - - val x = 1 // OK - def y = 2 // OK - def z = g // OK - var w = 2 // OK - -package foo.test.contructors: - case class A private (x:Int) // OK - class B private (val x: Int) // OK - class C private (private val x: Int) // error - class D private (private val x: Int): // OK - def y = x - class E private (private var x: Int): // error not set - def y = x - class F private (private var x: Int): // OK - def y = - x = 3 - x - -package test.foo.i16682: - object myPackage: - private object IntExtractor: // OK - def unapply(s: String): Option[Int] = s.toIntOption - - def isInt(s: String) = s match { - case IntExtractor(i) => println(s"Number $i") - case _ => println("NaN") - } - - def f = myPackage.isInt("42") diff --git a/tests/neg/i15503d.scala b/tests/neg/i15503d.scala deleted file mode 100644 index c43dc07c638e..000000000000 --- a/tests/neg/i15503d.scala +++ /dev/null @@ -1,30 +0,0 @@ -//> using options -Xfatal-warnings -Wunused:unsafe-warn-patvars -// todo : change to :patvars - -sealed trait Calc -sealed trait Const extends Calc -case class Sum(a: Calc, b: Calc) extends Calc -case class S(pred: Const) extends Const -case object Z extends Const - -val a = Sum(S(S(Z)),Z) match { - case Sum(a,Z) => Z // error - // case Sum(a @ _,Z) => Z // todo : this should pass in the future - case Sum(a@S(_),Z) => Z // error - case Sum(a@S(_),Z) => a // OK - case Sum(a@S(b@S(_)), Z) => a // error - case Sum(a@S(b@S(_)), Z) => a // error - case Sum(a@S(b@(S(_))), Z) => Sum(a,b) // OK - case Sum(_,_) => Z // OK - case _ => Z // OK -} - -// todo : This should pass in the future -// val b = for { -// case Some(x) <- Option(Option(1)) -// } println(s"$x") - -// todo : This should *NOT* pass in the future -// val c = for { -// case Some(x) <- Option(Option(1)) -// } println(s"hello world") diff --git a/tests/neg/i15503e.scala b/tests/neg/i15503e.scala deleted file mode 100644 index f3214e7b24e6..000000000000 --- a/tests/neg/i15503e.scala +++ /dev/null @@ -1,71 +0,0 @@ -//> using options -Xfatal-warnings -Wunused:explicits - -object Foo { - /* This goes around the "trivial method" detection */ - val default_val = 1 - - private def f1(a: Int) = a // OK - private def f2(a: Int) = default_val // error - private def f3(a: Int)(using Int) = a // OK - private def f4(a: Int)(using Int) = default_val // error - private def f6(a: Int)(using Int) = summon[Int] // error - private def f7(a: Int)(using Int) = summon[Int] + a // OK -} - -package scala2main.unused.args: - object happyBirthday { - def main(args: Array[String]): Unit = println("Hello World") // ok - } - -package scala2main: - object happyBirthday { - def main(args: Array[String]): Unit = // OK - println(s"Hello World, there are ${args.size} arguments") - } - -package scala3main: - /* This goes around the "trivial method" detection */ - val default_unit = () - @main def hello = println("Hello World") // OK - -package foo.test.lambda.param: - val default_val = 1 - val a = (i: Int) => i // OK - val b = (i: Int) => default_val // OK - val c = (_: Int) => default_val // OK - -package foo.test.trivial: - /* A twisted test from Scala 2 */ - class C { - def answer: 42 = 42 - object X - private def g0(x: Int) = ??? // OK - private def f0(x: Int) = () // OK - private def f1(x: Int) = throw new RuntimeException // OK - private def f2(x: Int) = 42 // OK - private def f3(x: Int): Option[Int] = None // OK - private def f4(x: Int) = classOf[Int] // OK - private def f5(x: Int) = answer + 27 // OK - private def f6(x: Int) = X // OK - private def f7(x: Int) = Y // OK - private def f8(x: Int): List[C] = Nil // OK - private def f9(x: Int): List[Int] = List(1,2,3,4) // error - private def foo:Int = 32 // OK - private def f77(x: Int) = foo // error - } - object Y - -package foo.test.i16955: - class S(var r: String) // OK - -package foo.test.i16865: - trait Foo: - def fn(a: Int, b: Int): Int // OK - trait Bar extends Foo - - object Ex extends Bar: - def fn(a: Int, b: Int): Int = b + 3 // OK - - object Ex2 extends Bar: - override def fn(a: Int, b: Int): Int = b + 3 // OK - diff --git a/tests/neg/i15503f.scala b/tests/neg/i15503f.scala deleted file mode 100644 index 08520d149b95..000000000000 --- a/tests/neg/i15503f.scala +++ /dev/null @@ -1,14 +0,0 @@ -//> using options -Xfatal-warnings -Wunused:implicits - -/* This goes around the "trivial method" detection */ -val default_int = 1 - -object Xd { - private def f1(a: Int) = a // OK - private def f2(a: Int) = 1 // OK - private def f3(a: Int)(using Int) = a // OK - private def f4(a: Int)(using Int) = default_int // OK - private def f6(a: Int)(using Int) = summon[Int] // OK - private def f7(a: Int)(using Int) = summon[Int] + a // OK - private def f8(a: Int)(using foo: Int) = a // error -} diff --git a/tests/neg/i15503g.scala b/tests/neg/i15503g.scala deleted file mode 100644 index 4da98a8d43f2..000000000000 --- a/tests/neg/i15503g.scala +++ /dev/null @@ -1,23 +0,0 @@ -//> using options -Xfatal-warnings -Wunused:params - -/* This goes around the "trivial method" detection */ -object Foo { - val default_int = 1 - - private def f1(a: Int) = a // OK - private def f2(a: Int) = default_int // error - private def f3(a: Int)(using Int) = a // OK - private def f4(a: Int)(using Int) = default_int // error - private def f6(a: Int)(using Int) = summon[Int] // error - private def f7(a: Int)(using Int) = summon[Int] + a // OK - /* --- Trivial method check --- */ - private def g1(x: Int) = 1 // OK - private def g2(x: Int) = ??? // OK -} - -package foo.test.i17101: - type Test[A] = A - extension[A] (x: Test[A]) { // OK - def value: A = x - def causesIssue: Unit = println("oh no") - } diff --git a/tests/neg/i15503h.scala b/tests/neg/i15503h.scala deleted file mode 100644 index cef1f6cf566f..000000000000 --- a/tests/neg/i15503h.scala +++ /dev/null @@ -1,20 +0,0 @@ -//> using options -Xfatal-warnings -Wunused:linted - -import collection.mutable.Set // error - -class A { - private val a = 1 // error - val b = 2 // OK - - private def c = 2 // error - def d(using x:Int): Int = b // ok - def e(x: Int) = 1 // OK - def f = - val x = 1 // error - def f = 2 // error - 3 - - def g(x: Int): Int = x match - case x:1 => 0 // OK - case _ => 1 -} \ No newline at end of file diff --git a/tests/neg/i15503i.scala b/tests/neg/i15503i.scala deleted file mode 100644 index d415c95a701a..000000000000 --- a/tests/neg/i15503i.scala +++ /dev/null @@ -1,315 +0,0 @@ -//> using options -Xfatal-warnings -Wunused:all - -import collection.mutable.{Map => MutMap} // error -import collection.mutable.Set // error - -class A { - import collection.mutable.{Map => MutMap} // OK - private val a = 1 // error - val b = 2 // OK - - /* This goes around the trivial method detection */ - val default_int = 12 - - val someMap = MutMap() - - private def c1 = 2 // error - private def c2 = 2 // OK - def c3 = c2 - - def d1(using x:Int): Int = default_int // ok - def d2(using x:Int): Int = x // OK - - def e1(x: Int) = default_int // ok - def e2(x: Int) = x // OK - def f = - val x = 1 // error - def f = 2 // error - val y = 3 // OK - def g = 4 // OK - y + g - - // todo : uncomment once patvars is fixed - // def g(x: Int): Int = x match - // case x:1 => 0 // ?error - // case x:2 => x // ?OK - // case _ => 1 // ?OK -} - -/* ---- CHECK scala.annotation.unused ---- */ -package foo.test.scala.annotation: - import annotation.unused // OK - - /* This goes around the trivial method detection */ - val default_int = 12 - - def a1(a: Int) = a // OK - def a2(a: Int) = default_int // ok - - def a3(@unused a: Int) = default_int //OK - - def b1 = - def f = 1 // error - 1 - - def b2 = - def f = 1 // OK - f - - def b3 = - @unused def f = 1 // OK - 1 - - object Foo: - private def a = 1 // error - private def b = 2 // OK - @unused private def c = 3 // OK - - def other = b - -package foo.test.companionprivate: - class A: - import A.b // OK - def a = b // OK - - object A: - private def b = c // OK - def c = List(1,2,3) // OK - -package foo.test.i16678: - def foo(func: Int => String, value: Int): String = func(value) // OK - - def run = - println(foo(number => number.toString, value = 5)) // OK - println(foo(number => "", value = 5)) // error - println(foo(func = number => "", value = 5)) // error - println(foo(func = number => number.toString, value = 5)) // OK - println(foo(func = _.toString, value = 5)) // OK - -package foo.test.possibleclasses: - case class AllCaseClass( - k: Int, // OK - private val y: Int // OK /* Kept as it can be taken from pattern */ - )( - s: Int, - val t: Int, // OK - private val z: Int // error - ) - - case class AllCaseUsed( - k: Int, // OK - private val y: Int // OK - )( - s: Int, // OK - val t: Int, // OK - private val z: Int // OK - ) { - def a = k + y + s + t + z - } - - class AllClass( - k: Int, // error - private val y: Int // error - )( - s: Int, // error - val t: Int, // OK - private val z: Int // error - ) - - class AllUsed( - k: Int, // OK - private val y: Int // OK - )( - s: Int, // OK - val t: Int, // OK - private val z: Int // OK - ) { - def a = k + y + s + t + z - } - -package foo.test.possibleclasses.withvar: - case class AllCaseClass( - k: Int, // OK - private var y: Int // OK /* Kept as it can be taken from pattern */ - )( - s: Int, - var t: Int, // OK - private var z: Int // error - ) - - case class AllCaseUsed( - k: Int, // OK - private var y: Int // OK - )( - s: Int, // OK - var t: Int, // OK global scope can be set somewhere else - private var z: Int // error not set - ) { - def a = k + y + s + t + z - } - - class AllClass( - k: Int, // error - private var y: Int // error - )( - s: Int, // error - var t: Int, // OK - private var z: Int // error - ) - - class AllUsed( - k: Int, // OK - private var y: Int // error not set - )( - s: Int, // OK - var t: Int, // OK global scope can be set somewhere else - private var z: Int // error not set - ) { - def a = k + y + s + t + z - } - - - -package foo.test.from.i16675: - case class PositiveNumber private (i: Int) // OK - object PositiveNumber: - def make(i: Int): Option[PositiveNumber] = //OK - Option.when(i >= 0)(PositiveNumber(i)) // OK - -package foo.test.i16822: - enum ExampleEnum { - case Build(context: String) // OK - case List // OK - } - - def demo = { - val x = ExampleEnum.List // OK - println(x) // OK - } - -package foo.test.i16877: - import scala.collection.immutable.HashMap // OK - import scala.annotation.StaticAnnotation // OK - - class ExampleAnnotation(val a: Object) extends StaticAnnotation // OK - - @ExampleAnnotation(new HashMap()) // OK - class Test //OK - -package foo.test.i16926: - def hello(): Unit = - for { - i <- (0 to 10).toList - (a, b) = "hello" -> "world" // OK - } yield println(s"$a $b") - -package foo.test.i16925: - def hello = - for { - i <- 1 to 2 if true - _ = println(i) // OK - } yield () - -package foo.test.i16863a: - import scala.quoted.* - def fn(using Quotes) = - val x = Expr(1) - '{ $x + 2 } // OK - -package foo.test.i16863b: - import scala.quoted.* - def fn[A](using Quotes, Type[A]) = // OK - val numeric = Expr.summon[Numeric[A]].getOrElse(???) - '{ $numeric.fromInt(3) } // OK - -package foo.test.i16863c: - import scala.quoted.* - def fn[A](expr: Expr[Any])(using Quotes) = - val imp = expr match - case '{ ${ _ }: a } => Expr.summon[Numeric[a]] // OK - println(imp) - -package foo.test.i16863d: - import scala.quoted.* - import scala.compiletime.asMatchable // OK - def fn[A](using Quotes, Type[A]) = - import quotes.reflect.* - val imp = TypeRepr.of[A].widen.asMatchable match - case Refinement(_,_,_) => () - println(imp) - -package foo.test.i16679a: - object myPackage: - trait CaseClassName[A]: - def name: String - object CaseClassName: - trait CaseClassByStringName[A] extends CaseClassName[A] - import scala.deriving.Mirror - object CaseClassByStringName: - inline final def derived[A](using inline A: Mirror.Of[A]): CaseClassByStringName[A] = - new CaseClassByStringName[A]: - def name: String = A.toString - - object secondPackage: - import myPackage.CaseClassName // OK - case class CoolClass(i: Int) derives CaseClassName.CaseClassByStringName - println(summon[CaseClassName[CoolClass]].name) - -package foo.test.i16679b: - object myPackage: - trait CaseClassName[A]: - def name: String - - object CaseClassName: - import scala.deriving.Mirror - inline final def derived[A](using inline A: Mirror.Of[A]): CaseClassName[A] = - new CaseClassName[A]: - def name: String = A.toString - - object Foo: - given x: myPackage.CaseClassName[secondPackage.CoolClass] = null - - object secondPackage: - import myPackage.CaseClassName // OK - import Foo.x - case class CoolClass(i: Int) - println(summon[myPackage.CaseClassName[CoolClass]]) - -package foo.test.i17156: - package a: - trait Foo[A] - object Foo: - inline def derived[T]: Foo[T] = new Foo{} - - package b: - import a.Foo - type Xd[A] = Foo[A] - - package c: - import b.Xd - trait Z derives Xd - - -package foo.test.i17175: - val continue = true - def foo = - for { - i <- 1.until(10) // OK - if continue - } { - println(i) - } - -package foo.test.i17117: - package example { - object test1 { - val test = "test" - } - - object test2 { - - import example.test1 as t1 - - val test = t1.test - } - } diff --git a/tests/neg/i15503j.scala b/tests/neg/i15503j.scala deleted file mode 100644 index 66140934abc1..000000000000 --- a/tests/neg/i15503j.scala +++ /dev/null @@ -1,59 +0,0 @@ -//> using options -Xfatal-warnings -Wunused:strict-no-implicit-warn - -package foo.unused.strict.test: - package a: - given x: Int = 0 - implicit val y: Int = 1 - val z: Int = 2 - def f: Int = 3 - package b: - import a.given // OK - import a._ // OK - import a.* // OK - import a.x // OK - import a.y // OK - import a.z // error - import a.f // error - package c: - import a.given // OK - import a.x // OK - import a.y // OK - import a.z // OK - import a.f // OK - def g = f + z + y + x - -package foo.implicits.resolution: - class X - class Y extends X - object A { implicit val x: X = new X } - object B { implicit val y: Y = new Y } - class C { - import A._ // OK - import B._ // OK - def t = implicitly[X] - } - -package foo.unused.summon.inlines: - package lib: - trait A - trait B - trait C - trait X - - given willBeUnused: (A & X) = new A with X {} - given willBeUsed: (A & B) = new A with B {} - - package use: - import lib.{A, B, C, willBeUnused, willBeUsed} //OK - import compiletime.summonInline //OK - - transparent inline given conflictInside: C = - summonInline[A] - new {} - - transparent inline given potentialConflict: C = - summonInline[B] - new {} - - val b: B = summon[B] - val c: C = summon[C] \ No newline at end of file diff --git a/tests/neg/i15662.scala b/tests/neg/i15662.scala deleted file mode 100644 index c84ed6e5e341..000000000000 --- a/tests/neg/i15662.scala +++ /dev/null @@ -1,16 +0,0 @@ -//> using options -Xfatal-warnings - -case class Composite[T](v: T) - -def m(composite: Composite[?]): Unit = - composite match { - case Composite[Int](v) => println(v) // error: cannot be checked at runtime - } - -def m2(composite: Composite[?]): Unit = - composite match { - case Composite(v) => println(v) // ok - } - -@main def Test = - m(Composite("This is String")) diff --git a/tests/neg/i15893.scala b/tests/neg/i15893.scala deleted file mode 100644 index a62ddc3ae653..000000000000 --- a/tests/neg/i15893.scala +++ /dev/null @@ -1,63 +0,0 @@ -//> using options -Xfatal-warnings - -sealed trait NatT -case class Zero() extends NatT -case class Succ[+N <: NatT](n: N) extends NatT - -type Mod2[N <: NatT] <: NatT = N match - case Zero => Zero - case Succ[Zero] => Succ[Zero] - case Succ[Succ[predPredN]] => Mod2[predPredN] - -def mod2(n: NatT): NatT = n match - case Zero() => Zero() - case Succ(Zero()) => Succ(Zero()) - case Succ(Succ(predPredN)) => mod2(predPredN) - -inline def inlineMod2(inline n: NatT): NatT = inline n match - case Zero() => Zero() - case Succ(Zero()) => Succ(Zero()) - case Succ(Succ(predPredN)) => inlineMod2(predPredN) - -transparent inline def transparentInlineMod2(inline n: NatT): NatT = inline n match - case Zero() => Zero() - case Succ(Zero()) => Succ(Zero()) - case Succ(Succ(predPredN)) => transparentInlineMod2(predPredN) - -def dependentlyTypedMod2[N <: NatT](n: N): Mod2[N] = n match - case Zero(): Zero => Zero() // error - case Succ(Zero()): Succ[Zero] => Succ(Zero()) // error - case Succ(Succ(predPredN)): Succ[Succ[?]] => dependentlyTypedMod2(predPredN) // error - -inline def inlineDependentlyTypedMod2[N <: NatT](inline n: N): Mod2[N] = inline n match - case Zero(): Zero => Zero() // error - case Succ(Zero()): Succ[Zero] => Succ(Zero()) // error - case Succ(Succ(predPredN)): Succ[Succ[?]] => inlineDependentlyTypedMod2(predPredN) // error - -transparent inline def transparentInlineDependentlyTypedMod2[N <: NatT](inline n: N): Mod2[N] = inline n match - case Zero(): Zero => Zero() // error - case Succ(Zero()): Succ[Zero] => Succ(Zero()) // error - case Succ(Succ(predPredN)): Succ[Succ[?]] => transparentInlineDependentlyTypedMod2(predPredN) // error - -def foo(n: NatT): NatT = mod2(n) match - case Succ(Zero()) => Zero() - case _ => n - -inline def inlineFoo(inline n: NatT): NatT = inline inlineMod2(n) match - case Succ(Zero()) => Zero() - case _ => n - -inline def transparentInlineFoo(inline n: NatT): NatT = inline transparentInlineMod2(n) match - case Succ(Zero()) => Zero() - case _ => n - -@main def main(): Unit = - println(mod2(Succ(Succ(Succ(Zero()))))) // prints Succ(Zero()), as expected - println(foo(Succ(Succ(Succ(Zero()))))) // prints Zero(), as expected - println(inlineMod2(Succ(Succ(Succ(Zero()))))) // prints Succ(Zero()), as expected - println(inlineFoo(Succ(Succ(Succ(Zero()))))) // prints Succ(Succ(Succ(Zero()))); unexpected - println(transparentInlineMod2(Succ(Succ(Succ(Zero()))))) // prints Succ(Zero()), as expected - println(transparentInlineFoo(Succ(Succ(Succ(Zero()))))) // prints Zero(), as expected - println(dependentlyTypedMod2(Succ(Succ(Succ(Zero()))))) // runtime error; unexpected - println(inlineDependentlyTypedMod2(Succ(Succ(Succ(Zero()))))) // prints Succ(Zero()), as expected - println(transparentInlineDependentlyTypedMod2(Succ(Succ(Succ(Zero()))))) // prints Succ(Zero()), as expected diff --git a/tests/neg/i16639a.scala b/tests/neg/i16639a.scala deleted file mode 100644 index 5b348d594f5b..000000000000 --- a/tests/neg/i16639a.scala +++ /dev/null @@ -1,207 +0,0 @@ -//> using options -Xfatal-warnings -Wunused:all -source:3.3 -// -class Bippy(a: Int, b: Int) { - private def this(c: Int) = this(c, c) // warn /Dotty:NoWarn - private def boop(x: Int) = x+a+b // error - private def bippy(x: Int): Int = bippy(x) // error TODO: could warn - final private val MILLIS1 = 2000 // error no warn, /Dotty:Warn - final private val MILLIS2: Int = 1000 // error - final private val HI_COMPANION: Int = 500 // no warn, accessed from companion - def hi() = Bippy.HI_INSTANCE -} -object Bippy { - def hi(x: Bippy) = x.HI_COMPANION - private val HI_INSTANCE: Int = 500 // no warn, accessed from instance - private val HEY_INSTANCE: Int = 1000 // error warn - private lazy val BOOL: Boolean = true // error warn -} - -class A(val msg: String) -class B1(msg: String) extends A(msg) -class B2(msg0: String) extends A(msg0) -class B3(msg0: String) extends A("msg") // error /Dotty: unused explicit parameter - -trait Bing - -trait Accessors { - private var v1: Int = 0 // error warn - private var v2: Int = 0 // error warn, never set - private var v3: Int = 0 - private var v4: Int = 0 // no warn - - private[this] var v5 = 0 // error warn, never set - private[this] var v6 = 0 - private[this] var v7 = 0 // no warn - - def bippy(): Int = { - v3 = 3 - v4 = 4 - v6 = 6 - v7 = 7 - v2 + v4 + v5 + v7 - } -} - -class StableAccessors { - private var s1: Int = 0 // error warn - private var s2: Int = 0 // error warn, never set - private var s3: Int = 0 // warn, never got /Dotty: no warn even if not usued - private var s4: Int = 0 // no warn - - private[this] var s5 = 0 // error warn, never set - private[this] var s6 = 0 // no warn, limitation /Dotty: Why limitation ? - private[this] var s7 = 0 // no warn - - def bippy(): Int = { - s3 = 3 - s4 = 4 - s6 = 6 - s7 = 7 - s2 + s4 + s5 + s7 - } -} - -trait DefaultArgs { - // warn about default getters for x2 and x3 - private def bippy(x1: Int, x2: Int = 10, x3: Int = 15): Int = x1 + x2 + x3 // no more warn warn since #17061 - - def boppy() = bippy(5, 100, 200) -} - - -class Outer { - class Inner -} - -trait Locals { - def f0 = { - var x = 1 // error warn - var y = 2 - y = 3 - y + y - } - def f1 = { - val a = new Outer // no warn - val b = new Outer // error warn - new a.Inner - } - def f2 = { - var x = 100 // error warn about it being a var, var not set - x - } -} - -object Types { - private object Dongo { def f = this } // no more warn since #17061 - private class Bar1 // error warn - private class Bar2 // no warn - private type Alias1 = String // error warn - private type Alias2 = String // no warn - def bippo = (new Bar2).toString - - def f(x: Alias2) = x.length - - def l1() = { - object HiObject { def f = this } // no more warn since #17061 - class Hi { // error warn - def f1: Hi = new Hi - def f2(x: Hi) = x - } - class DingDongDoobie // error warn - class Bippy // no warn - type Something = Bippy // no warn - type OtherThing = String // error warn - (new Bippy): Something - } -} - -trait Underwarn { - def f(): Seq[Int] - - def g() = { - val Seq(_, _) = f() // no warn - true - } -} - -class OtherNames { - private def x_=(i: Int): Unit = () // no more warn since #17061 - private def x: Int = 42 // error Dotty triggers unused private member : To investigate - private def y_=(i: Int): Unit = () // // no more warn since #17061 - private def y: Int = 42 - - def f = y -} - - -trait Forever { - def f = { - val t = Option((17, 42)) - for { - ns <- t - (i, j) = ns // no warn - } yield (i + j) - } - def g = { - val t = Option((17, 42)) - for { - ns <- t - (i, j) = ns // no warn - } yield 42 // val emitted only if needed, hence nothing unused - } -} - -trait Ignorance { - private val readResolve = 42 // error ignore /dotty triggers unused private member/ why should we ignore ? -} - -trait CaseyKasem { - def f = 42 match { - case x if x < 25 => "no warn" - case y if toString.nonEmpty => "no warn" + y - case z => "warn" - } -} -trait CaseyAtTheBat { - def f = Option(42) match { - case Some(x) if x < 25 => "no warn" - case Some(y @ _) if toString.nonEmpty => "no warn" - case Some(z) => "warn" - case None => "no warn" - } -} - -class `not even using companion privates` - -object `not even using companion privates` { - private implicit class `for your eyes only`(i: Int) { // no more warn since #17061 - def f = i - } -} - -class `no warn in patmat anonfun isDefinedAt` { - def f(pf: PartialFunction[String, Int]) = pf("42") - def g = f { - case s => s.length // no warn (used to warn case s => true in isDefinedAt) - } -} - -// this is the ordinary case, as AnyRef is an alias of Object -class `nonprivate alias is enclosing` { - class C - type C2 = C - private class D extends C2 // error warn -} - -object `classof something` { - private class intrinsically - def f = classOf[intrinsically].toString() -} - -trait `short comings` { - def f: Int = { - val x = 42 // error /Dotty only triggers in dotty - 17 - } -} - diff --git a/tests/neg/i16649-refutable.check b/tests/neg/i16649-refutable.check deleted file mode 100644 index a1325d7cfa91..000000000000 --- a/tests/neg/i16649-refutable.check +++ /dev/null @@ -1,8 +0,0 @@ --- Error: tests/neg/i16649-refutable.scala:6:6 ------------------------------------------------------------------------- -6 | val '{ ($y: Int) + ($z: Int) } = x // error - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | pattern binding uses refutable extractor `'{...}` - | - | If this usage is intentional, this can be communicated by adding `: @unchecked` after the expression, - | which may result in a MatchError at runtime. - | This patch can be rewritten automatically under -rewrite -source 3.2-migration. diff --git a/tests/neg/i16649-refutable.scala b/tests/neg/i16649-refutable.scala deleted file mode 100644 index 8caac5b2576a..000000000000 --- a/tests/neg/i16649-refutable.scala +++ /dev/null @@ -1,9 +0,0 @@ -//> using options -Xfatal-warnings - -import quoted.* - -def foo(using Quotes)(x: Expr[Int]) = - val '{ ($y: Int) + ($z: Int) } = x // error - val '{ $a: Int } = x - val '{ $b: Any } = x - val '{ $c } = x diff --git a/tests/neg/i16728.check b/tests/neg/i16728.check deleted file mode 100644 index 93cc215696c2..000000000000 --- a/tests/neg/i16728.check +++ /dev/null @@ -1,6 +0,0 @@ --- [E092] Pattern Match Error: tests/neg/i16728.scala:18:11 ------------------------------------------------------------ -18 | case tx : C[Int]#X => // error - | ^ - | the type test for C[Int] cannot be checked at runtime because its type arguments can't be determined from A - | - | longer explanation available when compiling with `-explain` diff --git a/tests/neg/i16728.scala b/tests/neg/i16728.scala deleted file mode 100644 index b76bb03fa14a..000000000000 --- a/tests/neg/i16728.scala +++ /dev/null @@ -1,34 +0,0 @@ -//> using options -Xfatal-warnings - -class A[T] { - class X { - def outer : A.this.type = A.this - } -} - -class B extends A[Int] -class C[T] extends A[T] - -object Test { - def main(args: Array[String]) : Unit = { - val b0 = new B - val b0x : A[?]#X = new b0.X - - def test = b0x match { - case tx : C[Int]#X => // error - val c : C[Int] = tx.outer - c - case _ => - "no match" - } - - def test2 = b0x match { - case tx : C[Int]#X @unchecked => // ok - val c : C[Int] = tx.outer - c - case _ => - "no match" - } - - } -} \ No newline at end of file diff --git a/tests/neg/i16876/Test.scala b/tests/neg/i16876/Test.scala index 2dd6bfb34421..71a01128990e 100644 --- a/tests/neg/i16876/Test.scala +++ b/tests/neg/i16876/Test.scala @@ -4,8 +4,7 @@ object Foo { private def myMethod(a: Int, b: Int, c: Int) = adder // ok myMethod(1, 2, 3) - private def myMethodFailing(a: Int, b: Int, c: Int) = a + 0 // error // error + private def myMethodFailing(a: Int, b: Int, c: Int) = a + 0 // warn // warn myMethodFailing(1, 2, 3) } - - +// nopos-error: No warnings can be incurred under -Werror. \ No newline at end of file diff --git a/tests/neg/i16930.scala b/tests/neg/i16930.scala deleted file mode 100644 index c7af60161424..000000000000 --- a/tests/neg/i16930.scala +++ /dev/null @@ -1,22 +0,0 @@ -//> using options -Xfatal-warnings -Wunused:imports - -trait Outer: - trait Used - trait Unused - -object Test { - val outer: Outer = ??? - import outer.{Used, Unused} // error - def foo(x: Any): Used = x.asInstanceOf[Used] -} - -trait Outer1: - trait UnusedToo1 - trait Unused1 - def unusedToo1: UnusedToo1 - -object Test1 { - val outer1: Outer1 = ??? - import outer1.{Unused1, UnusedToo1} // error // error - def foo() = outer1.unusedToo1 // in this case UnusedToo1 is not used explicitly, only inferred -} diff --git a/tests/neg/i17266.check b/tests/neg/i17266.check deleted file mode 100644 index 1a84d1bf5e89..000000000000 --- a/tests/neg/i17266.check +++ /dev/null @@ -1,98 +0,0 @@ --- [E181] Potential Issue Error: tests/neg/i17266.scala:4:2 ------------------------------------------------------------ -4 | synchronized { // error - | ^^^^^^^^^^^^ - | Suspicious top-level unqualified call to synchronized - |--------------------------------------------------------------------------------------------------------------------- - | Explanation (enabled by `-explain`) - |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | Top-level unqualified calls to AnyRef or Any methods such as synchronized are - | resolved to calls on Predef or on imported methods. This might not be what - | you intended. - --------------------------------------------------------------------------------------------------------------------- --- [E181] Potential Issue Error: tests/neg/i17266.scala:17:2 ----------------------------------------------------------- -17 | synchronized { // error - | ^^^^^^^^^^^^ - | Suspicious top-level unqualified call to synchronized - |-------------------------------------------------------------------------------------------------------------------- - | Explanation (enabled by `-explain`) - |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | Top-level unqualified calls to AnyRef or Any methods such as synchronized are - | resolved to calls on Predef or on imported methods. This might not be what - | you intended. - -------------------------------------------------------------------------------------------------------------------- --- [E187] Potential Issue Error: tests/neg/i17266.scala:22:4 ----------------------------------------------------------- -22 | 1.synchronized { // error - | ^^^^^^^^^^^^^^ - | Suspicious synchronized call on boxed class - |-------------------------------------------------------------------------------------------------------------------- - | Explanation (enabled by `-explain`) - |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | You called the synchronized method on a boxed primitive. This might not be what - | you intended. - -------------------------------------------------------------------------------------------------------------------- --- [E181] Potential Issue Error: tests/neg/i17266.scala:108:2 ---------------------------------------------------------- -108 | wait() // error - | ^^^^ - | Suspicious top-level unqualified call to wait - |------------------------------------------------------------------------------------------------------------------- - | Explanation (enabled by `-explain`) - |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | Top-level unqualified calls to AnyRef or Any methods such as wait are - | resolved to calls on Predef or on imported methods. This might not be what - | you intended. - ------------------------------------------------------------------------------------------------------------------- --- [E181] Potential Issue Error: tests/neg/i17266.scala:115:2 ---------------------------------------------------------- -115 | wait() // error - | ^^^^ - | Suspicious top-level unqualified call to wait - |------------------------------------------------------------------------------------------------------------------- - | Explanation (enabled by `-explain`) - |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | Top-level unqualified calls to AnyRef or Any methods such as wait are - | resolved to calls on Predef or on imported methods. This might not be what - | you intended. - ------------------------------------------------------------------------------------------------------------------- --- [E181] Potential Issue Error: tests/neg/i17266.scala:121:2 ---------------------------------------------------------- -121 | wait(10) // error - | ^^^^ - | Suspicious top-level unqualified call to wait - |------------------------------------------------------------------------------------------------------------------- - | Explanation (enabled by `-explain`) - |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | Top-level unqualified calls to AnyRef or Any methods such as wait are - | resolved to calls on Predef or on imported methods. This might not be what - | you intended. - ------------------------------------------------------------------------------------------------------------------- --- [E181] Potential Issue Error: tests/neg/i17266.scala:128:2 ---------------------------------------------------------- -128 | wait(10) // error - | ^^^^ - | Suspicious top-level unqualified call to wait - |------------------------------------------------------------------------------------------------------------------- - | Explanation (enabled by `-explain`) - |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | Top-level unqualified calls to AnyRef or Any methods such as wait are - | resolved to calls on Predef or on imported methods. This might not be what - | you intended. - ------------------------------------------------------------------------------------------------------------------- --- [E181] Potential Issue Error: tests/neg/i17266.scala:134:2 ---------------------------------------------------------- -134 | hashCode() // error - | ^^^^^^^^ - | Suspicious top-level unqualified call to hashCode - |------------------------------------------------------------------------------------------------------------------- - | Explanation (enabled by `-explain`) - |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | Top-level unqualified calls to AnyRef or Any methods such as hashCode are - | resolved to calls on Predef or on imported methods. This might not be what - | you intended. - ------------------------------------------------------------------------------------------------------------------- --- [E181] Potential Issue Error: tests/neg/i17266.scala:141:2 ---------------------------------------------------------- -141 | hashCode() // error - | ^^^^^^^^ - | Suspicious top-level unqualified call to hashCode - |------------------------------------------------------------------------------------------------------------------- - | Explanation (enabled by `-explain`) - |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | Top-level unqualified calls to AnyRef or Any methods such as hashCode are - | resolved to calls on Predef or on imported methods. This might not be what - | you intended. - ------------------------------------------------------------------------------------------------------------------- diff --git a/tests/neg/i17266.scala b/tests/neg/i17266.scala deleted file mode 100644 index 439abafc44a1..000000000000 --- a/tests/neg/i17266.scala +++ /dev/null @@ -1,144 +0,0 @@ -//> using options -Werror -explain - -def test1 = - synchronized { // error - println("hello") - } - -def test2 = - this.synchronized { // not an error (should be?) - println("hello") - } - -object MyLib - -def test3 = - import MyLib.* - synchronized { // error - println("hello") - } - -def test4 = - 1.synchronized { // error - println("hello") - } - -object Test4: - synchronized { // not an error - println("hello") - } - -object Test5: - def test5 = - synchronized { // not an error - println("hello") - } - -object Test6: - import MyLib.* - synchronized { // not an error - println("hello") - } - -object Test7: - import MyLib.* - def test7 = - synchronized { // not an error - println("hello") - } - -/* -object Test7b: - def test8 = - import MyLib.* - synchronized { // already an error: Reference to synchronized is ambiguous. - println("hello") - } -*/ - -class Test8: - synchronized { // not an error - println("hello") - } - -class Test9: - def test5 = - synchronized { // not an error - println("hello") - } - -class Test10: - import MyLib.* - synchronized { // not an error - println("hello") - } - -class Test11: - import MyLib.* - def test7 = - synchronized { // not an error - println("hello") - } - -trait Test12: - synchronized { // not an error - println("hello") - } - -trait Test13: - def test5 = - synchronized { // not an error - println("hello") - } - -trait Test14: - import MyLib.* - synchronized { // not an error - println("hello") - } - -trait Test15: - import MyLib.* - def test7 = - synchronized { // not an error - println("hello") - } - -def test16 = - wait() // error - -def test17 = - this.wait() // not an error (should be?) - -def test18 = - import MyLib.* - wait() // error - -def test19 = - 1.wait() // not an error (should be?) - -def test20 = - wait(10) // error - -def test21 = - this.wait(10) // not an error (should be?) - -def test22 = - import MyLib.* - wait(10) // error - -def test23 = - 1.wait(10) // not an error (should be?) - -def test24 = - hashCode() // error - -def test25 = - this.hashCode() // not an error (should be?) - -def test26 = - import MyLib.* - hashCode() // error - -def test27 = - 1.hashCode()// not an error (should be? probably not) diff --git a/tests/neg/i17314b.scala b/tests/neg/i17314b.scala deleted file mode 100644 index 9e89fecde935..000000000000 --- a/tests/neg/i17314b.scala +++ /dev/null @@ -1,14 +0,0 @@ -//> using options -Xfatal-warnings -Wunused:all - -package foo: - class Foo[T] - given Foo[Int] = new Foo[Int] - - -package bar: - import foo.{given foo.Foo[Int]} // error - import foo.Foo - - given Foo[Int] = ??? - - val repro: Foo[Int] = summon[Foo[Int]] diff --git a/tests/neg/i17612a.check b/tests/neg/i17612a.check deleted file mode 100644 index 04a5b07b6e33..000000000000 --- a/tests/neg/i17612a.check +++ /dev/null @@ -1,32 +0,0 @@ --- Error: tests/neg/i17612a.scala:18:15 -------------------------------------------------------------------------------- -18 | class Derived(x : Int, y: Int, z2: Int) extends Base(x, y + 1, z2): // error // error / for x, y translated to private[this] x field & shadowing var Base.x, Base.y - | ^ - | value x in class Derived shadows field x inherited from class Base --- Error: tests/neg/i17612a.scala:18:24 -------------------------------------------------------------------------------- -18 | class Derived(x : Int, y: Int, z2: Int) extends Base(x, y + 1, z2): // error // error / for x, y translated to private[this] x field & shadowing var Base.x, Base.y - | ^ - | value y in class Derived shadows field y inherited from class Base --- Error: tests/neg/i17612a.scala:20:2 --------------------------------------------------------------------------------- -20 | private val shadowed2 = 2 + 2 // error (In Scala 2 we cannot do that got the warning) - | ^ - | value shadowed2 in class Derived shadows field shadowed2 inherited from class Base --- Error: tests/neg/i17612a.scala:21:2 --------------------------------------------------------------------------------- -21 | private[this] val shadowed3 = 3 + 3 // error - | ^ - | value shadowed3 in class Derived shadows field shadowed3 inherited from class Base --- Error: tests/neg/i17612a.scala:23:2 --------------------------------------------------------------------------------- -23 | private val shadowed5 = 5 + 5 // error - | ^ - | value shadowed5 in class Derived shadows field shadowed5 inherited from class Base --- Error: tests/neg/i17612a.scala:34:20 -------------------------------------------------------------------------------- -34 | class UnderDerived(x: Int, y: Int, z: Int) extends Derived(x, y, z) // error // error // error - | ^ - | value x in class UnderDerived shadows field x inherited from class Base --- Error: tests/neg/i17612a.scala:34:28 -------------------------------------------------------------------------------- -34 | class UnderDerived(x: Int, y: Int, z: Int) extends Derived(x, y, z) // error // error // error - | ^ - | value y in class UnderDerived shadows field y inherited from class Base --- Error: tests/neg/i17612a.scala:34:36 -------------------------------------------------------------------------------- -34 | class UnderDerived(x: Int, y: Int, z: Int) extends Derived(x, y, z) // error // error // error - | ^ - | value z in class UnderDerived shadows field z inherited from class Base diff --git a/tests/neg/i17612a.scala b/tests/neg/i17612a.scala deleted file mode 100644 index 099b528965e1..000000000000 --- a/tests/neg/i17612a.scala +++ /dev/null @@ -1,42 +0,0 @@ -//> using options -Xfatal-warnings -Xlint:private-shadow -source:3.3 - -object i17612a: - class Base(var x: Int, val y: Int, var z: Int): - var shadowed2 = 2 - val shadowed3 = 3 - val shadowed4 = 4 - protected var shadowed5 = 5 - //var shadowed6 = 6 - - val notShadowed = -1 - private val notShadowed2 = -2 - //val fatalOverride = 0 - - def increment(): Unit = - x = x + 1 - - class Derived(x : Int, y: Int, z2: Int) extends Base(x, y + 1, z2): // error // error / for x, y translated to private[this] x field & shadowing var Base.x, Base.y - private def hello() = 4 - private val shadowed2 = 2 + 2 // error (In Scala 2 we cannot do that got the warning) - private[this] val shadowed3 = 3 + 3 // error - //private[Derived] val fatalOverride = 0 // value fatalOverride of type Int has weaker access privileges; it should be public - private val shadowed5 = 5 + 5 // error - private val notShadowed2 = -4 - //protected var shadowed6 = 6 + 6 // variable shadowed6 of type Int has weaker access privileges; it should be public - - def inFunctionScope() = - val notShadowed = -2 // OK - -2 - - override def toString = - s"x : ${x.toString}, y : ${y.toString}" - - class UnderDerived(x: Int, y: Int, z: Int) extends Derived(x, y, z) // error // error // error - - def main(args: Array[String]) = - val derived = new Derived(1, 1, 1) - println(derived.toString) // yields x: '1', as expected - derived.increment() - println(derived.toString) // still x: '1', probably unexpected, for y it never prints the super value, less surprising - println(derived.shadowed2) - println(derived.shadowed3) \ No newline at end of file diff --git a/tests/neg/i17612b.check b/tests/neg/i17612b.check index 75e8b7312833..ae5b071d6187 100644 --- a/tests/neg/i17612b.check +++ b/tests/neg/i17612b.check @@ -1,32 +1,33 @@ --- Error: tests/neg/i17612b/i17612b.scala:21:15 ------------------------------------------------------------------------ -21 | class Derived(x : Int, x3: Int, y: Int, z2: Int) extends BaseB, BaseC(x3), Base(x, y + 1, z2): // error // error / for x, y translated to private[this] x field & shadowing var Base.x, Base.y +-- Warning: tests/neg/i17612b/i17612b.scala:21:15 ---------------------------------------------------------------------- +21 | class Derived(x : Int, x3: Int, y: Int, z2: Int) extends BaseB, BaseC(x3), Base(x, y + 1, z2): // warn // warn / for x, y translated to private[this] x field & shadowing var Base.x, Base.y | ^ | value x in class Derived shadows field x inherited from trait Base --- Error: tests/neg/i17612b/i17612b.scala:21:33 ------------------------------------------------------------------------ -21 | class Derived(x : Int, x3: Int, y: Int, z2: Int) extends BaseB, BaseC(x3), Base(x, y + 1, z2): // error // error / for x, y translated to private[this] x field & shadowing var Base.x, Base.y +-- Warning: tests/neg/i17612b/i17612b.scala:21:33 ---------------------------------------------------------------------- +21 | class Derived(x : Int, x3: Int, y: Int, z2: Int) extends BaseB, BaseC(x3), Base(x, y + 1, z2): // warn // warn / for x, y translated to private[this] x field & shadowing var Base.x, Base.y | ^ | value y in class Derived shadows field y inherited from trait Base --- Error: tests/neg/i17612b/i17612b.scala:23:2 ------------------------------------------------------------------------- -23 | private val shadowed2 = 2 + 2 // error (In Scala 2 we cannot do that got the warning) +-- Warning: tests/neg/i17612b/i17612b.scala:23:2 ----------------------------------------------------------------------- +23 | private val shadowed2 = 2 + 2 // warn (In Scala 2 we cannot do that got the warning) | ^ | value shadowed2 in class Derived shadows field shadowed2 inherited from trait Base --- Error: tests/neg/i17612b/i17612b.scala:24:2 ------------------------------------------------------------------------- -24 | private[this] val shadowed3 = 3 + 3 // error +-- Warning: tests/neg/i17612b/i17612b.scala:24:2 ----------------------------------------------------------------------- +24 | private[this] val shadowed3 = 3 + 3 // warn | ^ | value shadowed3 in class Derived shadows field shadowed3 inherited from trait Base --- Error: tests/neg/i17612b/i17612b.scala:26:2 ------------------------------------------------------------------------- -26 | private val shadowed5 = 5 + 5 // error +-- Warning: tests/neg/i17612b/i17612b.scala:26:2 ----------------------------------------------------------------------- +26 | private val shadowed5 = 5 + 5 // warn | ^ | value shadowed5 in class Derived shadows field shadowed5 inherited from trait Base --- Error: tests/neg/i17612b/i17612b.scala:41:20 ------------------------------------------------------------------------ -41 | class UnderDerived(x: Int, y: Int, z: Int) extends Derived(x, 1, y, z) // error // error // error +-- Warning: tests/neg/i17612b/i17612b.scala:41:20 ---------------------------------------------------------------------- +41 | class UnderDerived(x: Int, y: Int, z: Int) extends Derived(x, 1, y, z) // warn // warn // warn | ^ | value x in class UnderDerived shadows field x inherited from trait Base --- Error: tests/neg/i17612b/i17612b.scala:41:28 ------------------------------------------------------------------------ -41 | class UnderDerived(x: Int, y: Int, z: Int) extends Derived(x, 1, y, z) // error // error // error +-- Warning: tests/neg/i17612b/i17612b.scala:41:28 ---------------------------------------------------------------------- +41 | class UnderDerived(x: Int, y: Int, z: Int) extends Derived(x, 1, y, z) // warn // warn // warn | ^ | value y in class UnderDerived shadows field y inherited from trait Base --- Error: tests/neg/i17612b/i17612b.scala:41:36 ------------------------------------------------------------------------ -41 | class UnderDerived(x: Int, y: Int, z: Int) extends Derived(x, 1, y, z) // error // error // error +-- Warning: tests/neg/i17612b/i17612b.scala:41:36 ---------------------------------------------------------------------- +41 | class UnderDerived(x: Int, y: Int, z: Int) extends Derived(x, 1, y, z) // warn // warn // warn | ^ | value z in class UnderDerived shadows field z inherited from trait Base +No warnings can be incurred under -Werror. diff --git a/tests/neg/i17612b/i17612b.scala b/tests/neg/i17612b/i17612b.scala index d16feb240c2a..a1aa1973cea2 100644 --- a/tests/neg/i17612b/i17612b.scala +++ b/tests/neg/i17612b/i17612b.scala @@ -18,12 +18,12 @@ object i17612b: trait BaseB trait BaseC(var x2: Int) - class Derived(x : Int, x3: Int, y: Int, z2: Int) extends BaseB, BaseC(x3), Base(x, y + 1, z2): // error // error / for x, y translated to private[this] x field & shadowing var Base.x, Base.y + class Derived(x : Int, x3: Int, y: Int, z2: Int) extends BaseB, BaseC(x3), Base(x, y + 1, z2): // warn // warn / for x, y translated to private[this] x field & shadowing var Base.x, Base.y private def hello() = 4 - private val shadowed2 = 2 + 2 // error (In Scala 2 we cannot do that got the warning) - private[this] val shadowed3 = 3 + 3 // error + private val shadowed2 = 2 + 2 // warn (In Scala 2 we cannot do that got the warning) + private[this] val shadowed3 = 3 + 3 // warn - private val shadowed5 = 5 + 5 // error + private val shadowed5 = 5 + 5 // warn private val notShadowed2 = -4 val lambda: Int => Int => Int = @@ -38,7 +38,8 @@ object i17612b: override def toString = s"x : ${x.toString}, y : ${y.toString}" - class UnderDerived(x: Int, y: Int, z: Int) extends Derived(x, 1, y, z) // error // error // error + class UnderDerived(x: Int, y: Int, z: Int) extends Derived(x, 1, y, z) // warn // warn // warn def main(args: Array[String]) = val derived = new Derived(1, 1, 1, 1) +// nopos-error: No warnings can be incurred under -Werror. \ No newline at end of file diff --git a/tests/neg/i17613a.check b/tests/neg/i17613a.check deleted file mode 100644 index 4721b786c82d..000000000000 --- a/tests/neg/i17613a.check +++ /dev/null @@ -1,28 +0,0 @@ --- Error: tests/neg/i17613a.scala:8:13 --------------------------------------------------------------------------------- -8 | def foobar[D](in: D) = in.toString // error method parameter shadows some other type - | ^ - | Type parameter D for method foobar shadows the type defined by trait D in class B --- Error: tests/neg/i17613a.scala:9:13 --------------------------------------------------------------------------------- -9 | type MySeq[D] = Seq[D] // error type member's parameter shadows some other type - | ^ - | Type parameter D for type MySeq shadows the type defined by trait D in class B --- Error: tests/neg/i17613a.scala:11:12 -------------------------------------------------------------------------------- -11 | class Foo[T](t: T): // error class parameter shadows some other type - | ^ - | Type parameter T for class Foo shadows the type defined by type T in class B --- Error: tests/neg/i17613a.scala:12:11 -------------------------------------------------------------------------------- -12 | def bar[T](w: T) = w.toString // error a type parameter shadows another type parameter - | ^ - | Type parameter T for method bar shadows the type defined by type T in class Foo --- Error: tests/neg/i17613a.scala:15:12 -------------------------------------------------------------------------------- -15 | class C[M[List[_]]] // error - | ^^^^^^^ - | Type parameter List for class C shadows the type defined by type List in package scala --- Error: tests/neg/i17613a.scala:16:11 -------------------------------------------------------------------------------- -16 | type E[M[List[_]]] = Int // error - | ^^^^^^^ - | Type parameter List for type E shadows the type defined by type List in package scala --- Error: tests/neg/i17613a.scala:17:14 -------------------------------------------------------------------------------- -17 | def foo[N[M[List[_]]]] = ??? // error - | ^^^^^^^ - | Type parameter List for method foo shadows the type defined by type List in package scala diff --git a/tests/neg/i17613a.scala b/tests/neg/i17613a.scala deleted file mode 100644 index d0e413098cec..000000000000 --- a/tests/neg/i17613a.scala +++ /dev/null @@ -1,23 +0,0 @@ -//> using options -Xfatal-warnings -Xlint:type-parameter-shadow - -object i17613a: - class B: - type T = Int - trait D - - def foobar[D](in: D) = in.toString // error method parameter shadows some other type - type MySeq[D] = Seq[D] // error type member's parameter shadows some other type - - class Foo[T](t: T): // error class parameter shadows some other type - def bar[T](w: T) = w.toString // error a type parameter shadows another type parameter - - // even deeply nested... - class C[M[List[_]]] // error - type E[M[List[_]]] = Int // error - def foo[N[M[List[_]]]] = ??? // error - - // ...but not between type parameters in the same list - class F[A, M[N[A]]] - type G[A, M[L[A]]] = Int - def bar[A, N[M[L[A]]]] = ??? - def main(args: Array[String]) = println("Test for type parameter shadow") diff --git a/tests/neg/i17613b.check b/tests/neg/i17613b.check index d8cf8618fb27..15dd2f6451e6 100644 --- a/tests/neg/i17613b.check +++ b/tests/neg/i17613b.check @@ -1,56 +1,61 @@ --- Error: tests/neg/i17613b/i17613b.scala:9:13 ------------------------------------------------------------------------- -9 | def foobar[ImTrait](in: D) = in.toString // error - | ^^^^^^^ - | Type parameter ImTrait for method foobar shadows the type defined by trait ImTrait in object importTry --- Error: tests/neg/i17613b/i17613b.scala:10:13 ------------------------------------------------------------------------ -10 | type MySeq[ImTrait] = Seq[D] // error +-- Warning: tests/neg/i17613b/i17613b.scala:7:18 ----------------------------------------------------------------------- +7 | trait Typeclass[T] + | ^ + | Type parameter T for trait Typeclass shadows the type defined by type T in class B +-- Warning: tests/neg/i17613b/i17613b.scala:10:13 ---------------------------------------------------------------------- +10 | def foobar[ImTrait](in: D) = in.toString // warn + | ^^^^^^^ + | Type parameter ImTrait for method foobar shadows the type defined by trait ImTrait in object importTry +-- Warning: tests/neg/i17613b/i17613b.scala:11:13 ---------------------------------------------------------------------- +11 | type MySeq[ImTrait] = Seq[D] // warn | ^^^^^^^ | Type parameter ImTrait for type MySeq shadows the type defined by trait ImTrait in object importTry --- Error: tests/neg/i17613b/i17613b.scala:12:14 ------------------------------------------------------------------------ -12 | def foobar2[ImClass](in: D) = in.toString // error +-- Warning: tests/neg/i17613b/i17613b.scala:13:14 ---------------------------------------------------------------------- +13 | def foobar2[ImClass](in: D) = in.toString // warn | ^^^^^^^ | Type parameter ImClass for method foobar2 shadows the type defined by class ImClass in object importTry --- Error: tests/neg/i17613b/i17613b.scala:13:14 ------------------------------------------------------------------------ -13 | type MySeq2[ImClass] = Seq[D] // error +-- Warning: tests/neg/i17613b/i17613b.scala:14:14 ---------------------------------------------------------------------- +14 | type MySeq2[ImClass] = Seq[D] // warn | ^^^^^^^ | Type parameter ImClass for type MySeq2 shadows the type defined by class ImClass in object importTry --- Error: tests/neg/i17613b/i17613b.scala:16:24 ------------------------------------------------------------------------ -16 | type TypeLambda[A] = [ImTrait] =>> Map[ImTrait, B] // error +-- Warning: tests/neg/i17613b/i17613b.scala:17:24 ---------------------------------------------------------------------- +17 | type TypeLambda[A] = [ImTrait] =>> Map[ImTrait, B] | ^^^^^^^ | Type parameter ImTrait for type TypeLambda shadows the type defined by trait ImTrait in object importTry --- Error: tests/neg/i17613b/i17613b.scala:17:21 ------------------------------------------------------------------------ -17 | type PolyFun[A] = [ImTrait] => ImTrait => B // error +-- Warning: tests/neg/i17613b/i17613b.scala:18:21 ---------------------------------------------------------------------- +18 | type PolyFun[A] = [ImTrait] => ImTrait => B // warn | ^^^^^^^ | Type parameter ImTrait for type PolyFun shadows the type defined by trait ImTrait in object importTry --- Error: tests/neg/i17613b/i17613b.scala:23:12 ------------------------------------------------------------------------ -23 | class Foo[T](t: T): // error class parameter shadows some other type +-- Warning: tests/neg/i17613b/i17613b.scala:24:12 ---------------------------------------------------------------------- +24 | class Foo[T](t: T): // warn class parameter shadows some other type | ^ | Type parameter T for class Foo shadows the type defined by type T in class B --- Error: tests/neg/i17613b/i17613b.scala:27:15 ------------------------------------------------------------------------ -27 | def intType[List1](x: T) = x.toString() // error +-- Warning: tests/neg/i17613b/i17613b.scala:28:15 ---------------------------------------------------------------------- +28 | def intType[List1](x: T) = x.toString() // warn | ^^^^^ | Type parameter List1 for method intType shadows an explicitly renamed type : List1 --- Error: tests/neg/i17613b/i17613b.scala:32:10 ------------------------------------------------------------------------ -32 | given [Int]: Ordering[Int]() // error +-- Warning: tests/neg/i17613b/i17613b.scala:33:10 ---------------------------------------------------------------------- +33 | given [Int]: Typeclass[Int]() // warn | ^^^ - | Type parameter Int for method given_Ordering_Int shadows the type defined by class Int in package scala --- Error: tests/neg/i17613b/i17613b.scala:34:12 ------------------------------------------------------------------------ -34 | class C[M[List[_]]] // error List not renamed here + | Type parameter Int for method given_Typeclass_Int shadows the type defined by class Int in package scala +-- Warning: tests/neg/i17613b/i17613b.scala:35:12 ---------------------------------------------------------------------- +35 | class C[M[List[_]]] // warn List not renamed here | ^^^^^^^ | Type parameter List for class C shadows the type defined by type List in package scala --- Error: tests/neg/i17613b/i17613b.scala:35:11 ------------------------------------------------------------------------ -35 | type E[M[Int[_]]] = Int // error +-- Warning: tests/neg/i17613b/i17613b.scala:36:11 ---------------------------------------------------------------------- +36 | type E[M[Int[_]]] = Int // warn | ^^^^^^ | Type parameter Int for type E shadows the type defined by class Int in package scala --- Error: tests/neg/i17613b/i17613b.scala:37:14 ------------------------------------------------------------------------ -37 | def foo[N[M[List[_]]]] = // error +-- Warning: tests/neg/i17613b/i17613b.scala:38:14 ---------------------------------------------------------------------- +38 | def foo[N[M[List[_]]]] = // warn | ^^^^^^^ | Type parameter List for method foo shadows the type defined by type List in package scala --- Error: tests/neg/i17613b/i17613b.scala:40:11 ------------------------------------------------------------------------ -40 | type Z[ImClassR] = Int // error +-- Warning: tests/neg/i17613b/i17613b.scala:41:11 ---------------------------------------------------------------------- +41 | type Z[ImClassR] = Int // warn | ^^^^^^^^ | Type parameter ImClassR for type Z shadows an explicitly renamed type : ImClassR --- Error: tests/neg/i17613b/i17613b.scala:41:18 ------------------------------------------------------------------------ -41 | class InnerCl[ImClassR] // error +-- Warning: tests/neg/i17613b/i17613b.scala:42:18 ---------------------------------------------------------------------- +42 | class InnerCl[ImClassR] // warn | ^^^^^^^^ | Type parameter ImClassR for class InnerCl shadows an explicitly renamed type : ImClassR +No warnings can be incurred under -Werror. diff --git a/tests/neg/i17613b/i17613b.scala b/tests/neg/i17613b/i17613b.scala index b0c4f11b949c..42506a274a65 100644 --- a/tests/neg/i17613b/i17613b.scala +++ b/tests/neg/i17613b/i17613b.scala @@ -1,44 +1,47 @@ -//> using options -Xfatal-warnings -Xlint:type-parameter-shadow +//> using options -Xlint:type-parameter-shadow -Xfatal-warnings object i17613b: import importTry._ class B: type T = Int + trait Typeclass[T] trait D - def foobar[ImTrait](in: D) = in.toString // error - type MySeq[ImTrait] = Seq[D] // error + def foobar[ImTrait](in: D) = in.toString // warn + type MySeq[ImTrait] = Seq[D] // warn - def foobar2[ImClass](in: D) = in.toString // error - type MySeq2[ImClass] = Seq[D] // error + def foobar2[ImClass](in: D) = in.toString // warn + type MySeq2[ImClass] = Seq[D] // warn - given [A]: Ordering[Int]() - type TypeLambda[A] = [ImTrait] =>> Map[ImTrait, B] // error - type PolyFun[A] = [ImTrait] => ImTrait => B // error + given [A]: Typeclass[Int]() // warn + type TypeLambda[A] = [ImTrait] =>> Map[ImTrait, B] + type PolyFun[A] = [ImTrait] => ImTrait => B // warn type MatchType[A] = A match { case String => Int case ImTrait => Boolean } - class Foo[T](t: T): // error class parameter shadows some other type + class Foo[T](t: T): // warn class parameter shadows some other type import scala.collection.immutable.{List => List1} def bar[List](w: T) = w.toString // no warning due to the explicit import renaming - def intType[List1](x: T) = x.toString() // error + def intType[List1](x: T) = x.toString() // warn type Y[List] = Int // no warning - given [A]: Ordering[A]() - given [Int]: Ordering[Int]() // error + given [A]: Typeclass[A]() + given [Int]: Typeclass[Int]() // warn - class C[M[List[_]]] // error List not renamed here - type E[M[Int[_]]] = Int // error + class C[M[List[_]]] // warn List not renamed here + type E[M[Int[_]]] = Int // warn - def foo[N[M[List[_]]]] = // error + def foo[N[M[List[_]]]] = // warn import importTry.{ImClass => ImClassR} def inner[ImClass] = // no warning - type Z[ImClassR] = Int // error - class InnerCl[ImClassR] // error + type Z[ImClassR] = Int // warn + class InnerCl[ImClassR] // warn 5 - def main(args: Array[String]) = println("Test for type parameter shadow") \ No newline at end of file + def main(args: Array[String]) = println("Test for type parameter shadow") + + // nopos-error fatal warnings diff --git a/tests/neg/i18722.check b/tests/neg/i18722.check deleted file mode 100644 index 539e23787752..000000000000 --- a/tests/neg/i18722.check +++ /dev/null @@ -1,44 +0,0 @@ --- [E190] Potential Issue Error: tests/neg/i18722.scala:3:15 ----------------------------------------------------------- -3 |def f1: Unit = null // error - | ^^^^ - | Discarded non-Unit value of type Null. You may want to use `()`. - |--------------------------------------------------------------------------------------------------------------------- - | Explanation (enabled by `-explain`) - |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | As this expression is not of type Unit, it is desugared into `{ null; () }`. - | Here the `null` expression is a pure statement that can be discarded. - | Therefore the expression is effectively equivalent to `()`. - --------------------------------------------------------------------------------------------------------------------- --- [E190] Potential Issue Error: tests/neg/i18722.scala:4:15 ----------------------------------------------------------- -4 |def f2: Unit = 1 // error - | ^ - | Discarded non-Unit value of type Int. You may want to use `()`. - |--------------------------------------------------------------------------------------------------------------------- - | Explanation (enabled by `-explain`) - |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | As this expression is not of type Unit, it is desugared into `{ 1; () }`. - | Here the `1` expression is a pure statement that can be discarded. - | Therefore the expression is effectively equivalent to `()`. - --------------------------------------------------------------------------------------------------------------------- --- [E190] Potential Issue Error: tests/neg/i18722.scala:5:15 ----------------------------------------------------------- -5 |def f3: Unit = "a" // error - | ^^^ - | Discarded non-Unit value of type String. You may want to use `()`. - |--------------------------------------------------------------------------------------------------------------------- - | Explanation (enabled by `-explain`) - |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | As this expression is not of type Unit, it is desugared into `{ "a"; () }`. - | Here the `"a"` expression is a pure statement that can be discarded. - | Therefore the expression is effectively equivalent to `()`. - --------------------------------------------------------------------------------------------------------------------- --- [E190] Potential Issue Error: tests/neg/i18722.scala:7:15 ----------------------------------------------------------- -7 |def f4: Unit = i // error - | ^ - | Discarded non-Unit value of type Int. You may want to use `()`. - |--------------------------------------------------------------------------------------------------------------------- - | Explanation (enabled by `-explain`) - |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | As this expression is not of type Unit, it is desugared into `{ i; () }`. - | Here the `i` expression is a pure statement that can be discarded. - | Therefore the expression is effectively equivalent to `()`. - --------------------------------------------------------------------------------------------------------------------- diff --git a/tests/neg/i18722.scala b/tests/neg/i18722.scala deleted file mode 100644 index c68390b76201..000000000000 --- a/tests/neg/i18722.scala +++ /dev/null @@ -1,9 +0,0 @@ -//> using options -Werror -explain - -def f1: Unit = null // error -def f2: Unit = 1 // error -def f3: Unit = "a" // error -val i: Int = 1 -def f4: Unit = i // error -val u: Unit = () -def f5: Unit = u diff --git a/tests/neg/i18862-3.4.check b/tests/neg/i18862-3.4.check deleted file mode 100644 index b56454feeeaa..000000000000 --- a/tests/neg/i18862-3.4.check +++ /dev/null @@ -1,5 +0,0 @@ --- Error: tests/neg/i18862-3.4.scala:6:38 ------------------------------------------------------------------------------ -6 |def test(xs: List[Int]): Unit = f(xs: _*) // error: migration warning - | ^ - | The syntax `x: _*` is no longer supported for vararg splices; use `x*` instead - | This construct can be rewritten automatically under -rewrite -source 3.4-migration. diff --git a/tests/neg/i18862-3.4.scala b/tests/neg/i18862-3.4.scala deleted file mode 100644 index a30c8c8f1a59..000000000000 --- a/tests/neg/i18862-3.4.scala +++ /dev/null @@ -1,6 +0,0 @@ -//> using options -Werror - -import scala.language.`3.4` - -def f(x: Int*): Unit = () -def test(xs: List[Int]): Unit = f(xs: _*) // error: migration warning diff --git a/tests/neg/i18862-future-migration.scala b/tests/neg/i18862-future-migration.scala deleted file mode 100644 index ff8ba1c377c3..000000000000 --- a/tests/neg/i18862-future-migration.scala +++ /dev/null @@ -1,6 +0,0 @@ -//> using options -Werror - -import scala.language.`future-migration` - -def f(x: Int*): Unit = () -def test(xs: List[Int]): Unit = f(xs: _*) // error: migration warning diff --git a/tests/neg/i18867-3.4.scala b/tests/neg/i18867-3.4.scala deleted file mode 100644 index c5fd2976c8b0..000000000000 --- a/tests/neg/i18867-3.4.scala +++ /dev/null @@ -1,7 +0,0 @@ -//> using options -Werror - -import language.`3.4` - -def foo(x: Int) = x - -def test = foo _ // error diff --git a/tests/neg/i18867.check b/tests/neg/i18867.check deleted file mode 100644 index 014e9e7bd92e..000000000000 --- a/tests/neg/i18867.check +++ /dev/null @@ -1,6 +0,0 @@ --- Error: tests/neg/i18867.scala:5:15 ---------------------------------------------------------------------------------- -5 |def test = foo _ // error - | ^^^^^ - | The syntax ` _` is no longer supported; - | you can simply leave out the trailing ` _` - | This construct can be rewritten automatically under -rewrite -source 3.4-migration. diff --git a/tests/neg/i18867.scala b/tests/neg/i18867.scala deleted file mode 100644 index 722347a613f5..000000000000 --- a/tests/neg/i18867.scala +++ /dev/null @@ -1,5 +0,0 @@ -//> using options -Werror - -def foo(x: Int) = x - -def test = foo _ // error diff --git a/tests/neg/i2333.scala b/tests/neg/i2333.scala deleted file mode 100644 index 67cddbc73f48..000000000000 --- a/tests/neg/i2333.scala +++ /dev/null @@ -1,11 +0,0 @@ -//> using options -Xfatal-warnings -deprecation - -@deprecated("bla", "2.11.0") class Foo { - println("") - def this(x: Int) = this() -} - -object Test { - new Foo // error: deprecated - new Foo(1) // error: deprecated -} \ No newline at end of file diff --git a/tests/neg/i2673.scala b/tests/neg/i2673.scala deleted file mode 100644 index 62c787fa00fb..000000000000 --- a/tests/neg/i2673.scala +++ /dev/null @@ -1,6 +0,0 @@ -//> using options -Xfatal-warnings - -package Foos - -class Foo // error -class foo diff --git a/tests/neg/i2673b.scala b/tests/neg/i2673b.scala deleted file mode 100644 index 26e09ec3297e..000000000000 --- a/tests/neg/i2673b.scala +++ /dev/null @@ -1,6 +0,0 @@ -//> using options -Xfatal-warnings - -package Foos - -class Bar // error -object bar diff --git a/tests/neg/i2673c.scala b/tests/neg/i2673c.scala deleted file mode 100644 index 575d8c25d9e0..000000000000 --- a/tests/neg/i2673c.scala +++ /dev/null @@ -1,8 +0,0 @@ -//> using options -Xfatal-warnings - -package Foos - -object Outer { - case class X() // error - object x -} diff --git a/tests/neg/i3561.scala b/tests/neg/i3561.scala deleted file mode 100644 index 862e65f3c2f7..000000000000 --- a/tests/neg/i3561.scala +++ /dev/null @@ -1,18 +0,0 @@ -//> using options -Xfatal-warnings - -class Test { - val Constant = 'Q' // OK if final - def tokenMe(ch: Char) = (ch: @annotation.switch) match { // error: could not emit switch - case ' ' => 1 - case 'A' => 2 - case '5' | Constant => 3 - case '4' => 4 - } - - def test2(x: Any) = (x: @annotation.switch) match { // error: could not emit switch - case ' ' => 1 - case 'A' => 2 - case '5' | Constant => 3 - case '4' => 4 - } -} diff --git a/tests/neg/i4008.check b/tests/neg/i4008.check deleted file mode 100644 index c1f27866d1c1..000000000000 --- a/tests/neg/i4008.check +++ /dev/null @@ -1,40 +0,0 @@ --- [E158] Reference Error: tests/neg/i4008.scala:7:56 ------------------------------------------------------------------ -7 |@annotation.implicitNotFound("An implicit ShouldWarn1[${B}] is not in scope") // error - | ^ - | Invalid reference to a type variable `B` found in the annotation argument. - | The variable does not occur as a parameter in the scope of type `ShouldWarn1`. --- [E158] Reference Error: tests/neg/i4008.scala:11:56 ----------------------------------------------------------------- -11 |@annotation.implicitNotFound("An implicit ShouldWarn2[${A}] is not in scope") // error - | ^ - | Invalid reference to a type variable `A` found in the annotation argument. - | The variable does not occur as a parameter in the scope of type `ShouldWarn2`. --- [E158] Reference Error: tests/neg/i4008.scala:15:56 ----------------------------------------------------------------- -15 |@annotation.implicitNotFound("An implicit ShouldWarn3[${A},${B}] is not in scope") // error - | ^ - | Invalid reference to a type variable `A` found in the annotation argument. - | The variable does not occur as a parameter in the scope of type `ShouldWarn3`. --- [E158] Reference Error: tests/neg/i4008.scala:19:56 ----------------------------------------------------------------- -19 |@annotation.implicitNotFound("An implicit ShouldWarn4[${A},${B}] is not in scope") // error // error - | ^ - | Invalid reference to a type variable `A` found in the annotation argument. - | The variable does not occur as a parameter in the scope of type `ShouldWarn4`. --- [E158] Reference Error: tests/neg/i4008.scala:19:61 ----------------------------------------------------------------- -19 |@annotation.implicitNotFound("An implicit ShouldWarn4[${A},${B}] is not in scope") // error // error - | ^ - | Invalid reference to a type variable `B` found in the annotation argument. - | The variable does not occur as a parameter in the scope of type `ShouldWarn4`. --- [E158] Reference Error: tests/neg/i4008.scala:23:61 ----------------------------------------------------------------- -23 |@annotation.implicitNotFound("An implicit ShouldWarn5[${C},${Abc}] is not in scope") // error - | ^ - | Invalid reference to a type variable `Abc` found in the annotation argument. - | The variable does not occur as a parameter in the scope of type `ShouldWarn5`. --- [E158] Reference Error: tests/neg/i4008.scala:46:54 ----------------------------------------------------------------- -46 |class C[A](using @annotation.implicitNotFound("No C[${B}] found") c: Class[A]) // error - | ^ - | Invalid reference to a type variable `B` found in the annotation argument. - | The variable does not occur as a parameter in the scope of the constructor of `C`. --- [E158] Reference Error: tests/neg/i4008.scala:48:62 ----------------------------------------------------------------- -48 |def someMethod1[A](using @annotation.implicitNotFound("No C[${B}] found") sc: C[A]) = 0 // error - | ^ - | Invalid reference to a type variable `B` found in the annotation argument. - | The variable does not occur as a parameter in the scope of method `someMethod1`. diff --git a/tests/neg/i4008.scala b/tests/neg/i4008.scala deleted file mode 100644 index 5b851c987e37..000000000000 --- a/tests/neg/i4008.scala +++ /dev/null @@ -1,50 +0,0 @@ -//> using options -Xfatal-warnings - -// ===== Template annotations ===== - - -// class, 1TP, invalid ref -@annotation.implicitNotFound("An implicit ShouldWarn1[${B}] is not in scope") // error -class ShouldWarn1[A] - -// trait, 1TP, invalid ref -@annotation.implicitNotFound("An implicit ShouldWarn2[${A}] is not in scope") // error -trait ShouldWarn2[B] - -// trait, 2TP, 1 invalid ref -@annotation.implicitNotFound("An implicit ShouldWarn3[${A},${B}] is not in scope") // error -trait ShouldWarn3[B, C] - -// class, 2TP, 2 invalid refs -@annotation.implicitNotFound("An implicit ShouldWarn4[${A},${B}] is not in scope") // error // error -class ShouldWarn4[C, D] - -// class, 2TP, 1 invalid multi-char refs -@annotation.implicitNotFound("An implicit ShouldWarn5[${C},${Abc}] is not in scope") // error -class ShouldWarn5[C, D] - -// trait, 1TP, valid ref -@annotation.implicitNotFound("An implicit ShouldntWarn1[${A}] is not in scope") -trait ShouldntWarn1[A] - -// class, 2TP, only one ref but that one is valid -@annotation.implicitNotFound("An implicit ShouldntWarn2[${A}, ...] is not in scope") -class ShouldntWarn2[A, B] - -// trait, 2TP, 2 valid refs -@annotation.implicitNotFound("An implicit ShouldntWarn3[${A}, ${B}] is not in scope") -trait ShouldntWarn3[A, B] - -// class, 2TP, 2 valid refs -@annotation.implicitNotFound("An implicit ShouldntWarn4[${Hello},${World}] is not in scope") -class ShouldntWarn4[Hello, World] - -// ===== DefDef param annotations ===== - - -@annotation.implicitNotFound("Hopefully you don't see this!") -class C[A](using @annotation.implicitNotFound("No C[${B}] found") c: Class[A]) // error - -def someMethod1[A](using @annotation.implicitNotFound("No C[${B}] found") sc: C[A]) = 0 // error - -def someMethod2[A](using @annotation.implicitNotFound("No C[${A}] found") sc: C[A]) = "" \ No newline at end of file diff --git a/tests/neg/i4364.scala b/tests/neg/i4364.scala deleted file mode 100644 index 85dca443f6d4..000000000000 --- a/tests/neg/i4364.scala +++ /dev/null @@ -1,11 +0,0 @@ -//> using options -Xfatal-warnings - -object Test { - def foo(c: java.util.function.Consumer[Integer]) = c.accept(0) - def f(x: Int): Unit = () - - def main(args: Array[String]) = { - foo(f) // Ok: Consumer is @FunctionalInterface - new java.io.ObjectOutputStream(f) // error: OutputStream is not @FunctionalInterface - } -} diff --git a/tests/neg/i4812.check b/tests/neg/i4812.check deleted file mode 100644 index f4aee0e35dde..000000000000 --- a/tests/neg/i4812.check +++ /dev/null @@ -1,42 +0,0 @@ --- [E092] Pattern Match Error: tests/neg/i4812.scala:8:11 -------------------------------------------------------------- -8 | case prev: A => // error: the type test for A cannot be checked at runtime - | ^ - | the type test for A cannot be checked at runtime because it's a local class - | - | longer explanation available when compiling with `-explain` --- [E092] Pattern Match Error: tests/neg/i4812.scala:18:11 ------------------------------------------------------------- -18 | case prev: A => // error: the type test for A cannot be checked at runtime - | ^ - | the type test for A cannot be checked at runtime because it's a local class - | - | longer explanation available when compiling with `-explain` --- [E092] Pattern Match Error: tests/neg/i4812.scala:28:11 ------------------------------------------------------------- -28 | case prev: A => // error: the type test for A cannot be checked at runtime - | ^ - | the type test for A cannot be checked at runtime because it's a local class - | - | longer explanation available when compiling with `-explain` --- [E092] Pattern Match Error: tests/neg/i4812.scala:38:11 ------------------------------------------------------------- -38 | case prev: A => // error: the type test for A cannot be checked at runtime - | ^ - | the type test for A cannot be checked at runtime because it's a local class - | - | longer explanation available when compiling with `-explain` --- [E092] Pattern Match Error: tests/neg/i4812.scala:50:13 ------------------------------------------------------------- -50 | case prev: A => // error: the type test for A cannot be checked at runtime - | ^ - | the type test for A cannot be checked at runtime because it's a local class - | - | longer explanation available when compiling with `-explain` --- [E092] Pattern Match Error: tests/neg/i4812.scala:60:11 ------------------------------------------------------------- -60 | case prev: A => // error: the type test for A cannot be checked at runtime - | ^ - | the type test for A cannot be checked at runtime because it's a local class - | - | longer explanation available when compiling with `-explain` --- [E092] Pattern Match Error: tests/neg/i4812.scala:96:11 ------------------------------------------------------------- -96 | case x: B => // error: the type test for B cannot be checked at runtime - | ^ - | the type test for B cannot be checked at runtime because it's a local class - | - | longer explanation available when compiling with `-explain` diff --git a/tests/neg/i4812.scala b/tests/neg/i4812.scala deleted file mode 100644 index c6f6dafc656c..000000000000 --- a/tests/neg/i4812.scala +++ /dev/null @@ -1,119 +0,0 @@ -//> using options -Werror -object Test: - var prev: Any = scala.compiletime.uninitialized - - def test[T](x: T): T = - class A(val elem: (T, Boolean)) - prev match - case prev: A => // error: the type test for A cannot be checked at runtime - prev.elem._1 - case _ => - prev = new A((x, true)) - x - - def test2[T](x: T): T = - abstract class Parent(_elem: T) { def elem: T = _elem } - class A extends Parent(x) - prev match - case prev: A => // error: the type test for A cannot be checked at runtime - prev.elem - case _ => - prev = new A - x - - def test3[T](x: T): T = - class Holder(val elem: T) - class A(val holder: Holder) - prev match - case prev: A => // error: the type test for A cannot be checked at runtime - prev.holder.elem - case _ => - prev = new A(new Holder(x)) - x - - def test4[T](x: T): T = - class Holder(val elem: (Int, (Unit, (T, Boolean)))) - class A { var holder: Holder = null } - prev match - case prev: A => // error: the type test for A cannot be checked at runtime - prev.holder.elem._2._2._1 - case _ => - val a = new A - a.holder = new Holder((42, ((), (x, true)))) - prev = a - x - - class Foo[U]: - def test5(x: U): U = - class A(val elem: U) - prev match - case prev: A => // error: the type test for A cannot be checked at runtime - prev.elem - case _ => - prev = new A(x) - x - - def test6[T](x: T): T = - class A { var b: B = null } - class B { var a: A = null; var elem: T = scala.compiletime.uninitialized } - prev match - case prev: A => // error: the type test for A cannot be checked at runtime - prev.b.elem - case _ => - val a = new A - val b = new B - b.elem = x - a.b = b - prev = a - x - - def test7[T](x: T): T = - class A(val elem: T) - prev match - case prev: A @unchecked => prev.elem - case _ => prev = new A(x); x - - def test8[T](x: T): T = - class A(val elem: T) - val p = prev - (p: @unchecked) match - case prev: A => prev.elem - case _ => prev = new A(x); x - - def test9 = - trait A - class B extends A - val x: A = new B - x match - case x: B => x - - sealed class A - var prevA: A = scala.compiletime.uninitialized - def test10: A = - val methodCallId = System.nanoTime() - class B(val id: Long) extends A - prevA match - case x: B => // error: the type test for B cannot be checked at runtime - x.ensuring(x.id == methodCallId, s"Method call id $methodCallId != ${x.id}") - case _ => - val x = new B(methodCallId) - prevA = x - x - - def test11 = - trait A - trait B - class C extends A with B - val x: A = new C - x match - case x: B => x - - def test12 = - class Foo - class Bar - val x: Foo | Bar = new Foo - x.isInstanceOf[Foo] - - def main(args: Array[String]): Unit = - test(1) - val x: String = test("") // was: ClassCastException: java.lang.Integer cannot be cast to java.lang.String diff --git a/tests/neg/i4936b.scala b/tests/neg/i4936b.scala deleted file mode 100644 index 58c240e92309..000000000000 --- a/tests/neg/i4936b.scala +++ /dev/null @@ -1,3 +0,0 @@ -//> using options -Xfatal-warnings - -final object Foo // error diff --git a/tests/neg/i4986b.check b/tests/neg/i4986b.check deleted file mode 100644 index db30dcba8003..000000000000 --- a/tests/neg/i4986b.check +++ /dev/null @@ -1,40 +0,0 @@ --- [E158] Reference Error: tests/neg/i4986b.scala:5:65 ----------------------------------------------------------------- -5 |@implicitNotFound(msg = "Cannot construct a collection of type ${Too} with elements of type ${Elem} based on a collection of type ${From}.") // error // error - | ^ - | Invalid reference to a type variable `Too` found in the annotation argument. - | The variable does not occur as a parameter in the scope of type `Meh`. --- [E158] Reference Error: tests/neg/i4986b.scala:5:94 ----------------------------------------------------------------- -5 |@implicitNotFound(msg = "Cannot construct a collection of type ${Too} with elements of type ${Elem} based on a collection of type ${From}.") // error // error - | ^ - | Invalid reference to a type variable `Elem` found in the annotation argument. - | The variable does not occur as a parameter in the scope of type `Meh`. --- [E158] Reference Error: tests/neg/i4986b.scala:8:71 ----------------------------------------------------------------- -8 |@implicitNotFound(msg = "Cannot construct a collection of type ${To} ${Elem}.") // error - | ^ - | Invalid reference to a type variable `Elem` found in the annotation argument. - | The variable does not occur as a parameter in the scope of type `Meh2`. --- [E158] Reference Error: tests/neg/i4986b.scala:11:46 ---------------------------------------------------------------- -11 |class C[T](implicit @implicitNotFound("No C[${t}] available") t: T) // error - | ^ - | Invalid reference to a type variable `t` found in the annotation argument. - | The variable does not occur as a parameter in the scope of the constructor of `C`. --- [E158] Reference Error: tests/neg/i4986b.scala:14:54 ---------------------------------------------------------------- -14 | def m[Aaa](implicit @implicitNotFound("I see no C[${Uuh}]") theC: C[Aaa]) = ??? // error - | ^ - | Invalid reference to a type variable `Uuh` found in the annotation argument. - | The variable does not occur as a parameter in the scope of method `m`. --- [E158] Reference Error: tests/neg/i4986b.scala:20:73 ---------------------------------------------------------------- -20 | def m[S](implicit @implicitNotFound("${X} ${Y} ${ Z } ${R} ${S} -- ${XX} ${ZZ} ${ Nix }") i: Int) = ??? // error // error // error - | ^ - | Invalid reference to a type variable `XX` found in the annotation argument. - | The variable does not occur as a parameter in the scope of method `m`. --- [E158] Reference Error: tests/neg/i4986b.scala:20:79 ---------------------------------------------------------------- -20 | def m[S](implicit @implicitNotFound("${X} ${Y} ${ Z } ${R} ${S} -- ${XX} ${ZZ} ${ Nix }") i: Int) = ??? // error // error // error - | ^ - | Invalid reference to a type variable `ZZ` found in the annotation argument. - | The variable does not occur as a parameter in the scope of method `m`. --- [E158] Reference Error: tests/neg/i4986b.scala:20:86 ---------------------------------------------------------------- -20 | def m[S](implicit @implicitNotFound("${X} ${Y} ${ Z } ${R} ${S} -- ${XX} ${ZZ} ${ Nix }") i: Int) = ??? // error // error // error - | ^ - | Invalid reference to a type variable `Nix` found in the annotation argument. - | The variable does not occur as a parameter in the scope of method `m`. diff --git a/tests/neg/i4986b.scala b/tests/neg/i4986b.scala deleted file mode 100644 index c726e40fd4d8..000000000000 --- a/tests/neg/i4986b.scala +++ /dev/null @@ -1,22 +0,0 @@ -//> using options -Xfatal-warnings - -import scala.annotation.implicitNotFound - -@implicitNotFound(msg = "Cannot construct a collection of type ${Too} with elements of type ${Elem} based on a collection of type ${From}.") // error // error -trait Meh[-From, +To] - -@implicitNotFound(msg = "Cannot construct a collection of type ${To} ${Elem}.") // error -trait Meh2[-From, +To] - -class C[T](implicit @implicitNotFound("No C[${t}] available") t: T) // error - -trait T { - def m[Aaa](implicit @implicitNotFound("I see no C[${Uuh}]") theC: C[Aaa]) = ??? // error - def n[Aaa](implicit @implicitNotFound("I see no C[${Aaa}]") theC: C[Aaa]) = ??? -} - -trait U[X, Y[_], Z[_, ZZ]] { - class I[R] { - def m[S](implicit @implicitNotFound("${X} ${Y} ${ Z } ${R} ${S} -- ${XX} ${ZZ} ${ Nix }") i: Int) = ??? // error // error // error - } -} diff --git a/tests/neg/i4986d.scala b/tests/neg/i4986d.scala index 909221bea5f0..73c92822a291 100644 --- a/tests/neg/i4986d.scala +++ b/tests/neg/i4986d.scala @@ -3,10 +3,10 @@ trait Foo[A] type Fooable[A] = { - def foo(implicit @annotation.implicitNotFound("There's no Foo[${A}]") ev: Foo[A]): Any // error + def foo(implicit @annotation.implicitNotFound("There's no Foo[${A}]") ev: Foo[A]): Any // warn type InnerFooable = { - def foo(implicit @annotation.implicitNotFound("There's no Foo[${A}]") ev: Foo[A]): Any // error + def foo(implicit @annotation.implicitNotFound("There's no Foo[${A}]") ev: Foo[A]): Any // warn } } @@ -22,3 +22,4 @@ trait Bar[A] type Barable[A] = { def bar(implicit ev: Bar[A]): Any // ok } +// nopos-error: No warnings can be incurred under -Werror. \ No newline at end of file diff --git a/tests/neg/i5013.scala b/tests/neg/i5013.scala deleted file mode 100644 index adf09e2cf3be..000000000000 --- a/tests/neg/i5013.scala +++ /dev/null @@ -1,11 +0,0 @@ -//> using options -Xfatal-warnings - -class Foo { - - def foo1: Unit = 2 // error: A pure expression does nothing in statement position - - def foo2: Unit = { - 3 // error: A pure expression does nothing in statement position - 4 // error: A pure expression does nothing in statement position - } -} diff --git a/tests/neg/i5013b.scala b/tests/neg/i5013b.scala deleted file mode 100644 index 7ccaf47c12f3..000000000000 --- a/tests/neg/i5013b.scala +++ /dev/null @@ -1,18 +0,0 @@ -//> using options -Xfatal-warnings - -class Foo { - - val a: Int = 3 - - def b: 1 = { - println("1") - 1 - } - - val c: Unit = () - - def foo1: Unit = a // error: A pure expression does nothing in statement position - def foo2: Unit = b - def foo3: Unit = c // Not addapted to { c; () } and hence c is not a statement - -} diff --git a/tests/neg/i5077.scala b/tests/neg/i5077.scala deleted file mode 100644 index d705ffe52dd9..000000000000 --- a/tests/neg/i5077.scala +++ /dev/null @@ -1,33 +0,0 @@ -//> using options -Xfatal-warnings -Wimplausible-patterns -trait Is[A] -case object IsInt extends Is[Int] -case object IsString extends Is[String] -case class C[A](is: Is[A], value: A) - -@main -def Test = { - val c_string: C[String] = C(IsString, "name") - val c_any: C[?] = c_string - val any: Any = c_string - - // Case 1: error - c_string match { - case C(IsInt, _) => println(s"An Int") // error - case C(IsString, s) => println(s"A String with length ${s.length}") - case _ => println("No match") - } - - // Case 2: Should match the second case and print the length of the string - c_any match { - case C(IsInt, i) if i < 10 => println(s"An Int less than 10") - case C(IsString, s) => println(s"A String with length ${s.length}") - case _ => println("No match") - } - - // Case 3: Same as above; should match the second case and print the length of the string - any match { - case C(IsInt, i) if i < 10 => println(s"An Int less than 10") - case C(IsString, s) => println(s"A String with length ${s.length}") - case _ => println("No match") - } -} \ No newline at end of file diff --git a/tests/neg/i6190b.check b/tests/neg/i6190b.check deleted file mode 100644 index 5d4dbd7c24cb..000000000000 --- a/tests/neg/i6190b.check +++ /dev/null @@ -1,4 +0,0 @@ --- Error: tests/neg/i6190b.scala:5:29 ---------------------------------------------------------------------------------- -5 |def foo = List("1", "2").map(Rule) // error - | ^^^^ - | The method `apply` is inserted. The auto insertion will be deprecated, please write `Rule.apply` explicitly. diff --git a/tests/neg/i6190b.scala b/tests/neg/i6190b.scala deleted file mode 100644 index 42270c1a984c..000000000000 --- a/tests/neg/i6190b.scala +++ /dev/null @@ -1,5 +0,0 @@ -//> using options -Xfatal-warnings - -case class Rule(name: String) - -def foo = List("1", "2").map(Rule) // error diff --git a/tests/neg/i7314.scala b/tests/neg/i7314.scala deleted file mode 100644 index b865f2ad881b..000000000000 --- a/tests/neg/i7314.scala +++ /dev/null @@ -1,11 +0,0 @@ -//> using options -Xfatal-warnings -source future - -@main def Test = - // conversion out of the opaque type: - val imm1 = IArray(1,2,3) // supposedly immutable - println(imm1(0)) // 1 - imm1 match { - case a: Array[Int] => // error: should not be scrutinized - a(0) = 0 - } - println(imm1(0)) // 0 diff --git a/tests/neg/i7821.scala b/tests/neg/i7821.scala deleted file mode 100644 index 5275c06e487f..000000000000 --- a/tests/neg/i7821.scala +++ /dev/null @@ -1,26 +0,0 @@ -//> using options -Xfatal-warnings - -object XObject { - opaque type X = Int - - def anX: X = 5 - - given ops: Object with { - extension (x: X) def + (y: X): X = x + y - } -} - -object MyXObject { - opaque type MyX = XObject.X - - def anX: MyX = XObject.anX - - given ops: Object with { - extension (x: MyX) def + (y: MyX): MyX = x + y // error: warring: Infinite recursive call - } -} - -object Main extends App { - println(XObject.anX + XObject.anX) // prints 10 - println(MyXObject.anX + MyXObject.anX) // infinite loop -} diff --git a/tests/neg/i7821b.scala b/tests/neg/i7821b.scala deleted file mode 100644 index f82a38d259e1..000000000000 --- a/tests/neg/i7821b.scala +++ /dev/null @@ -1,13 +0,0 @@ -//> using options -Xfatal-warnings - -object Test { - - { def f(x: Int, y: Int): Int = f(x, y) } // error - { def f(x: Int, y: Int): Int = { f(x, y) } } // error - { def f(x: Int, y: Int): Int = f(y, x) } // error - { def f(x: Int, y: Int): Int = f(x, x) } // error - { def f(x: Int, y: Int): Int = f(1, 1) } // error - { def f(x: Int, y: Int): Int = { val a = 3; f(a, 1) } } // error - { def f(x: Int): Int = f(1) } // error - -} diff --git a/tests/neg/i8427.scala b/tests/neg/i8427.scala deleted file mode 100644 index 3db449bed41c..000000000000 --- a/tests/neg/i8427.scala +++ /dev/null @@ -1,9 +0,0 @@ -//> using options -Xfatal-warnings - -@SerialVersionUID(1L) // error -trait T - -object Test { - var t: T = compiletime.uninitialized - def main(args: Array[String]) = println("hi") -} diff --git a/tests/neg/i8681.scala b/tests/neg/i8681.scala index 4d91509eb0d3..f7e7066fd2e0 100644 --- a/tests/neg/i8681.scala +++ b/tests/neg/i8681.scala @@ -13,4 +13,5 @@ val b = (A(1): A | B) match { case A(_) => "OK" case B(_) => "OK" case C(_) => "NOT OK" // error -} \ No newline at end of file +} +// nopos-error: No warnings can be incurred under -Werror. \ No newline at end of file diff --git a/tests/neg/i8711.check b/tests/neg/i8711.check index 5dbeeb22460c..10764e936b5a 100644 --- a/tests/neg/i8711.check +++ b/tests/neg/i8711.check @@ -1,12 +1,21 @@ --- [E030] Match case Unreachable Error: tests/neg/i8711.scala:9:9 ------------------------------------------------------ +-- [E030] Match case Unreachable Warning: tests/neg/i8711.scala:9:9 ---------------------------------------------------- 9 | case x: B => x // error: this case is unreachable since class A is not a subclass of class B | ^^^^ | Unreachable case --- [E030] Match case Unreachable Error: tests/neg/i8711.scala:14:9 ----------------------------------------------------- +-- [E030] Match case Unreachable Warning: tests/neg/i8711.scala:14:9 --------------------------------------------------- 14 | case x: C => x // error | ^^^^ | Unreachable case --- [E030] Match case Unreachable Error: tests/neg/i8711.scala:19:9 ----------------------------------------------------- -19 | case x: (B | C) => x // error +-- [E030] Match case Unreachable Warning: tests/neg/i8711.scala:19:9 --------------------------------------------------- +19 | case x: (B | C) => x // warn | ^^^^^^^^^^ | Unreachable case +-- Error: tests/neg/i8711.scala:9:9 ------------------------------------------------------------------------------------ +9 | case x: B => x // error: this case is unreachable since class A is not a subclass of class B + | ^ + | this case is unreachable since type A and class B are unrelated +-- Error: tests/neg/i8711.scala:14:9 ----------------------------------------------------------------------------------- +14 | case x: C => x // error + | ^ + | this case is unreachable since type A | B and class C are unrelated +No warnings can be incurred under -Werror. diff --git a/tests/neg/i8711.scala b/tests/neg/i8711.scala index 2647e20fe03b..0ae32393a327 100644 --- a/tests/neg/i8711.scala +++ b/tests/neg/i8711.scala @@ -16,7 +16,9 @@ object Test { } def baz(x: A) = x match { - case x: (B | C) => x // error + case x: (B | C) => x // warn case _ => } } + +// nopos-error: No warnings can be incurred under -Werror. \ No newline at end of file diff --git a/tests/neg/i8781b.scala b/tests/neg/i8781b.scala deleted file mode 100644 index 7c9b074e1be7..000000000000 --- a/tests/neg/i8781b.scala +++ /dev/null @@ -1,7 +0,0 @@ -//> using options -Xfatal-warnings - -object Test: - - println((3: Boolean | Int).isInstanceOf[Boolean]) - - println(3.isInstanceOf[Boolean]) // error diff --git a/tests/neg/i8922b.scala b/tests/neg/i8922b.scala deleted file mode 100644 index 9e615a8d5b58..000000000000 --- a/tests/neg/i8922b.scala +++ /dev/null @@ -1,78 +0,0 @@ -//> using options -Xfatal-warnings - -case class Token(tokenType: TokenType, lexeme: StringV, line: IntV) - -sealed trait TokenType - // Single-character tokens. -object MINUS extends TokenType -object PLUS extends TokenType -object SLASH extends TokenType -object STAR extends TokenType -object BANG extends TokenType -object BANG_EQUAL extends TokenType -object EQUAL extends TokenType -object EQUAL_EQUAL extends TokenType -object GREATER extends TokenType -object GREATER_EQUAL extends TokenType -object LESS extends TokenType -object LESS_EQUAL extends TokenType - -sealed trait Expr -case class Binary(left: Expr, operator: Token, right: Expr) extends Expr - -sealed trait Value -case class StringV(v: String) extends Value -case class IntV(v: Int) extends Value -case class DoubleV(v: Double) extends Value -case class BooleanV(v: Boolean) extends Value -case class UnitV() extends Value - -object Interpreter { - def eval(expr: Expr): Value = - expr match { - case Binary(left, op, right) => - val l = eval(left) - val r = eval(right) - (l, r, op.tokenType) match { // error - case (l: DoubleV, r: DoubleV, PLUS) => ??? - case (l: IntV, r: IntV, PLUS) => ??? - case (l: DoubleV, r: IntV, PLUS) => ??? - case (l: IntV, r: DoubleV, PLUS) => ??? - case (l: StringV, r: StringV, PLUS) => ??? - case (l: DoubleV, r: DoubleV, MINUS) => ??? - case (l: IntV, r: IntV, MINUS) => ??? - case (l: DoubleV, r: IntV, MINUS) => ??? - case (l: IntV, r: DoubleV, MINUS) => ??? - case (l: DoubleV, r: DoubleV, STAR) => ??? - case (l: IntV, r: IntV, STAR) => ??? - case (l: DoubleV, r: IntV, STAR) => ??? - case (l: IntV, r: DoubleV, STAR) => ??? - case (l: DoubleV, r: DoubleV, SLASH) => ??? - case (l: IntV, r: IntV, SLASH) => ??? - case (l: DoubleV, r: IntV, SLASH) => ??? - case (l: IntV, r: DoubleV, SLASH) => ??? - case (l: DoubleV, r: DoubleV, GREATER) => ??? - case (l: IntV, r: IntV, GREATER) => ??? - case (l: DoubleV, r: IntV, GREATER) => ??? - case (l: IntV, r: DoubleV, GREATER) => ??? - case (l: StringV, r: StringV, GREATER) => ??? - case (l: DoubleV, r: DoubleV, LESS) => ??? - case (l: IntV, r: IntV, LESS) => ??? - case (l: DoubleV, r: IntV, LESS) => ??? - case (l: IntV, r: DoubleV, LESS) => ??? - case (l: StringV, r: StringV, LESS) => ??? - case (l: DoubleV, r: DoubleV, LESS_EQUAL) => ??? - case (l: IntV, r: IntV, LESS_EQUAL) => ??? - case (l: DoubleV, r: IntV, LESS_EQUAL) => ??? - case (l: IntV, r: DoubleV, LESS_EQUAL) => ??? - case (l: StringV, r: StringV, LESS_EQUAL) => ??? - case (l: DoubleV, r: DoubleV, GREATER_EQUAL) => ??? - case (l: IntV, r: IntV, GREATER_EQUAL) => ??? - case (l: DoubleV, r: IntV, GREATER_EQUAL) => ??? - case (l: IntV, r: DoubleV, GREATER_EQUAL) => ??? - case (l: StringV, r: StringV, GREATER_EQUAL) => ??? - // case _ => ??? - } - } - -} \ No newline at end of file diff --git a/tests/neg/i9166.scala b/tests/neg/i9166.scala deleted file mode 100644 index b9644bf56f71..000000000000 --- a/tests/neg/i9166.scala +++ /dev/null @@ -1,7 +0,0 @@ -//> using options -Xfatal-warnings -Wimplausible-patterns -object UnitTest extends App { - def foo(m: Unit) = m match { - case runtime.BoxedUnit.UNIT => println("ok") // error - } - foo(()) -} diff --git a/tests/neg/i9241.scala b/tests/neg/i9241.scala deleted file mode 100644 index e7c959fc9ee2..000000000000 --- a/tests/neg/i9241.scala +++ /dev/null @@ -1,43 +0,0 @@ -//> using options -Xfatal-warnings - -class Foo { - def unary_~() : Foo = this // error - def unary_-(using Int)(): Foo = this // error - def unary_+()(implicit i: Int): Foo = this // error - def unary_![T](): Foo = this // error -} - -class Bar { - def unary_~ : Bar = this - def unary_-(using Int): Bar = this - def unary_+(implicit i: Int): Bar = this - def unary_![T]: Bar = this -} - -final class Baz private (val x: Int) extends AnyVal { - def unary_- : Baz = ??? - def unary_+[T] : Baz = ??? - def unary_!() : Baz = ??? // error - def unary_~(using Int) : Baz = ??? -} - -extension (x: Int) - def unary_- : Int = ??? - def unary_+[T] : Int = ??? - def unary_!() : Int = ??? // error - def unary_~(using Int) : Int = ??? -end extension - -extension [T](x: Short) - def unary_- : Int = ??? - def unary_+[U] : Int = ??? - def unary_!() : Int = ??? // error - def unary_~(using Int) : Int = ??? -end extension - -extension (using Int)(x: Byte) - def unary_- : Int = ??? - def unary_+[U] : Int = ??? - def unary_!() : Int = ??? // error - def unary_~(using Int) : Int = ??? -end extension diff --git a/tests/neg/i9266.check b/tests/neg/i9266.check deleted file mode 100644 index bd80a017da02..000000000000 --- a/tests/neg/i9266.check +++ /dev/null @@ -1,5 +0,0 @@ --- Error: tests/neg/i9266.scala:5:22 ----------------------------------------------------------------------------------- -5 |def test = { implicit x: Int => x + x } // error - | ^ - | This syntax is no longer supported; parameter needs to be enclosed in (...) - | This construct can be rewritten automatically under -rewrite -source future-migration. diff --git a/tests/neg/i9266.scala b/tests/neg/i9266.scala deleted file mode 100644 index e6f8db7417c7..000000000000 --- a/tests/neg/i9266.scala +++ /dev/null @@ -1,5 +0,0 @@ -//> using options -Xfatal-warnings - -import language.`future-migration` - -def test = { implicit x: Int => x + x } // error diff --git a/tests/neg/i9408a.check b/tests/neg/i9408a.check deleted file mode 100644 index d9deb9cddaf7..000000000000 --- a/tests/neg/i9408a.check +++ /dev/null @@ -1,24 +0,0 @@ --- Error: tests/neg/i9408a.scala:18:20 --------------------------------------------------------------------------------- -18 | val length: Int = "qwerty" // error - | ^^^^^^^^ - |The conversion (Test3.implicitLength : String => Int) will not be applied implicitly here in Scala 3 because only implicit methods and instances of Conversion class will continue to work as implicit views. --- Error: tests/neg/i9408a.scala:23:20 --------------------------------------------------------------------------------- -23 | val length: Int = "qwerty" // error - | ^^^^^^^^ - |The conversion (Test4.implicitLength : => String => Int) will not be applied implicitly here in Scala 3 because only implicit methods and instances of Conversion class will continue to work as implicit views. --- Error: tests/neg/i9408a.scala:28:20 --------------------------------------------------------------------------------- -28 | val length: Int = "qwerty" // error - | ^^^^^^^^ - |The conversion (Test5.implicitLength : [A]: String => Int) will not be applied implicitly here in Scala 3 because only implicit methods and instances of Conversion class will continue to work as implicit views. --- Error: tests/neg/i9408a.scala:33:20 --------------------------------------------------------------------------------- -33 | val length: Int = "qwerty" // error - | ^^^^^^^^ - |The conversion (Test6.implicitLength : Map[String, Int]) will not be applied implicitly here in Scala 3 because only implicit methods and instances of Conversion class will continue to work as implicit views. --- Error: tests/neg/i9408a.scala:37:60 --------------------------------------------------------------------------------- -37 | implicit def a2int[A](a: A)(implicit ev: A => Int): Int = a // error - | ^ - |The conversion (ev : A => Int) will not be applied implicitly here in Scala 3 because only implicit methods and instances of Conversion class will continue to work as implicit views. --- Error: tests/neg/i9408a.scala:61:2 ---------------------------------------------------------------------------------- -61 | 123.foo // error - | ^^^ - |The conversion (Test11.a2foo : [A]: A => Test11.Foo) will not be applied implicitly here in Scala 3 because only implicit methods and instances of Conversion class will continue to work as implicit views. diff --git a/tests/neg/i9408a.scala b/tests/neg/i9408a.scala deleted file mode 100644 index 594417ec3215..000000000000 --- a/tests/neg/i9408a.scala +++ /dev/null @@ -1,88 +0,0 @@ -//> using options -Xfatal-warnings - -import language.`3.0-migration` -import scala.language.implicitConversions - -object Test1 { - implicit def implicitLength(s: String): Int = s.length - val length: Int = "qwerty" // ok -} - -object Test2 { - implicit val implicitLength: Conversion[String, Int] = _.length - val length: Int = "qwerty" // ok -} - -object Test3 { - implicit val implicitLength: String => Int = _.length - val length: Int = "qwerty" // error -} - -object Test4 { - implicit def implicitLength: String => Int = _.length - val length: Int = "qwerty" // error -} - -object Test5 { - implicit def implicitLength[A]: String => Int = _.length - val length: Int = "qwerty" // error -} - -object Test6 { - implicit val implicitLength: Map[String, Int] = Map("qwerty" -> 6) - val length: Int = "qwerty" // error -} - -object Test7 { - implicit def a2int[A](a: A)(implicit ev: A => Int): Int = a // error -} - -object Test8 { - implicit def a2int[A](a: A)(implicit ev: A => Int): Int = ev(a) // ok -} - -object Test9 { - implicit def a2int[A](a: A)(implicit ev: A <:< Int): Int = a // ok -} - -object Test10 { - trait Foo { - def foo = "foo" - } - implicit def a2foo[A](a: A): Foo = new Foo {} - 123.foo // ok -} - -object Test11 { - trait Foo { - def foo = "foo" - } - implicit def a2foo[A]: A => Foo = _ => new Foo {} - 123.foo // error -} - -object Test12 { - implicit class FooOps(a: Any) { - def foo = "foo" - } - 123.foo // ok -} - -object Test13 { - def foo()(implicit x: String => Int) = ??? - implicit val f: String => Int = _.size - foo() // ok -} - -object Test14 { - case class MySeq[A](underlying: Seq[A]) - - implicit def mySeq2seq[A](mySeq: MySeq[A]): Seq[A] = mySeq.underlying - val s: Seq[Int] = MySeq(Seq(1, 2, 3)) // ok -} - -object Test15 { - implicit def implicitSeq[A]: Seq[A] = ??? - def foo(implicit ev: Seq[Int]): Unit = ??? - foo -} diff --git a/tests/neg/i9408b.check b/tests/neg/i9408b.check index 5f8a854a9282..4d86f5a0ef0b 100644 --- a/tests/neg/i9408b.check +++ b/tests/neg/i9408b.check @@ -1,5 +1,6 @@ --- Error: tests/neg/i9408b/Test_2.scala:8:20 --------------------------------------------------------------------------- -8 | val length: Int = "abc" // error +-- Migration Warning: tests/neg/i9408b/Test_2.scala:8:20 --------------------------------------------------------------- +8 | val length: Int = "abc" // warn | ^^^^^ |The conversion (test.conversions.Conv.implicitLength : String => Int) will not be applied implicitly here in Scala 3 because only implicit methods and instances of Conversion class will continue to work as implicit views. +No warnings can be incurred under -Werror. diff --git a/tests/neg/i9408b/Test_2.scala b/tests/neg/i9408b/Test_2.scala index 6b3cbbafcb0e..11cad10f1e9f 100644 --- a/tests/neg/i9408b/Test_2.scala +++ b/tests/neg/i9408b/Test_2.scala @@ -5,5 +5,7 @@ import scala.language.implicitConversions object Test { import test.conversions.Conv.* - val length: Int = "abc" // error + val length: Int = "abc" // warn } + +// nopos-error: No warnings can be incurred under -Werror. \ No newline at end of file diff --git a/tests/neg/i9740.check b/tests/neg/i9740.check deleted file mode 100644 index 359603a2863a..000000000000 --- a/tests/neg/i9740.check +++ /dev/null @@ -1,12 +0,0 @@ --- [E186] Type Error: tests/neg/i9740.scala:10:9 ----------------------------------------------------------------------- -10 | case RecoveryCompleted => println("Recovery completed") // error - | ^^^^^^^^^^^^^^^^^ - | Implausible pattern: - | RecoveryCompleted could match selector of type object TypedRecoveryCompleted - | only if there is an `equals` method identifying elements of the two types. --- [E186] Type Error: tests/neg/i9740.scala:15:9 ----------------------------------------------------------------------- -15 | case RecoveryCompleted => // error - | ^^^^^^^^^^^^^^^^^ - | Implausible pattern: - | RecoveryCompleted could match selector of type TypedRecoveryCompleted - | only if there is an `equals` method identifying elements of the two types. diff --git a/tests/neg/i9740.scala b/tests/neg/i9740.scala deleted file mode 100644 index 6222298df48b..000000000000 --- a/tests/neg/i9740.scala +++ /dev/null @@ -1,17 +0,0 @@ -//> using options -Xfatal-warnings -Wimplausible-patterns -abstract class RecoveryCompleted -object RecoveryCompleted extends RecoveryCompleted - -abstract class TypedRecoveryCompleted -object TypedRecoveryCompleted extends TypedRecoveryCompleted - -class Test { - TypedRecoveryCompleted match { - case RecoveryCompleted => println("Recovery completed") // error - case TypedRecoveryCompleted => println("Typed recovery completed") - } - - def foo(x: TypedRecoveryCompleted) = x match - case RecoveryCompleted => // error - case TypedRecoveryCompleted => -} diff --git a/tests/neg/i9740b.scala b/tests/neg/i9740b.scala deleted file mode 100644 index dcd9a1d6a474..000000000000 --- a/tests/neg/i9740b.scala +++ /dev/null @@ -1,20 +0,0 @@ -//> using options -Xfatal-warnings -Wimplausible-patterns -enum Recovery: - case RecoveryCompleted - -enum TypedRecovery: - case TypedRecoveryCompleted - -import Recovery.* -import TypedRecovery.* - -class Test { - TypedRecoveryCompleted match { - case RecoveryCompleted => println("Recovery completed") // error - case TypedRecoveryCompleted => println("Typed recovery completed") - } - - def foo(x: TypedRecovery) = x match - case RecoveryCompleted => // error - case TypedRecoveryCompleted => -} diff --git a/tests/neg/i9740c.scala b/tests/neg/i9740c.scala deleted file mode 100644 index c6a3a1380f1d..000000000000 --- a/tests/neg/i9740c.scala +++ /dev/null @@ -1,17 +0,0 @@ -//> using options -Xfatal-warnings -Wimplausible-patterns -sealed trait Exp[T] -case class IntExp(x: Int) extends Exp[Int] -case class StrExp(x: String) extends Exp[String] -object UnitExp extends Exp[Unit] - -trait Txn[T <: Txn[T]] -case class Obj(o: AnyRef) extends Txn[Obj] with Exp[AnyRef] - - -class Foo { - def bar[A <: Txn[A]](x: Exp[A]): Unit = x match - case IntExp(x) => - case StrExp(x) => - case UnitExp => // error - case Obj(o) => -} diff --git a/tests/neg/i9740d.scala b/tests/neg/i9740d.scala deleted file mode 100644 index 6f3cc3be02e2..000000000000 --- a/tests/neg/i9740d.scala +++ /dev/null @@ -1,13 +0,0 @@ -//> using options -Xfatal-warnings -Wimplausible-patterns - -sealed trait Exp[T] -case class IntExp(x: Int) extends Exp[Int] -case class StrExp(x: String) extends Exp[String] -object UnitExp extends Exp[Unit] - -class Foo[U <: Int, T <: U] { - def bar[A <: T](x: Exp[A]): Unit = x match - case IntExp(x) => - case StrExp(x) => - case UnitExp => // error -} diff --git a/tests/neg/i9751.scala b/tests/neg/i9751.scala deleted file mode 100644 index 618d237e0cd4..000000000000 --- a/tests/neg/i9751.scala +++ /dev/null @@ -1,11 +0,0 @@ -//> using options -Xfatal-warnings - -def f(): Unit = { - () // error - () -} - -inline def g(): Unit = { - () // error - () -} diff --git a/tests/neg/i9776.scala b/tests/neg/i9776.scala deleted file mode 100644 index b05488810416..000000000000 --- a/tests/neg/i9776.scala +++ /dev/null @@ -1,61 +0,0 @@ -//> using options -Xfatal-warnings - -import scala.annotation.switch - -sealed trait Fruit - -object Fruit { - case object Apple extends Fruit - case object Banana extends Fruit - case object Lemon extends Fruit - case object Lime extends Fruit - case object Orange extends Fruit - - def isCitrus(fruit: Fruit): Boolean = - (fruit: @switch) match { // error Could not emit switch for @switch annotated match - case Orange => true - case Lemon => true - case Lime => true - case _ => false - } -} - - -sealed trait TaggedFruit { - def tag: Int -} - -object TaggedFruit { - case object Apple extends TaggedFruit { - val tag = 1 - } - case object Banana extends TaggedFruit { - val tag = 2 - } - case object Orange extends TaggedFruit { - val tag = 3 - } - - def isCitrus(fruit: TaggedFruit): Boolean = - (fruit.tag: @switch) match { // error Could not emit switch for @switch annotated match - case Apple.tag => true - case 2 => true - case 3 => true - case _ => false - } - - // fewer than four cases, so no warning - def succ1(fruit: TaggedFruit): Boolean = - (fruit.tag: @switch) match { - case 3 => false - case 2 | Apple.tag => true - } - - // fewer than four cases, so no warning - def succ2(fruit: TaggedFruit): Boolean = - (fruit.tag: @switch) match { - case 3 => false - case 2 => true - case Apple.tag => true - } -} diff --git a/tests/neg/i9880.scala b/tests/neg/i9880.scala deleted file mode 100644 index f99fae25e5dc..000000000000 --- a/tests/neg/i9880.scala +++ /dev/null @@ -1,32 +0,0 @@ -//> using options -Xfatal-warnings - -opaque type Bytes = Array[Byte] -object Bytes: - extension (self: Bytes) - def size: Int = (self: Array[Byte]).size // error - -// - -object Module1: - opaque type State[S, +A] = S => (S, A) - object State: - extension [S, A](self: State[S, A]) - def map[B](f: A => B): State[S, B] = - s => { val (s2, a) = self(s); (s2, f(a)) } -object Module2: - import Module1.State - trait RNG - opaque type Gen[+A] = State[RNG, A] - object Gen: - extension [A](self: Gen[A]) - def map[B](f: A => B): Gen[B] = - self.map(f) // error - -// - -class Sym(val owner: Sym) - -extension (sym: Sym) - def isSomething: Boolean = false - def isFoo: Boolean = sym.isSomething && sym.owner.isFoo // was: Infinite loop in function body - def isBar: Boolean = sym.isSomething || sym.owner.isBar // was: Infinite loop in function body diff --git a/tests/neg/impl-conv/A.scala b/tests/neg/impl-conv/A.scala index 31eccf4fa4f7..9c47e67ca789 100644 --- a/tests/neg/impl-conv/A.scala +++ b/tests/neg/impl-conv/A.scala @@ -2,7 +2,7 @@ package implConv object A { - implicit def s2i(x: String): Int = Integer.parseInt(x) // error: feature + implicit def s2i(x: String): Int = Integer.parseInt(x) // warn: feature given i2s: Conversion[Int, String] = _.toString // ok implicit class Foo(x: String) { diff --git a/tests/neg/impl-conv/B.scala b/tests/neg/impl-conv/B.scala index 618868b8bbc0..b475c460f318 100644 --- a/tests/neg/impl-conv/B.scala +++ b/tests/neg/impl-conv/B.scala @@ -8,5 +8,6 @@ object B { "".foo val x: Int = "" // ok - val y: String = 1 // error: feature + val y: String = 1 // warn: feature } +// nopos-error: No warnings can be incurred under -Werror. \ No newline at end of file diff --git a/tests/neg/implicit-conversions-old.scala b/tests/neg/implicit-conversions-old.scala deleted file mode 100644 index 0a7b75766bbf..000000000000 --- a/tests/neg/implicit-conversions-old.scala +++ /dev/null @@ -1,25 +0,0 @@ -//> using options -Xfatal-warnings -feature - -class A -class B - -object A { - - implicit def a2b(x: A): B = ??? // error under -Xfatal-warnings -feature - - implicit def b2a(x: B): A = ??? // error under -Xfatal-warnings -feature -} - -class C - -object D { - implicit def a2c(x: A): C = ??? // error under -Xfatal-warnings -feature -} - -object Test { - import D.* - - val x1: A = new B - val x2: B = new A // ok, since it's an old-style comversion - val x3: C = new A // ok, since it's an old-style comversion -} \ No newline at end of file diff --git a/tests/neg/implicit-conversions.scala b/tests/neg/implicit-conversions.scala deleted file mode 100644 index ead8c5ac7646..000000000000 --- a/tests/neg/implicit-conversions.scala +++ /dev/null @@ -1,31 +0,0 @@ -//> using options -Xfatal-warnings -feature - -class A -class B - -object A { - - given Conversion[A, B] with { - def apply(x: A): B = ??? - } - - given Conversion[B, A] with { - def apply(x: B): A = ??? - } -} - -class C - -object D { - given Conversion[A, C] with { - def apply(x: A): C = ??? - } -} - -object Test { - import D.given - - val x1: A = new B // error under -Xfatal-warnings -feature - val x2: B = new A // error under -Xfatal-warnings -feature - val x3: C = new A // error under -Xfatal-warnings -feature -} \ No newline at end of file diff --git a/tests/neg/indentLeft.scala b/tests/neg/indentLeft.scala index c4a260583de2..7e1cf8041bc7 100644 --- a/tests/neg/indentLeft.scala +++ b/tests/neg/indentLeft.scala @@ -1,10 +1,11 @@ //> using options -Xfatal-warnings +// nopos-error: No warnings can be incurred under -Werror. object Test { if (true) { println("hi") - println("!") // error: too far to the left + println("!") // warn: too far to the left } // error: too far to the left \ No newline at end of file diff --git a/tests/neg/indentRight.scala b/tests/neg/indentRight.scala index 8eb9deb23389..6c43651d67e6 100644 --- a/tests/neg/indentRight.scala +++ b/tests/neg/indentRight.scala @@ -1,19 +1,19 @@ //> using options -no-indent -Xfatal-warnings trait A - case class B() extends A // error: Line is indented too far to the right - case object C extends A // error: Line is indented too far to the right + case class B() extends A // warn: Line is indented too far to the right + case object C extends A // warn: Line is indented too far to the right object Test { if (true) println("ho") - println("hu") // error: Line is indented too far to the right + println("hu") // warn: Line is indented too far to the right if (true) { println("ho") } - println("hu") // error: Line is indented too far to the right + println("hu") // warn: Line is indented too far to the right while (true) () @@ -24,8 +24,8 @@ object Test { } trait A - case class B() extends A // error: Line is indented too far to the right - case object C extends A // error: Line is indented too far to the right + case class B() extends A // warn: Line is indented too far to the right + case object C extends A // warn: Line is indented too far to the right if (true) // OK println("hi") @@ -33,4 +33,4 @@ object Test { println("!") // error: expected a toplevel definition } - +// nopos-error: No warnings can be incurred under -Werror. \ No newline at end of file diff --git a/tests/neg/infix.check b/tests/neg/infix.check new file mode 100644 index 000000000000..7c7c87005291 --- /dev/null +++ b/tests/neg/infix.check @@ -0,0 +1,30 @@ +-- Error: tests/neg/infix.scala:26:4 ----------------------------------------------------------------------------------- +26 | c mop 2 // error: should not be used as infix operator + | ^^^ + | Alphanumeric method mop is not declared infix; it should not be used as infix operator. + | Instead, use method syntax .mop(...) or backticked identifier `mop`. + | The latter can be rewritten automatically under -rewrite -source future-migration. +-- Error: tests/neg/infix.scala:27:4 ----------------------------------------------------------------------------------- +27 | c meth 2 // error: should not be used as infix operator + | ^^^^ + | Alphanumeric method meth is not declared infix; it should not be used as infix operator. + | Instead, use method syntax .meth(...) or backticked identifier `meth`. + | The latter can be rewritten automatically under -rewrite -source future-migration. +-- Error: tests/neg/infix.scala:45:14 ---------------------------------------------------------------------------------- +45 | val x1: Int Map String = ??? // error + | ^^^ + | Alphanumeric type Map is not declared infix; it should not be used as infix operator. + | Instead, use prefix syntax Map[...] or backticked identifier `Map`. + | The latter can be rewritten automatically under -rewrite -source future-migration. +-- Error: tests/neg/infix.scala:47:14 ---------------------------------------------------------------------------------- +47 | val x3: Int AndC String = ??? // error + | ^^^^ + | Alphanumeric type AndC is not declared infix; it should not be used as infix operator. + | Instead, use prefix syntax AndC[...] or backticked identifier `AndC`. + | The latter can be rewritten automatically under -rewrite -source future-migration. +-- Error: tests/neg/infix.scala:61:8 ----------------------------------------------------------------------------------- +61 | val _ Pair _ = p // error + | ^^^^ + | Alphanumeric extractor Pair is not declared infix; it should not be used as infix operator. + | Instead, use prefix syntax Pair(...) or backticked identifier `Pair`. + | The latter can be rewritten automatically under -rewrite -source future-migration. diff --git a/tests/neg/infix.scala b/tests/neg/infix.scala index aefdd5c40d47..dda638c829f9 100644 --- a/tests/neg/infix.scala +++ b/tests/neg/infix.scala @@ -1,4 +1,4 @@ -//> using options -source future -deprecation -Xfatal-warnings +//> using options -source future -deprecation // Compile with -strict -Xfatal-warnings -deprecation class C: @@ -67,4 +67,4 @@ def test() = { val _ Q _ = q // OK -} +} \ No newline at end of file diff --git a/tests/neg/inline-givens.scala b/tests/neg/inline-givens.scala deleted file mode 100644 index 3e388de2ce8b..000000000000 --- a/tests/neg/inline-givens.scala +++ /dev/null @@ -1,16 +0,0 @@ -//> using options -Xfatal-warnings - -class Item(x: String) - -inline given a: Conversion[String, Item] = - Item(_) // error - -inline given b: Conversion[String, Item] = - (x => Item(x)) // error - -inline given c: Conversion[String, Item] = - { x => Item(x) } // error - -inline given d: Conversion[String, Item] with - def apply(x: String) = Item(x) // ok - diff --git a/tests/neg/main-functions-nameclash.scala b/tests/neg/main-functions-nameclash.scala deleted file mode 100644 index 1f9352e1592d..000000000000 --- a/tests/neg/main-functions-nameclash.scala +++ /dev/null @@ -1,5 +0,0 @@ -//> using options -Xfatal-warnings - -object foo { - @main def foo(x: Int) = () // error: class foo and object foo produce classes that overwrite one another -} diff --git a/tests/neg/manifest-summoning-b.scala b/tests/neg/manifest-summoning-b.scala deleted file mode 100644 index 6d1b8baff007..000000000000 --- a/tests/neg/manifest-summoning-b.scala +++ /dev/null @@ -1,4 +0,0 @@ -//> using options -Xfatal-warnings -deprecation - -val foo = manifest[List[? <: Int]] // error -val bar = optManifest[Array[? <: String]] // error diff --git a/tests/neg/matchable.scala b/tests/neg/matchable.scala deleted file mode 100644 index aaf8234f6d1e..000000000000 --- a/tests/neg/matchable.scala +++ /dev/null @@ -1,29 +0,0 @@ -//> using options -Xfatal-warnings -source future - -def foo[T](x: T): Matchable = - println(x.getClass()) // ok - println(x.isInstanceOf[Int]) // ok - x match - case x: Int => // error: should not be scrutinized - println("int") - x - case x: String => // error: should not be scrutinized - println("string") - x - List(x) match - case (x: Int) :: Nil => // error: should not be scrutinized - println("int") - x - case List(x: String) => // error: should not be scrutinized - println("string") - x - case List(y :: Nil) => // error: should not be scrutinized - y :: Nil - case _ => - x // error: should not be scrutinized - -@main def Test = - val x: Matchable = foo(1) - val y: Matchable = foo("hello") - assert(x != y) - diff --git a/tests/neg/missing-targetName.scala b/tests/neg/missing-targetName.scala index b5403ac7cb19..8c799c4a19dd 100644 --- a/tests/neg/missing-targetName.scala +++ b/tests/neg/missing-targetName.scala @@ -5,7 +5,8 @@ import scala.annotation.targetName class & { // error @targetName("op") def *(x: Int): Int = ??? // OK - def / (x: Int): Int // error - val frozen_& : Int = ??? // error - object some_??? // error + def / (x: Int): Int // warn + val frozen_& : Int = ??? // warn + object some_??? // warn } +// nopos-error: No warnings can be incurred under -Werror. \ No newline at end of file diff --git a/tests/neg/old-syntax.scala b/tests/neg/old-syntax.scala deleted file mode 100644 index 124781d13db2..000000000000 --- a/tests/neg/old-syntax.scala +++ /dev/null @@ -1,5 +0,0 @@ -//> using options -Xfatal-warnings -deprecation - -val f = (x: Int) ⇒ x + 1 // error - -val list = for (n ← List(42)) yield n + 1 // error diff --git a/tests/neg/ovlazy.scala b/tests/neg/ovlazy.scala deleted file mode 100644 index 69078fbd2745..000000000000 --- a/tests/neg/ovlazy.scala +++ /dev/null @@ -1,8 +0,0 @@ -//> using options -source 3.0-migration -Xfatal-warnings - -class A { - val x: Int = 1 -} -class B extends A { - override lazy val x: Int = 2 // error -} diff --git a/tests/neg/private-this-3.4.scala b/tests/neg/private-this-3.4.scala deleted file mode 100644 index b198e954e41b..000000000000 --- a/tests/neg/private-this-3.4.scala +++ /dev/null @@ -1,7 +0,0 @@ -//> using options -Werror - -import scala.language.`3.4` - -class Foo: - private[this] def foo: Int = ??? // error: migration warning - protected[this] def bar: Int = ??? // error: migration warning diff --git a/tests/neg/private-this-future-migration.scala b/tests/neg/private-this-future-migration.scala deleted file mode 100644 index 7e3da2be72e2..000000000000 --- a/tests/neg/private-this-future-migration.scala +++ /dev/null @@ -1,7 +0,0 @@ -//> using options -Werror - -import scala.language.`future-migration` - -class Foo: - private[this] def foo: Int = ??? // error: migration warning - protected[this] def bar: Int = ??? // error: migration warning diff --git a/tests/neg/pureStatement.scala b/tests/neg/pureStatement.scala index 4d2ea1d49b08..72d39ce2ecf6 100644 --- a/tests/neg/pureStatement.scala +++ b/tests/neg/pureStatement.scala @@ -3,16 +3,16 @@ class IOCapability object Test { - "" // error: pure expression does nothing in statement position + "" // warn: pure expression does nothing in statement position locally { - "" // error: pure expression does nothing in statement position + "" // warn: pure expression does nothing in statement position println("") - 42 // error: pure expression does nothing in statement position + 42 // warn: pure expression does nothing in statement position - ((x: Int) => println("hi")) // error: pure expression does nothing in statement position + ((x: Int) => println("hi")) // warn: pure expression does nothing in statement position () } @@ -24,7 +24,7 @@ object Test { implicit val cap: IOCapability = new IOCapability - 2 // error: pure expression does nothing in statement position + 2 // warn: pure expression does nothing in statement position doSideEffects(1) // error: pure expression does nothing in statement position @@ -32,3 +32,4 @@ object Test { broken.foo // no extra error, and no pure expression warning broken.foo() // same } +// nopos-error: No warnings can be incurred under -Werror. \ No newline at end of file diff --git a/tests/neg/quote-simple-hole.scala b/tests/neg/quote-simple-hole.scala deleted file mode 100644 index 64e2bcad4862..000000000000 --- a/tests/neg/quote-simple-hole.scala +++ /dev/null @@ -1,17 +0,0 @@ -//> using options -Xfatal-warnings - -import scala.quoted.Quotes - -def test(using Quotes) = { - val x = '{0} - val y = '{ // error: Canceled splice directly inside a quote. '{ ${ XYZ } } is equivalent to XYZ. - $x - } - val z = '{ - val a = ${ // error: Canceled quote directly inside a splice. ${ '{ XYZ } } is equivalent to XYZ. - '{ - $y - } - } - } -} diff --git a/tests/neg/refinements-this.scala b/tests/neg/refinements-this.scala deleted file mode 100644 index f8d41bd85360..000000000000 --- a/tests/neg/refinements-this.scala +++ /dev/null @@ -1,5 +0,0 @@ -//> using options -Xfatal-warnings - -class Outer: - type X = { type O = Outer.this.type } // ok - type Y = { type O = this.type } // error diff --git a/tests/neg/refutable-pattern-binding-messages.check b/tests/neg/refutable-pattern-binding-messages.check index 5a9d85fd4447..4a8f895264a3 100644 --- a/tests/neg/refutable-pattern-binding-messages.check +++ b/tests/neg/refutable-pattern-binding-messages.check @@ -22,24 +22,24 @@ | If the narrowing is intentional, this can be communicated by adding the `case` keyword before the full pattern, | which will result in a filtering for expression (using `withFilter`). | This patch can be rewritten automatically under -rewrite -source 3.2-migration. --- Error: tests/neg/refutable-pattern-binding-messages.scala:5:14 ------------------------------------------------------ -5 | val Positive(p) = 5 // error: refutable extractor +-- Warning: tests/neg/refutable-pattern-binding-messages.scala:5:14 ---------------------------------------------------- +5 | val Positive(p) = 5 // warn: refutable extractor | ^^^^^^^^^^^^^^^ | pattern binding uses refutable extractor `Test.Positive` | | If this usage is intentional, this can be communicated by adding `: @unchecked` after the expression, | which may result in a MatchError at runtime. | This patch can be rewritten automatically under -rewrite -source 3.2-migration. --- Error: tests/neg/refutable-pattern-binding-messages.scala:10:20 ----------------------------------------------------- -10 | val i :: is = List(1, 2, 3) // error: pattern type more specialized +-- Warning: tests/neg/refutable-pattern-binding-messages.scala:10:20 --------------------------------------------------- +10 | val i :: is = List(1, 2, 3) // warn: pattern type more specialized | ^^^^^^^^^^^^^ | pattern's type ::[Int] is more specialized than the right hand side expression's type List[Int] | | If the narrowing is intentional, this can be communicated by adding `: @unchecked` after the expression, | which may result in a MatchError at runtime. | This patch can be rewritten automatically under -rewrite -source 3.2-migration. --- Error: tests/neg/refutable-pattern-binding-messages.scala:16:10 ----------------------------------------------------- -16 | val 1 = 2 // error: pattern type does not match +-- Warning: tests/neg/refutable-pattern-binding-messages.scala:16:10 --------------------------------------------------- +16 | val 1 = 2 // warn: pattern type does not match | ^ | pattern's type (1 : Int) does not match the right hand side expression's type (2 : Int) | diff --git a/tests/neg/refutable-pattern-binding-messages.scala b/tests/neg/refutable-pattern-binding-messages.scala index c6ae043652c2..e71371785d15 100644 --- a/tests/neg/refutable-pattern-binding-messages.scala +++ b/tests/neg/refutable-pattern-binding-messages.scala @@ -1,17 +1,17 @@ -//> using options -Werror + object Test { // refutable extractor object Positive { def unapply(i: Int): Option[Int] = Some(i).filter(_ > 0) } - val Positive(p) = 5 // error: refutable extractor + val Positive(p) = 5 // warn: refutable extractor for Positive(i) <- List(1, 2, 3) do () // error: refutable extractor // more specialized val xs: List[AnyRef] = ??? - val i :: is = List(1, 2, 3) // error: pattern type more specialized + val i :: is = List(1, 2, 3) // warn: pattern type more specialized for ((x: String) <- xs) do () // error: pattern type more specialized // does not match val ys: List[Option[?]] = ??? for none @ None <- ys do () // error: pattern type does not match - val 1 = 2 // error: pattern type does not match + val 1 = 2 // warn: pattern type does not match } diff --git a/tests/neg/rewrite-messages.scala b/tests/neg/rewrite-messages.scala deleted file mode 100644 index 7509682c4baa..000000000000 --- a/tests/neg/rewrite-messages.scala +++ /dev/null @@ -1,8 +0,0 @@ -//> using options -source:future-migration -deprecation -Werror - -import scala.util._ // error - -object Test { - extension (x: Int) def foo(y: Int) = x + y - 2 foo 4 // error -} diff --git a/tests/neg/strict-pattern-bindings-3.2.scala b/tests/neg/strict-pattern-bindings-3.2.scala deleted file mode 100644 index d7db6cd165e4..000000000000 --- a/tests/neg/strict-pattern-bindings-3.2.scala +++ /dev/null @@ -1,37 +0,0 @@ -//> using options -Xfatal-warnings -// These tests should fail under -Xfatal-warnings with source version source version 3.2 or later -import language.`3.2` - -object Test: - // from filtering-fors.scala - val xs: List[AnyRef] = ??? - - for ((x: String) <- xs) do () // error - for (y@ (x: String) <- xs) do () // error - for ((x, y) <- xs) do () // error - - for ((x: String) <- xs if x.isEmpty) do () // error - for ((x: String) <- xs; y = x) do () // error - for ((x: String) <- xs; (y, z) <- xs) do () // error // error - for (case (x: String) <- xs; (y, z) <- xs) do () // error - for ((x: String) <- xs; case (y, z) <- xs) do () // error - - val pairs: List[AnyRef] = List((1, 2), "hello", (3, 4)) - for ((x, y) <- pairs) yield (y, x) // error - - // from unchecked-patterns.scala - val y :: ys = List(1, 2, 3) // error - val (1, c) = (1, 2) // error - val 1 *: cs = 1 *: Tuple() // error - - val (_: Int | _: AnyRef) = ??? : AnyRef // error - - val 1 = 2 // error - - object Positive { def unapply(i: Int): Option[Int] = Some(i).filter(_ > 0) } - object Always1 { def unapply(i: Int): Some[Int] = Some(i) } - object Pair { def unapply(t: (Int, Int)): t.type = t } - object Triple { def unapply(t: (Int, Int, Int)): (Int, Int, Int) = t } - - val Positive(p) = 5 // error - val Some(s1) = Option(1) // error diff --git a/tests/neg/structural-2.scala b/tests/neg/structural-2.scala index 3613d6073e34..85fac55c08a5 100644 --- a/tests/neg/structural-2.scala +++ b/tests/neg/structural-2.scala @@ -69,7 +69,8 @@ object Test { package p6 { class Refinements { - val y: { val x: T; type T } // error: deprecated warning: illegal forward reference in refinement; now illegal + val y: { val x: T; type T } // warn: deprecated warning: illegal forward reference in refinement; now illegal } } +// nopos-error: No warnings can be incurred under -Werror. diff --git a/tests/neg/symbolic-packages.scala b/tests/neg/symbolic-packages.scala deleted file mode 100644 index 12719d027b4c..000000000000 --- a/tests/neg/symbolic-packages.scala +++ /dev/null @@ -1,13 +0,0 @@ -//> using options -Xfatal-warnings - -package `with spaces` { // error - class Foo -} - -package +.* { // error // error - class Bar -} - -package object `mixed_*` { // error - class Baz -} diff --git a/tests/neg/unchecked-patterns.scala b/tests/neg/unchecked-patterns.scala index db304a2f1875..7e6c4de76a50 100644 --- a/tests/neg/unchecked-patterns.scala +++ b/tests/neg/unchecked-patterns.scala @@ -5,23 +5,24 @@ object Test { val (y1: Some[Int]) = Some(1): Option[Int] @unchecked // OK val y2: Some[Int] @unchecked = Some(1): Option[Int] // error - val x :: xs = List(1, 2, 3) // error - val (1, c) = (1, 2) // error - val 1 *: cs = 1 *: Tuple() // error + val x :: xs = List(1, 2, 3) // warn + val (1, c) = (1, 2) // warn + val 1 *: cs = 1 *: Tuple() // warn - val (_: Int | _: AnyRef) = ??? : AnyRef // error + val (_: Int | _: AnyRef) = ??? : AnyRef // warn - val 1 = 2 // error + val 1 = 2 // warn object Positive { def unapply(i: Int): Option[Int] = Some(i).filter(_ > 0) } object Always1 { def unapply(i: Int): Some[Int] = Some(i) } object Pair { def unapply(t: (Int, Int)): t.type = t } object Triple { def unapply(t: (Int, Int, Int)): (Int, Int, Int) = t } - val Positive(p) = 5 // error - val Some(s1) = Option(1) // error + val Positive(p) = 5 // warn + val Some(s1) = Option(1) // warn val Some(s2) = Some(1) // OK val Always1(p1) = 5 // OK val Pair(t1, t2) = (5, 5) // OK val Triple(u1, u2, u3) = (5, 5, 5) // OK -} \ No newline at end of file +} +// nopos-error: No warnings can be incurred under -Werror. \ No newline at end of file diff --git a/tests/neg/warn-value-discard.check b/tests/neg/warn-value-discard.check deleted file mode 100644 index ba43c743709f..000000000000 --- a/tests/neg/warn-value-discard.check +++ /dev/null @@ -1,20 +0,0 @@ --- [E175] Potential Issue Error: tests/neg/warn-value-discard.scala:27:36 ---------------------------------------------- -27 | mutable.Set.empty[String].remove("") // error - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | discarded non-Unit value of type Boolean --- [E175] Potential Issue Error: tests/neg/warn-value-discard.scala:39:41 ---------------------------------------------- -39 | mutable.Set.empty[String].subtractOne("") // error - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | discarded non-Unit value of type scala.collection.mutable.Set[String] --- [E175] Potential Issue Error: tests/neg/warn-value-discard.scala:59:4 ----------------------------------------------- -59 | mutable.Set.empty[String] += "" // error - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | discarded non-Unit value of type scala.collection.mutable.Set[String] --- [E175] Potential Issue Error: tests/neg/warn-value-discard.scala:15:35 ---------------------------------------------- -15 | firstThing().map(_ => secondThing()) // error - | ^^^^^^^^^^^^^ - | discarded non-Unit value of type Either[Failed, Unit] --- [E175] Potential Issue Error: tests/neg/warn-value-discard.scala:18:35 ---------------------------------------------- -18 | firstThing().map(_ => secondThing()) // error - | ^^^^^^^^^^^^^ - | discarded non-Unit value of type Either[Failed, Unit] diff --git a/tests/neg/with-type-operator-future-migration.scala b/tests/neg/with-type-operator-future-migration.scala deleted file mode 100644 index 3ed2e3a8f067..000000000000 --- a/tests/neg/with-type-operator-future-migration.scala +++ /dev/null @@ -1,5 +0,0 @@ -//> using options -Werror - -import scala.language.`future-migration` - -def foo: Int with String = ??? // error diff --git a/tests/warn/14034b.scala b/tests/warn/14034b.scala new file mode 100644 index 000000000000..fdef353f7aca --- /dev/null +++ b/tests/warn/14034b.scala @@ -0,0 +1,15 @@ +//> using options -deprecation + +@deprecated trait Exp +@deprecated val exp = 1 + +def test1 = exp // warn +def test2(a: Exp) = () // warn + +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 // warn +type Quuz[A <: Exp] = Int // warn \ No newline at end of file diff --git a/tests/neg/15981.check b/tests/warn/15981.check similarity index 68% rename from tests/neg/15981.check rename to tests/warn/15981.check index 10745839c566..6cc57d86385f 100644 --- a/tests/neg/15981.check +++ b/tests/warn/15981.check @@ -1,5 +1,5 @@ --- [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/warn/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 | diff --git a/tests/neg/15981.scala b/tests/warn/15981.scala similarity index 76% rename from tests/neg/15981.scala rename to tests/warn/15981.scala index 5aba3555c010..a52da28c8462 100644 --- a/tests/neg/15981.scala +++ b/tests/warn/15981.scala @@ -1,6 +1,6 @@ -//> 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 } } diff --git a/tests/neg/17284.check b/tests/warn/17284.check similarity index 86% rename from tests/neg/17284.check rename to tests/warn/17284.check index fa248c598311..47df2d21e3a7 100644 --- a/tests/neg/17284.check +++ b/tests/warn/17284.check @@ -1,5 +1,5 @@ --- [E187] Potential Issue Error: tests/neg/17284.scala:4:6 ------------------------------------------------------------- -4 | 451.synchronized {} // error +-- [E187] Potential Issue Warning: tests/warn/17284.scala:4:6 ---------------------------------------------------------- +4 | 451.synchronized {} // warn | ^^^^^^^^^^^^^^^^ | Suspicious synchronized call on boxed class |--------------------------------------------------------------------------------------------------------------------- @@ -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/warn/17284.scala:8:4 ---------------------------------------------------------- +8 | x.synchronized {} // warn | ^^^^^^^^^^^^^^ | Suspicious synchronized call on boxed class |--------------------------------------------------------------------------------------------------------------------- @@ -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/warn/17284.scala:11:7 --------------------------------------------------------- +11 | true.synchronized {} // warn | ^^^^^^^^^^^^^^^^^ | Suspicious synchronized call on boxed class |-------------------------------------------------------------------------------------------------------------------- diff --git a/tests/warn/17284.scala b/tests/warn/17284.scala new file mode 100644 index 000000000000..c30e8cb478ec --- /dev/null +++ b/tests/warn/17284.scala @@ -0,0 +1,14 @@ +//> using options -explain + +def test = + 451.synchronized {} // warn + +def test2 = + val x: Integer = 451 + x.synchronized {} // warn + +def test3 = + true.synchronized {} // warn + +def test4 = + true.hashCode() // success \ No newline at end of file diff --git a/tests/warn/1828.scala b/tests/warn/1828.scala new file mode 100644 index 000000000000..2231967a53e0 --- /dev/null +++ b/tests/warn/1828.scala @@ -0,0 +1,11 @@ + + +class Test { + def remove[S](a: S | Int, f: Int => S):S = a match { + case a: S => a // warn + case a: Int => f(a) + } + + val t: Int | String = 5 + val t1 = remove[String](t, _.toString) +} diff --git a/tests/warn/18493.check b/tests/warn/18493.check new file mode 100644 index 000000000000..64f2e2aac735 --- /dev/null +++ b/tests/warn/18493.check @@ -0,0 +1,8 @@ +-- [E030] Match case Unreachable Warning: tests/warn/18493.scala:6:9 --------------------------------------------------- +6 | case "abc" => // warn + | ^^^^^ + | Unreachable case +-- [E030] Match case Unreachable Warning: tests/warn/18493.scala:12:9 -------------------------------------------------- +12 | case "abc" => // warn + | ^^^^^ + | Unreachable case diff --git a/tests/neg/18493.scala b/tests/warn/18493.scala similarity index 68% rename from tests/neg/18493.scala rename to tests/warn/18493.scala index 8dfb3bf923cc..d3ca292a346e 100644 --- a/tests/neg/18493.scala +++ b/tests/warn/18493.scala @@ -1,14 +1,14 @@ -//> using options -Werror + 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 } } \ No newline at end of file diff --git a/tests/warn/3324b.scala b/tests/warn/3324b.scala new file mode 100644 index 000000000000..9a2011d18012 --- /dev/null +++ b/tests/warn/3324b.scala @@ -0,0 +1,11 @@ + + +class C[T] { + val x: Any = ??? + if (x.isInstanceOf[List[String]]) // warn: unchecked + if (x.isInstanceOf[T]) // warn: unchecked + x match { + case x: List[String] => // warn: unchecked + case x: T => // warn: unchecked + } +} \ No newline at end of file diff --git a/tests/warn/3324f.scala b/tests/warn/3324f.scala new file mode 100644 index 000000000000..86af918b0d5a --- /dev/null +++ b/tests/warn/3324f.scala @@ -0,0 +1,11 @@ + + +trait C[T] +class D[T] + +class Test { + def foo[T](x: C[T]) = x match { + case _: D[T] => // warn + case _: C[Int] => // warn + } +} \ No newline at end of file diff --git a/tests/warn/3324g.scala b/tests/warn/3324g.scala new file mode 100644 index 000000000000..23ff4b3d23f9 --- /dev/null +++ b/tests/warn/3324g.scala @@ -0,0 +1,21 @@ + + +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] => // 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] => // warn!! + } + + quux(new C[Int]) +} \ No newline at end of file diff --git a/tests/neg/IsInstanceOfClassTag2.scala b/tests/warn/IsInstanceOfClassTag2.scala similarity index 80% rename from tests/neg/IsInstanceOfClassTag2.scala rename to tests/warn/IsInstanceOfClassTag2.scala index 9d32ee401092..5ca8a8c91765 100644 --- a/tests/neg/IsInstanceOfClassTag2.scala +++ b/tests/warn/IsInstanceOfClassTag2.scala @@ -1,4 +1,4 @@ -//> using options -Xfatal-warnings + import scala.reflect.TypeTest @@ -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) => } @@ -22,3 +22,4 @@ object IsInstanceOfClassTag { } } } + diff --git a/tests/warn/JavaSeqLiteral.scala b/tests/warn/JavaSeqLiteral.scala new file mode 100644 index 000000000000..9652a9fa502c --- /dev/null +++ b/tests/warn/JavaSeqLiteral.scala @@ -0,0 +1,31 @@ + + +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]] // warn + + 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) +} diff --git a/tests/warn/avoid-warn-deprecation.scala b/tests/warn/avoid-warn-deprecation.scala new file mode 100644 index 000000000000..364added5e8a --- /dev/null +++ b/tests/warn/avoid-warn-deprecation.scala @@ -0,0 +1,11 @@ +//> using options -feature + +object A { + @deprecated("use bar instead of this one", "0.2.3") + def foo: Int = 3 +} + +object B { + A.foo +} +// nopos-warn there was 1 deprecation warning; re-run with -deprecation for details \ No newline at end of file diff --git a/tests/warn/conditionalWarnings.scala b/tests/warn/conditionalWarnings.scala new file mode 100644 index 000000000000..5ab63c263abf --- /dev/null +++ b/tests/warn/conditionalWarnings.scala @@ -0,0 +1,15 @@ +//> using options -deprecation + +object Test { + @deprecated def foo = ??? + + given Conversion[String, Int] = _.length + + 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-warn +} \ No newline at end of file diff --git a/tests/neg/convertible.scala b/tests/warn/convertible.scala similarity index 60% rename from tests/neg/convertible.scala rename to tests/warn/convertible.scala index e72de452f41d..c98006ecdc9b 100644 --- a/tests/neg/convertible.scala +++ b/tests/warn/convertible.scala @@ -1,4 +1,4 @@ -//> using options -Xfatal-warnings -feature +//> using options -feature import language.experimental.into @@ -11,9 +11,9 @@ object Test: def f(x: Text, y: => Text, zs: Text*) = println(s"${x.str} ${y.str} ${zs.map(_.str).mkString(" ")}") - f("abc", "def") // error // error - f("abc", "def", "xyz", "uvw") // error // error // error // error - f("abc", "def", "xyz", Text("uvw")) // error // error // error + f("abc", "def") // warn // warn + f("abc", "def", "xyz", "uvw") // warn // warn // warn // warn + f("abc", "def", "xyz", Text("uvw")) // warn // warn // warn def g(x: into Text) = println(x.str) @@ -27,5 +27,4 @@ object Test: def h(x: into Text) = val y = h1(x) - y("abc") // error, inference through type variable does not propagate - + y("abc") // warn, inference through type variable does not propagate \ No newline at end of file diff --git a/tests/neg/deprecated-override.scala b/tests/warn/deprecated-override.scala similarity index 52% rename from tests/neg/deprecated-override.scala rename to tests/warn/deprecated-override.scala index b532416c7126..2d0b0ceb4aea 100644 --- a/tests/neg/deprecated-override.scala +++ b/tests/warn/deprecated-override.scala @@ -1,4 +1,4 @@ -//> using options -source future -deprecation -Xfatal-warnings +//> using options -source future -deprecation trait A: def f: Int @@ -7,10 +7,9 @@ class B extends A: @deprecatedOverriding def f = 1 class C extends B: - override def f = 2 // error + override def f = 2 // warn trait D extends A: override def f = 3 -object E extends B, D // error - +object E extends B, D // warn \ No newline at end of file diff --git a/tests/neg/feature-shadowing.scala b/tests/warn/feature-shadowing.scala similarity index 77% rename from tests/neg/feature-shadowing.scala rename to tests/warn/feature-shadowing.scala index 16286d5eea87..301f24b241f7 100644 --- a/tests/neg/feature-shadowing.scala +++ b/tests/warn/feature-shadowing.scala @@ -1,4 +1,4 @@ -//> using options -Xfatal-warnings -feature +//> using options -feature import language.implicitConversions given Conversion[Int, String] = _.toString @@ -8,7 +8,7 @@ object a: object b: import language.implicitConversions as _ - val s: String = 2 // error + val s: String = 2 // warn object c: import language.implicitConversions diff --git a/tests/neg/gadt-contradictory-pattern.scala b/tests/warn/gadt-contradictory-pattern.scala similarity index 54% rename from tests/neg/gadt-contradictory-pattern.scala rename to tests/warn/gadt-contradictory-pattern.scala index 6fbd06120a48..5d85b23653db 100644 --- a/tests/neg/gadt-contradictory-pattern.scala +++ b/tests/warn/gadt-contradictory-pattern.scala @@ -1,14 +1,14 @@ -//> using options -Xfatal-warnings -Wimplausible-patterns +//> using options -Wimplausible-patterns object Test { sealed abstract class Foo[T] case object Bar1 extends Foo[Int] case object Bar2 extends Foo[String] case object Bar3 extends Foo[AnyRef] - def fail4[T <: AnyRef](xx: (Foo[T], Foo[T])) = xx match { - case (Bar1, Bar1) => () // error // error + def fail4[T <: AnyRef](xx: (Foo[T], Foo[T])) = xx match { // warn match may not be exhaustive + case (Bar1, Bar1) => () // warn // warn case (Bar2, Bar3) => () case (Bar3, _) => () } -} +} \ No newline at end of file diff --git a/tests/warn/gadt.scala b/tests/warn/gadt.scala new file mode 100644 index 000000000000..9d7b81220284 --- /dev/null +++ b/tests/warn/gadt.scala @@ -0,0 +1,15 @@ + + +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] => // warn + } + + quux(new B[D]) +} diff --git a/tests/warn/html.scala b/tests/warn/html.scala new file mode 100644 index 000000000000..98189c1bf2cb --- /dev/null +++ b/tests/warn/html.scala @@ -0,0 +1,20 @@ + + +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] => // warn + case e: AppliedAttr => + sb.append(" ").append(e) + } + sb + } diff --git a/tests/warn/main-functions-nameclash.scala b/tests/warn/main-functions-nameclash.scala new file mode 100644 index 000000000000..bc0fe64379d4 --- /dev/null +++ b/tests/warn/main-functions-nameclash.scala @@ -0,0 +1,5 @@ + + +object foo { + @main def foo(x: Int) = () // warn: class foo and object foo produce classes that overwrite one another +} diff --git a/tests/neg/manifest-summoning-b.check b/tests/warn/manifest-summoning-b.check similarity index 73% rename from tests/neg/manifest-summoning-b.check rename to tests/warn/manifest-summoning-b.check index bb63eebb555f..590b27ddbd98 100644 --- a/tests/neg/manifest-summoning-b.check +++ b/tests/warn/manifest-summoning-b.check @@ -1,12 +1,12 @@ --- Error: tests/neg/manifest-summoning-b.scala:3:34 -------------------------------------------------------------------- -3 |val foo = manifest[List[? <: Int]] // error +-- Deprecation Warning: tests/warn/manifest-summoning-b.scala:3:34 ----------------------------------------------------- +3 |val foo = manifest[List[? <: Int]] // warn | ^ | Compiler synthesis of Manifest and OptManifest is deprecated, instead | replace with the type `scala.reflect.ClassTag[List[? <: Int]]`. | Alternatively, consider using the new metaprogramming features of Scala 3, | see https://docs.scala-lang.org/scala3/reference/metaprogramming.html --- Error: tests/neg/manifest-summoning-b.scala:4:41 -------------------------------------------------------------------- -4 |val bar = optManifest[Array[? <: String]] // error +-- Deprecation Warning: tests/warn/manifest-summoning-b.scala:4:41 ----------------------------------------------------- +4 |val bar = optManifest[Array[? <: String]] // warn | ^ | Compiler synthesis of Manifest and OptManifest is deprecated, instead | replace with the type `scala.reflect.ClassTag[Array[? <: String]]`. diff --git a/tests/warn/manifest-summoning-b.scala b/tests/warn/manifest-summoning-b.scala new file mode 100644 index 000000000000..18ddec1250b5 --- /dev/null +++ b/tests/warn/manifest-summoning-b.scala @@ -0,0 +1,4 @@ +//> using options -deprecation + +val foo = manifest[List[? <: Int]] // warn +val bar = optManifest[Array[? <: String]] // warn \ No newline at end of file diff --git a/tests/warn/matchable.scala b/tests/warn/matchable.scala new file mode 100644 index 000000000000..8adcdcf1c90a --- /dev/null +++ b/tests/warn/matchable.scala @@ -0,0 +1,28 @@ +//> using options -source future + +def foo[T](x: T): Matchable = + println(x.getClass()) // ok + println(x.isInstanceOf[Int]) // ok + x match + case x: Int => // warn: should not be scrutinized + println("int") + x + case x: String => // warn: should not be scrutinized + println("string") + x + List(x) match + case (x: Int) :: Nil => // warn: should not be scrutinized + println("int") + x + case List(x: String) => // warn: should not be scrutinized + println("string") + x + case List(y :: Nil) => // warn: should not be scrutinized + y :: Nil + case _ => + x // warn: should not be scrutinized + +@main def Test = + val x: Matchable = foo(1) + val y: Matchable = foo("hello") + assert(x != y) \ No newline at end of file diff --git a/tests/neg/newline-braces.scala b/tests/warn/newline-braces.scala similarity index 55% rename from tests/neg/newline-braces.scala rename to tests/warn/newline-braces.scala index afe7731f3095..9ec2961ee30d 100644 --- a/tests/neg/newline-braces.scala +++ b/tests/warn/newline-braces.scala @@ -1,8 +1,9 @@ -//> using options -source 3.0-migration -Xfatal-warnings +//> using options -source 3.0-migration def f: List[Int] = { List(1, 2, 3).map // no newline inserted here in Scala-2 compat mode - { x => // error (migration) + { x => // warn (migration) x + 1 } } + diff --git a/tests/neg/nonunit-statement.scala b/tests/warn/nonunit-statement.scala similarity index 80% rename from tests/neg/nonunit-statement.scala rename to tests/warn/nonunit-statement.scala index 94346031077c..f90deb647d6e 100644 --- a/tests/neg/nonunit-statement.scala +++ b/tests/warn/nonunit-statement.scala @@ -1,4 +1,5 @@ -//> using options -Xfatal-warnings -Wnonunit-statement -Wvalue-discard -source:3.3 +//> using options -Wnonunit-statement -Wvalue-discard -source:3.3 + import collection.ArrayOps import collection.mutable.{ArrayBuilder, LinkedHashSet, ListBuffer} import concurrent._ @@ -9,38 +10,38 @@ class C { def c = { def improved = Future(42) def stale = Future(27) - improved // error + improved // warn stale } } class D { def d = { class E - new E().toString // error + new E().toString // warn new E().toString * 2 } } class F { import ExecutionContext.Implicits._ - Future(42) // error + Future(42) // warn } // unused template expression uses synthetic method of class case class K(s: String) { - copy() // error + copy() // warn } // mutations returning this are ok class Mutate { val b = ListBuffer.empty[Int] b += 42 // nowarn, returns this.type val xs = List(42) - 27 +: xs // error + 27 +: xs // warn def f(x: Int): this.type = this def g(): Unit = f(42) // nowarn } // some uninteresting expressions may warn for other reasons class WhoCares { - null // error for purity + null // warn for purity ??? // nowarn for impurity } // explicit Unit ascription to opt out of warning, even for funky applies @@ -50,15 +51,15 @@ class Absolution { // Future(42): Unit // nowarn { F(42)(ctx) }: Unit where annot is on F(42) // f(42): Unit // nowarn } -// warn uni-branched unless user disables it with -Wnonunit-if:false + class Boxed[A](a: A) { def isEmpty = false def foreach[U](f: A => U): Unit = - if (!isEmpty) f(a) // error (if) + if (!isEmpty) f(a) // warn (if) def forall(f: A => Boolean): Unit = if (!isEmpty) { println(".") - f(a) // error (if) + f(a) // warn (if) } def take(p: A => Boolean): Option[A] = { while (isEmpty || !p(a)) () @@ -69,20 +70,20 @@ class Unibranch[A, B] { def runWith[U](action: B => U): A => Boolean = { x => val z = null.asInstanceOf[B] val fellback = false - if (!fellback) action(z) // error (if) + if (!fellback) action(z) // warn (if) !fellback } def f(i: Int): Int = { def g = 17 if (i < 42) { - g // error block statement + g // warn block statement println("uh oh") - g // error (if) + g // warn (if) } while (i < 42) { - g // error + g // warn println("uh oh") - g // error + g // warn } 42 } @@ -92,7 +93,7 @@ class Dibranch { def j: Int = ??? def f(b: Boolean): Int = { // if-expr might have an uninteresting LUB - if (b) { // error, at least one branch looks interesting + if (b) { // warn, at least one branch looks interesting println("true") i } @@ -112,7 +113,7 @@ class Next[A] { class Setting[A] { def set = LinkedHashSet.empty[A] def f(a: A): Unit = { - set += a // error because cannot know whether the `set` was supposed to be consumed or assigned + set += a // warn because cannot know whether the `set` was supposed to be consumed or assigned println(set) } } @@ -122,27 +123,27 @@ class Strung { def iterator = Iterator.empty[String] def addString(b: StringBuilder, start: String, sep: String, end: String): StringBuilder = { val jsb = b.underlying - if (start.length != 0) jsb.append(start) // error (value-discard) + if (start.length != 0) jsb.append(start) // warn (value-discard) val it = iterator if (it.hasNext) { jsb.append(it.next()) while (it.hasNext) { jsb.append(sep) // nowarn (java) - jsb.append(it.next()) // error (value-discard) + jsb.append(it.next()) // warn (value-discard) } } - if (end.length != 0) jsb.append(end) // error (value-discard) + if (end.length != 0) jsb.append(end) // warn (value-discard) b } def f(b: java.lang.StringBuilder, it: Iterator[String]): String = { while (it.hasNext) { b.append("\n") // nowarn (java) - b.append(it.next()) // error (value-discard) + b.append(it.next()) // warn (value-discard) } b.toString } def g(b: java.lang.StringBuilder, it: Iterator[String]): String = { - while (it.hasNext) it.next() // error + while (it.hasNext) it.next() // warn b.toString } } @@ -195,4 +196,4 @@ class Depends { f(d) () } -} +} \ No newline at end of file diff --git a/tests/warn/old-syntax.scala b/tests/warn/old-syntax.scala new file mode 100644 index 000000000000..d584e3692a0a --- /dev/null +++ b/tests/warn/old-syntax.scala @@ -0,0 +1,5 @@ +//> using options -deprecation + +val f = (x: Int) ⇒ x + 1 // warn + +val list = for (n ← List(42)) yield n + 1 // warn \ No newline at end of file diff --git a/tests/neg/opaque-match.scala b/tests/warn/opaque-match.scala similarity index 63% rename from tests/neg/opaque-match.scala rename to tests/warn/opaque-match.scala index 59d0836fb2a3..453d525bac2c 100644 --- a/tests/neg/opaque-match.scala +++ b/tests/warn/opaque-match.scala @@ -1,4 +1,4 @@ -//> using options -Xfatal-warnings + case class C() @@ -12,17 +12,13 @@ def Test[T] = O.x match case _: C => ??? // ok C() match - case _: O.T => ??? // error + case _: O.T => ??? // warn C() match - case _: T => ??? // error + case _: T => ??? // warn (??? : Any) match - case _: List[O.T] => ??? // error + case _: List[O.T] => ??? // warn (??? : Any) match case _: List[O.T @unchecked] => ??? // OK (??? : Any) match - case _: List[T] => ??? // error - - - - + case _: List[T] => ??? // warn \ No newline at end of file diff --git a/tests/warn/or-type-trees.scala b/tests/warn/or-type-trees.scala new file mode 100644 index 000000000000..0e8569576796 --- /dev/null +++ b/tests/warn/or-type-trees.scala @@ -0,0 +1,40 @@ + + +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) => // warn + 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]]) // 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]) => // warn + 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/warn/ovlazy.scala b/tests/warn/ovlazy.scala new file mode 100644 index 000000000000..1dfa284a00c9 --- /dev/null +++ b/tests/warn/ovlazy.scala @@ -0,0 +1,9 @@ +//> using options -source 3.0-migration + +class A { + val x: Int = 1 +} +class B extends A { + override lazy val x: Int = 2 // warn +} + diff --git a/tests/neg/private-this-3.4.check b/tests/warn/private-this-3.4.check similarity index 74% rename from tests/neg/private-this-3.4.check rename to tests/warn/private-this-3.4.check index 29c2fe909ede..29cdcfac6477 100644 --- a/tests/neg/private-this-3.4.check +++ b/tests/warn/private-this-3.4.check @@ -1,11 +1,11 @@ --- Error: tests/neg/private-this-3.4.scala:6:16 ------------------------------------------------------------------------ -6 | private[this] def foo: Int = ??? // error: migration warning +-- Warning: tests/warn/private-this-3.4.scala:4:16 --------------------------------------------------------------------- +4 | private[this] def foo: Int = ??? // warn: migration warning | ^ | The [this] qualifier will be deprecated in the future; it should be dropped. | See: https://docs.scala-lang.org/scala3/reference/dropped-features/this-qualifier.html | This construct can be rewritten automatically under -rewrite -source 3.4-migration. --- Error: tests/neg/private-this-3.4.scala:7:18 ------------------------------------------------------------------------ -7 | protected[this] def bar: Int = ??? // error: migration warning +-- Warning: tests/warn/private-this-3.4.scala:5:18 --------------------------------------------------------------------- +5 | protected[this] def bar: Int = ??? // warn: migration warning | ^ | The [this] qualifier will be deprecated in the future; it should be dropped. | See: https://docs.scala-lang.org/scala3/reference/dropped-features/this-qualifier.html diff --git a/tests/warn/private-this-3.4.scala b/tests/warn/private-this-3.4.scala new file mode 100644 index 000000000000..1270eba116bc --- /dev/null +++ b/tests/warn/private-this-3.4.scala @@ -0,0 +1,5 @@ +import scala.language.`3.4` + +class Foo: + private[this] def foo: Int = ??? // warn: migration warning + protected[this] def bar: Int = ??? // warn: migration warning diff --git a/tests/warn/private-this-future-migration.scala b/tests/warn/private-this-future-migration.scala new file mode 100644 index 000000000000..d719187e534a --- /dev/null +++ b/tests/warn/private-this-future-migration.scala @@ -0,0 +1,5 @@ +import scala.language.`future-migration` + +class Foo: + private[this] def foo: Int = ??? // warn: migration warning + protected[this] def bar: Int = ??? // warn: migration warning diff --git a/tests/warn/quote-simple-hole.scala b/tests/warn/quote-simple-hole.scala new file mode 100644 index 000000000000..f23d2c0535c4 --- /dev/null +++ b/tests/warn/quote-simple-hole.scala @@ -0,0 +1,17 @@ + + +import scala.quoted.Quotes + +def test(using Quotes) = { + val x = '{0} + val y = '{ // warn: Canceled splice directly inside a quote. '{ ${ XYZ } } is equivalent to XYZ. + $x + } + val z = '{ + val a = ${ // warn: Canceled quote directly inside a splice. ${ '{ XYZ } } is equivalent to XYZ. + '{ + $y + } + } + } +} \ No newline at end of file diff --git a/tests/warn/refined-types.scala b/tests/warn/refined-types.scala new file mode 100644 index 000000000000..1ef0f84c00d4 --- /dev/null +++ b/tests/warn/refined-types.scala @@ -0,0 +1,24 @@ + + +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] // 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 \ No newline at end of file diff --git a/tests/warn/refinements-this.scala b/tests/warn/refinements-this.scala new file mode 100644 index 000000000000..3e4c64cf1e59 --- /dev/null +++ b/tests/warn/refinements-this.scala @@ -0,0 +1,6 @@ + + +class Outer: + type X = { type O = Outer.this.type } // ok + type Y = { type O = this.type } // warn + diff --git a/tests/neg/rewrite-messages.check b/tests/warn/rewrite-messages.check similarity index 76% rename from tests/neg/rewrite-messages.check rename to tests/warn/rewrite-messages.check index b062ab2bc732..d7147239cded 100644 --- a/tests/neg/rewrite-messages.check +++ b/tests/warn/rewrite-messages.check @@ -1,10 +1,10 @@ --- Error: tests/neg/rewrite-messages.scala:3:18 ------------------------------------------------------------------------ -3 |import scala.util._ // error +-- Migration Warning: tests/warn/rewrite-messages.scala:3:18 ----------------------------------------------------------- +3 |import scala.util._ // warn | ^ | `_` is no longer supported for a wildcard import; use `*` instead | This construct can be rewritten automatically under -rewrite -source future-migration. --- Error: tests/neg/rewrite-messages.scala:7:4 ------------------------------------------------------------------------- -7 | 2 foo 4 // error +-- Migration Warning: tests/warn/rewrite-messages.scala:7:4 ------------------------------------------------------------ +7 | 2 foo 4 // warn | ^^^ | Alphanumeric method foo is not declared infix; it should not be used as infix operator. | Instead, use method syntax .foo(...) or backticked identifier `foo`. diff --git a/tests/warn/rewrite-messages.scala b/tests/warn/rewrite-messages.scala new file mode 100644 index 000000000000..88166f8e8ac2 --- /dev/null +++ b/tests/warn/rewrite-messages.scala @@ -0,0 +1,8 @@ +//> using options -source:future-migration -deprecation + +import scala.util._ // warn + +object Test { + extension (x: Int) def foo(y: Int) = x + y + 2 foo 4 // warn +} \ No newline at end of file diff --git a/tests/neg/i15503-scala2/scala2-t11681.scala b/tests/warn/scala2-t11681.scala similarity index 90% rename from tests/neg/i15503-scala2/scala2-t11681.scala rename to tests/warn/scala2-t11681.scala index 2436668e0c9c..ae2187181ceb 100644 --- a/tests/neg/i15503-scala2/scala2-t11681.scala +++ b/tests/warn/scala2-t11681.scala @@ -1,5 +1,5 @@ -//> using options -Xfatal-warnings -Wunused:params -// +//> using options -Wunused:params + import Answers._ @@ -10,7 +10,7 @@ trait InterFace { trait BadAPI extends InterFace { private def f(a: Int, - b: String, // error + b: String, // warn c: Double): Int = { println(c) a @@ -47,10 +47,9 @@ trait BadAPI extends InterFace { // mustn't alter warnings in super trait PoorClient extends BadAPI { override def meth(x: Int) = ??? // OK - override def f(a: Int, b: String, c: Double): Int = a + b.toInt + c.toInt } -class Unusing(u: Int) { // error +class Unusing(u: Int) { // warn def f = ??? } @@ -107,4 +106,4 @@ object Answers { def answer: Int = 42 } -val a$1 = 2 \ No newline at end of file +val a$1 = 2 diff --git a/tests/warn/strict-pattern-bindings-3.2.scala b/tests/warn/strict-pattern-bindings-3.2.scala new file mode 100644 index 000000000000..e4df8e770a01 --- /dev/null +++ b/tests/warn/strict-pattern-bindings-3.2.scala @@ -0,0 +1,37 @@ + +// These tests should fail under -Xfatal-warnings with source version source version 3.2 or later +import language.`3.2` + +object Test: + // from filtering-fors.scala + val xs: List[AnyRef] = ??? + + for ((x: String) <- xs) do () // warn + for (y@ (x: String) <- xs) do () // warn + for ((x, y) <- xs) do () // warn + + for ((x: String) <- xs if x.isEmpty) do () // warn + for ((x: String) <- xs; y = x) do () // warn + for ((x: String) <- xs; (y, z) <- xs) do () // warn // warn + for (case (x: String) <- xs; (y, z) <- xs) do () // warn + for ((x: String) <- xs; case (y, z) <- xs) do () // warn + + val pairs: List[AnyRef] = List((1, 2), "hello", (3, 4)) + for ((x, y) <- pairs) yield (y, x) // warn + + // from unchecked-patterns.scala + val y :: ys = List(1, 2, 3) // warn + val (1, c) = (1, 2) // warn + val 1 *: cs = 1 *: Tuple() // warn + + val (_: Int | _: AnyRef) = ??? : AnyRef // warn + + val 1 = 2 // warn + + object Positive { def unapply(i: Int): Option[Int] = Some(i).filter(_ > 0) } + object Always1 { def unapply(i: Int): Some[Int] = Some(i) } + object Pair { def unapply(t: (Int, Int)): t.type = t } + object Triple { def unapply(t: (Int, Int, Int)): (Int, Int, Int) = t } + + val Positive(p) = 5 // warn + val Some(s1) = Option(1) // warn \ No newline at end of file diff --git a/tests/neg/supertraits-b.scala b/tests/warn/supertraits-b.scala similarity index 69% rename from tests/neg/supertraits-b.scala rename to tests/warn/supertraits-b.scala index 78854537974e..b36fcb5634b7 100644 --- a/tests/neg/supertraits-b.scala +++ b/tests/warn/supertraits-b.scala @@ -1,4 +1,4 @@ -//> using options -Xfatal-warnings + transparent sealed trait TA transparent sealed trait TB @@ -16,20 +16,20 @@ object Test: choose0(a, b) match case _: TA => ??? - case _: TB => ??? // error: unreachable + case _: TB => ??? // warn: unreachable choose1(a, b) match case _: TA => ??? - case _: TB => ??? // error: unreachable + case _: TB => ??? // warn: unreachable choose2(a, b) match case _: TB => ??? - case _: TA => ??? // error: unreachable + case _: TA => ??? // warn: unreachable choose3(a, b) match case _: Product => ??? - case _: TA => ??? // error: unreachable + case _: TA => ??? // warn: unreachable choose4(a, b) match case _: (TA & TB) => ??? - case _: Product => ??? // error: unreachable \ No newline at end of file + case _: Product => ??? // warn: unreachable \ No newline at end of file diff --git a/tests/neg/switches.scala b/tests/warn/switches.scala similarity index 77% rename from tests/neg/switches.scala rename to tests/warn/switches.scala index d405f8185706..9b45e3ed0d51 100644 --- a/tests/neg/switches.scala +++ b/tests/warn/switches.scala @@ -1,4 +1,4 @@ -//> using options -Xfatal-warnings + import scala.annotation.switch @@ -38,7 +38,7 @@ object Main { // multiple annotations are processed correctly // thinks a val in an object is constant... so naive - def fail1(c: Char) = (c: @switch @unchecked) match { // error: Could not emit switch for @switch annotated match + def fail1(c: Char) = (c: @switch @unchecked) match { // warn: Could not emit switch for @switch annotated match case 'A' => true case 'B' => true case Other.C1 => true @@ -46,7 +46,7 @@ object Main { } // more naivete - def fail2(c: Char) = (c: @unchecked @switch) match { // error: Could not emit switch for @switch annotated match + def fail2(c: Char) = (c: @unchecked @switch) match { // warn: Could not emit switch for @switch annotated match case 'A' => true case 'B' => true case Other.C3 => true @@ -69,12 +69,12 @@ object Main { case _ => -1 } - def fail3(x: Any) = (x: @switch) match { // error: Could not emit switch for @switch annotated match + def fail3(x: Any) = (x: @switch) match { // warn: Could not emit switch for @switch annotated match case 1 | 2 | 3 => true case _ => false } - def fail4(x: AnyVal) = (x: @switch) match { // error: Could not emit switch for @switch annotated match + def fail4(x: AnyVal) = (x: @switch) match { // warn: Could not emit switch for @switch annotated match case 1 | 2 | 3 => true case _ => false } @@ -82,7 +82,7 @@ object Main { case class IntAnyVal(x: Int) extends AnyVal val Ten = IntAnyVal(10) - def fail5(x: IntAnyVal) = (x: @switch) match { // error: Could not emit switch for @switch annotated match + def fail5(x: IntAnyVal) = (x: @switch) match { // warn: Could not emit switch for @switch annotated match case IntAnyVal(1) => 0 case Ten => 1 case IntAnyVal(100) => 2 @@ -92,11 +92,11 @@ object Main { // the generated lookupswitch covers only a subset of the cases final val One = IntAnyVal(1) - def fail6(x: IntAnyVal) = (x: @switch) match { // error: Could not emit switch for @switch annotated match + def fail6(x: IntAnyVal) = (x: @switch) match { // warn: Could not emit switch for @switch annotated match case One => 0 case IntAnyVal(10) => 1 case IntAnyVal(100) => 2 case IntAnyVal(1000) => 3 case IntAnyVal(10000) => 4 } -} +} \ No newline at end of file diff --git a/tests/neg/symbolic-packages.check b/tests/warn/symbolic-packages.check similarity index 65% rename from tests/neg/symbolic-packages.check rename to tests/warn/symbolic-packages.check index 8e9b7e114829..c1d56f67eba7 100644 --- a/tests/neg/symbolic-packages.check +++ b/tests/warn/symbolic-packages.check @@ -1,16 +1,16 @@ --- Error: tests/neg/symbolic-packages.scala:3:8 ------------------------------------------------------------------------ -3 |package `with spaces` { // error +-- Warning: tests/warn/symbolic-packages.scala:3:8 --------------------------------------------------------------------- +3 |package `with spaces` { // warn | ^^^^^^^^^^^^^ | The package name `with spaces` will be encoded on the classpath, and can lead to undefined behaviour. --- Error: tests/neg/symbolic-packages.scala:7:10 ----------------------------------------------------------------------- -7 |package +.* { // error // error +-- Warning: tests/warn/symbolic-packages.scala:7:10 -------------------------------------------------------------------- +7 |package +.* { // warn // warn | ^ | The package name `*` will be encoded on the classpath, and can lead to undefined behaviour. --- Error: tests/neg/symbolic-packages.scala:7:8 ------------------------------------------------------------------------ -7 |package +.* { // error // error +-- Warning: tests/warn/symbolic-packages.scala:7:8 --------------------------------------------------------------------- +7 |package +.* { // warn // warn | ^ | The package name `+` will be encoded on the classpath, and can lead to undefined behaviour. --- Error: tests/neg/symbolic-packages.scala:11:16 ---------------------------------------------------------------------- -11 |package object `mixed_*` { // error +-- Warning: tests/warn/symbolic-packages.scala:11:16 ------------------------------------------------------------------- +11 |package object `mixed_*` { // warn | ^^^^^^^ | The package name `mixed_*` will be encoded on the classpath, and can lead to undefined behaviour. diff --git a/tests/warn/symbolic-packages.scala b/tests/warn/symbolic-packages.scala new file mode 100644 index 000000000000..6e0ef04da6bb --- /dev/null +++ b/tests/warn/symbolic-packages.scala @@ -0,0 +1,13 @@ + + +package `with spaces` { // warn + class Foo +} + +package +.* { // warn // warn + class Bar +} + +package object `mixed_*` { // warn + class Baz +} \ No newline at end of file diff --git a/tests/warn/t2755.scala b/tests/warn/t2755.scala new file mode 100644 index 000000000000..1aeb06d237d1 --- /dev/null +++ b/tests/warn/t2755.scala @@ -0,0 +1,60 @@ + + +// 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 // warn: 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 // warn: 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)) + } +} \ No newline at end of file diff --git a/tests/neg/t3235-minimal.check b/tests/warn/t3235-minimal.check similarity index 75% rename from tests/neg/t3235-minimal.check rename to tests/warn/t3235-minimal.check index 83c287f85bc0..dcd28466f729 100644 --- a/tests/neg/t3235-minimal.check +++ b/tests/warn/t3235-minimal.check @@ -1,16 +1,16 @@ --- Error: tests/neg/t3235-minimal.scala:5:21 --------------------------------------------------------------------------- -5 | assert(123456789.round == 123456789) // error +-- Deprecation Warning: tests/warn/t3235-minimal.scala:5:21 ------------------------------------------------------------ +5 | assert(123456789.round == 123456789) // warn | ^^^^^^^^^^^^^^^ |method round in class RichInt is deprecated since 2.11.0: this is an integer type; there is no reason to round it. Perhaps you meant to call this on a floating-point value? --- Error: tests/neg/t3235-minimal.scala:6:16 --------------------------------------------------------------------------- -6 | assert(math.round(123456789) == 123456789) // error +-- Deprecation Warning: tests/warn/t3235-minimal.scala:6:16 ------------------------------------------------------------ +6 | assert(math.round(123456789) == 123456789) // warn | ^^^^^^^^^^ |method round in package scala.math is deprecated since 2.11.0: This is an integer type; there is no reason to round it. Perhaps you meant to call this with a floating-point value? --- Error: tests/neg/t3235-minimal.scala:7:32 --------------------------------------------------------------------------- -7 | assert(1234567890123456789L.round == 1234567890123456789L) // error +-- Deprecation Warning: tests/warn/t3235-minimal.scala:7:32 ------------------------------------------------------------ +7 | assert(1234567890123456789L.round == 1234567890123456789L) // warn | ^^^^^^^^^^^^^^^^^^^^^^^^^^ |method round in class RichLong is deprecated since 2.11.0: this is an integer type; there is no reason to round it. Perhaps you meant to call this on a floating-point value? --- Error: tests/neg/t3235-minimal.scala:8:16 --------------------------------------------------------------------------- -8 | assert(math.round(1234567890123456789L) == 1234567890123456789L) // error +-- Deprecation Warning: tests/warn/t3235-minimal.scala:8:16 ------------------------------------------------------------ +8 | assert(math.round(1234567890123456789L) == 1234567890123456789L) // warn | ^^^^^^^^^^ |method round in package scala.math is deprecated since 2.11.0: This is an integer type; there is no reason to round it. Perhaps you meant to call this with a floating-point value? diff --git a/tests/neg/t3235-minimal.scala b/tests/warn/t3235-minimal.scala similarity index 51% rename from tests/neg/t3235-minimal.scala rename to tests/warn/t3235-minimal.scala index f65ee13f87f5..22e6da9f31a0 100644 --- a/tests/neg/t3235-minimal.scala +++ b/tests/warn/t3235-minimal.scala @@ -1,10 +1,10 @@ -//> using options -Xfatal-warnings -deprecation +//> using options -deprecation object Test { def main(args: Array[String]): Unit = { - assert(123456789.round == 123456789) // error - assert(math.round(123456789) == 123456789) // error - assert(1234567890123456789L.round == 1234567890123456789L) // error - assert(math.round(1234567890123456789L) == 1234567890123456789L) // error + assert(123456789.round == 123456789) // warn + assert(math.round(123456789) == 123456789) // warn + assert(1234567890123456789L.round == 1234567890123456789L) // warn + assert(math.round(1234567890123456789L) == 1234567890123456789L) // warn } -} +} \ No newline at end of file diff --git a/tests/neg/t5830.scala b/tests/warn/t5830.scala similarity index 63% rename from tests/neg/t5830.scala rename to tests/warn/t5830.scala index 947b7bac4a22..41cdfb1059a7 100644 --- a/tests/neg/t5830.scala +++ b/tests/warn/t5830.scala @@ -1,11 +1,11 @@ -//> using options -Xfatal-warnings + import scala.annotation.switch class Test { def unreachable(ch: Char) = (ch: @switch) match { case 'a' => println("b") // ok - case 'a' => println("b") // error: unreachable case + case 'a' => println("b") // warn: unreachable case case 'c' => } } diff --git a/tests/warn/type-lambda.scala b/tests/warn/type-lambda.scala new file mode 100644 index 000000000000..788647496a4f --- /dev/null +++ b/tests/warn/type-lambda.scala @@ -0,0 +1,16 @@ + + +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] => // warn + case _ => + } +} diff --git a/tests/neg/type-test-paths-2.scala b/tests/warn/type-test-paths-2.scala similarity index 61% rename from tests/neg/type-test-paths-2.scala rename to tests/warn/type-test-paths-2.scala index 4bba2f87416e..79b22fa70049 100644 --- a/tests/neg/type-test-paths-2.scala +++ b/tests/warn/type-test-paths-2.scala @@ -1,4 +1,4 @@ -//> using options -Xfatal-warnings + import scala.reflect.TypeTest @@ -29,15 +29,15 @@ object Test { val r2: R = RI r1.n match { - case n: r2.Nat => // error: the type test for Test.r2.Nat cannot be checked at runtime - case n: r1.Idx => // error: the type test for Test.r1.Idx cannot be checked at runtime + case n: r2.Nat => // warn: the type test for Test.r2.Nat cannot be checked at runtime + case n: r1.Idx => // warn: the type test for Test.r1.Idx cannot be checked at runtime case n: r1.Succ => // Ok case n: r1.Nat => // Ok } r1.one match { - case n: r2.Nat => // error: the type test for Test.r2.Nat cannot be checked at runtime - case n: r1.Idx => // error: the type test for Test.r1.Idx cannot be checked at runtime + case n: r2.Nat => // warn: the type test for Test.r2.Nat cannot be checked at runtime + case n: r1.Idx => // warn: the type test for Test.r1.Idx cannot be checked at runtime case n: r1.Nat => // Ok } -} +} \ No newline at end of file diff --git a/tests/neg/type-test-paths.scala b/tests/warn/type-test-paths.scala similarity index 88% rename from tests/neg/type-test-paths.scala rename to tests/warn/type-test-paths.scala index 324ed43ba7fa..03501cfd5957 100644 --- a/tests/neg/type-test-paths.scala +++ b/tests/warn/type-test-paths.scala @@ -1,4 +1,4 @@ -//> using options -Xfatal-warnings + import scala.reflect.TypeTest @@ -8,7 +8,7 @@ object Test { val p2: T = T1 (p1.y: p1.X) match { - case x: p2.Y => // error: unchecked + case x: p2.Y => // warn: unchecked case x: p1.Y => case _ => } diff --git a/tests/neg/type-test-syntesize-b.scala b/tests/warn/type-test-syntesize-b.scala similarity index 74% rename from tests/neg/type-test-syntesize-b.scala rename to tests/warn/type-test-syntesize-b.scala index b5402eb92c66..ba8ffb8318b7 100644 --- a/tests/neg/type-test-syntesize-b.scala +++ b/tests/warn/type-test-syntesize-b.scala @@ -1,4 +1,4 @@ -//> using options -Xfatal-warnings + import scala.reflect.TypeTest @@ -19,13 +19,13 @@ object Test { test[Any, Array[Int]] test[Seq[Int], List[Int]] - test[Any, Some[Int]] // error - test[Any, a.X] // error - test[a.X, a.Y] // error + test[Any, Some[Int]] // warn + test[Any, a.X] // warn + test[a.X, a.Y] // warn } class A { type X type Y <: X -} +} \ No newline at end of file diff --git a/tests/neg/uninitialized-3.4.check b/tests/warn/uninitialized-3.4.check similarity index 75% rename from tests/neg/uninitialized-3.4.check rename to tests/warn/uninitialized-3.4.check index 1c7b985072d0..ddf4bfed85ed 100644 --- a/tests/neg/uninitialized-3.4.check +++ b/tests/warn/uninitialized-3.4.check @@ -1,5 +1,5 @@ --- Error: tests/neg/uninitialized-3.4.scala:7:15 ----------------------------------------------------------------------- -7 | var a: Int = _ // error: migration warning +-- Warning: tests/warn/uninitialized-3.4.scala:5:15 -------------------------------------------------------------------- +5 | var a: Int = _ // warn | ^ | `= _` has been deprecated; use `= uninitialized` instead. | `uninitialized` can be imported with `scala.compiletime.uninitialized`. diff --git a/tests/neg/uninitialized-3.4.scala b/tests/warn/uninitialized-3.4.scala similarity index 60% rename from tests/neg/uninitialized-3.4.scala rename to tests/warn/uninitialized-3.4.scala index 174a95ae6c54..966f2e51af1c 100644 --- a/tests/neg/uninitialized-3.4.scala +++ b/tests/warn/uninitialized-3.4.scala @@ -1,8 +1,6 @@ -//> using options -Werror - import scala.language.`3.4` import scala.compiletime.uninitialized class Foo: - var a: Int = _ // error: migration warning + var a: Int = _ // warn var b: Int = uninitialized diff --git a/tests/neg/uninitialized-future-migration.scala b/tests/warn/uninitialized-future-migration.scala similarity index 62% rename from tests/neg/uninitialized-future-migration.scala rename to tests/warn/uninitialized-future-migration.scala index 05f7c6b67f38..7c24f2466221 100644 --- a/tests/neg/uninitialized-future-migration.scala +++ b/tests/warn/uninitialized-future-migration.scala @@ -1,8 +1,6 @@ -//> using options -Werror - import scala.language.`future-migration` import scala.compiletime.uninitialized class Foo: - var a: Int = _ // error: migration warning + var a: Int = _ // warn: migration warning var b: Int = uninitialized diff --git a/tests/warn/warn-value-discard.check b/tests/warn/warn-value-discard.check new file mode 100644 index 000000000000..ca6fedb29053 --- /dev/null +++ b/tests/warn/warn-value-discard.check @@ -0,0 +1,20 @@ +-- [E175] Potential Issue Warning: tests/warn/warn-value-discard.scala:27:36 ------------------------------------------- +27 | mutable.Set.empty[String].remove("") // warn + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | discarded non-Unit value of type Boolean +-- [E175] Potential Issue Warning: tests/warn/warn-value-discard.scala:39:41 ------------------------------------------- +39 | mutable.Set.empty[String].subtractOne("") // warn + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | discarded non-Unit value of type scala.collection.mutable.Set[String] +-- [E175] Potential Issue Warning: tests/warn/warn-value-discard.scala:59:4 -------------------------------------------- +59 | mutable.Set.empty[String] += "" // warn + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | discarded non-Unit value of type scala.collection.mutable.Set[String] +-- [E175] Potential Issue Warning: tests/warn/warn-value-discard.scala:15:35 ------------------------------------------- +15 | firstThing().map(_ => secondThing()) // warn + | ^^^^^^^^^^^^^ + | discarded non-Unit value of type Either[Failed, Unit] +-- [E175] Potential Issue Warning: tests/warn/warn-value-discard.scala:18:35 ------------------------------------------- +18 | firstThing().map(_ => secondThing()) // warn + | ^^^^^^^^^^^^^ + | discarded non-Unit value of type Either[Failed, Unit] diff --git a/tests/neg/warn-value-discard.scala b/tests/warn/warn-value-discard.scala similarity index 84% rename from tests/neg/warn-value-discard.scala rename to tests/warn/warn-value-discard.scala index fb01fdeda384..8bb9aebf515b 100644 --- a/tests/neg/warn-value-discard.scala +++ b/tests/warn/warn-value-discard.scala @@ -1,4 +1,4 @@ -//> using options -Wvalue-discard -Werror +//> using options -Wvalue-discard import scala.util.{Either, Right, Left} import scala.collection.mutable @@ -12,10 +12,10 @@ def secondThing(): Either[Failed, Unit] = Left(Failed("whoops you should have flatMapped me")) def singleExpr(): Either[Failed, Unit] = - firstThing().map(_ => secondThing()) // error + firstThing().map(_ => secondThing()) // warn def block(): Either[Failed, Unit] = { - firstThing().map(_ => secondThing()) // error + firstThing().map(_ => secondThing()) // warn } class ValueDiscardTest: @@ -24,7 +24,7 @@ class ValueDiscardTest: def remove(): Unit = // Set#remove returns a Boolean, not this.type // --> Warning - mutable.Set.empty[String].remove("") // error + mutable.Set.empty[String].remove("") // warn // TODO IMHO we don't need to support this, // as it's just as easy to add a @nowarn annotation as a Unit ascription @@ -36,7 +36,7 @@ class ValueDiscardTest: // - Set#subtractOne returns this.type // - receiver is not a field or a local variable (not quite sure what you'd call it) // --> Warning - mutable.Set.empty[String].subtractOne("") // error + mutable.Set.empty[String].subtractOne("") // warn def mutateLocalVariable(): Unit = { // - Set#subtractOne returns this.type @@ -56,11 +56,11 @@ class ValueDiscardTest: // - += returns this.type // - receiver is not a field or a local variable // --> Warning - mutable.Set.empty[String] += "" // error + mutable.Set.empty[String] += "" // warn def assignmentOperatorLocalVariable(): Unit = // - += returns this.type // - receiver is a local variable // --> No warning val s: mutable.Set[String] = mutable.Set.empty[String] - s += "" + s += "" \ No newline at end of file diff --git a/tests/neg/wildcard-type-syntax-3.4.scala b/tests/warn/wildcard-type-syntax-3.4.scala similarity index 52% rename from tests/neg/wildcard-type-syntax-3.4.scala rename to tests/warn/wildcard-type-syntax-3.4.scala index 1123c9cbbe35..2dd280259ac5 100644 --- a/tests/neg/wildcard-type-syntax-3.4.scala +++ b/tests/warn/wildcard-type-syntax-3.4.scala @@ -1,8 +1,6 @@ -//> using options -Werror - import scala.language.`3.4-migration` def test = Seq() match - case _: List[_] => // error: migration warning + case _: List[_] => // warn: migration warning case _: Seq[?] => diff --git a/tests/neg/wildcard-type-syntax-future-migration.scala b/tests/warn/wildcard-type-syntax-future-migration.scala similarity index 53% rename from tests/neg/wildcard-type-syntax-future-migration.scala rename to tests/warn/wildcard-type-syntax-future-migration.scala index 6a5367385ab0..1c55827adb90 100644 --- a/tests/neg/wildcard-type-syntax-future-migration.scala +++ b/tests/warn/wildcard-type-syntax-future-migration.scala @@ -1,8 +1,6 @@ -//> using options -Werror - import scala.language.`future-migration` def test = Seq() match - case _: List[_] => // error: migration warning + case _: List[_] => // warn: migration warning case _: Seq[?] => diff --git a/tests/neg/with-type-operator-future-migration.check b/tests/warn/with-type-operator-future-migration.check similarity index 61% rename from tests/neg/with-type-operator-future-migration.check rename to tests/warn/with-type-operator-future-migration.check index e56049880431..2842592bee64 100644 --- a/tests/neg/with-type-operator-future-migration.check +++ b/tests/warn/with-type-operator-future-migration.check @@ -1,5 +1,5 @@ --- [E003] Syntax Error: tests/neg/with-type-operator-future-migration.scala:5:13 --------------------------------------- -5 |def foo: Int with String = ??? // error +-- [E003] Syntax Migration Warning: tests/warn/with-type-operator-future-migration.scala:5:13 -------------------------- +5 |def foo: Int with String = ??? // warn | ^^^^ | with as a type operator has been deprecated; use & instead | This construct can be rewritten automatically under -rewrite -source 3.4-migration. diff --git a/tests/warn/with-type-operator-future-migration.scala b/tests/warn/with-type-operator-future-migration.scala new file mode 100644 index 000000000000..42b029665565 --- /dev/null +++ b/tests/warn/with-type-operator-future-migration.scala @@ -0,0 +1,6 @@ + + +import scala.language.`future-migration` + +def foo: Int with String = ??? // warn + diff --git a/tests/neg/xfatalWarnings.scala b/tests/warn/xfatalWarnings.scala similarity index 69% rename from tests/neg/xfatalWarnings.scala rename to tests/warn/xfatalWarnings.scala index 3f49e159cbc4..7e77ac468370 100644 --- a/tests/neg/xfatalWarnings.scala +++ b/tests/warn/xfatalWarnings.scala @@ -1,9 +1,9 @@ -//> using options -Xfatal-warnings + object xfatalWarnings { val opt:Option[String] = Some("test") - opt match { // error when running with -Xfatal-warnings + opt match { // warn case None => } @@ -11,3 +11,5 @@ object xfatalWarnings { while (true) {} // should be ok. no "pure expression does nothing in statement position" issued. } } + +// When running with fatal warnings: