From f99f887b1b17882eb43bc93cac6aeadbe68df600 Mon Sep 17 00:00:00 2001 From: Hamza Remmal Date: Thu, 23 Oct 2025 19:20:16 +0100 Subject: [PATCH] chore: officially deprecate `scala.App` in Scala 3 --- library-js/src/scala/App.scala | 1 + library/src/scala/App.scala | 10 +++++----- tests/neg/i21207.scala | 2 +- tests/patmat/i12241.scala | 2 +- tests/patmat/t2425.scala | 2 +- tests/patmat/t7466.scala | 2 +- tests/patmat/t9672.scala | 2 +- tests/patmat/virtpatmat_reach_sealed_unsealed.scala | 2 +- tests/pos/i5970.scala | 2 +- tests/pos/t2425.scala | 2 +- tests/warn/i19302.scala | 2 +- tests/warn/i21207/usage.scala | 2 +- tests/warn/i7821.scala | 2 +- tests/warn/i9166.scala | 2 +- 14 files changed, 18 insertions(+), 17 deletions(-) diff --git a/library-js/src/scala/App.scala b/library-js/src/scala/App.scala index 3b4f51267268..0c0d433fe252 100644 --- a/library-js/src/scala/App.scala +++ b/library-js/src/scala/App.scala @@ -41,6 +41,7 @@ import scala.collection.mutable.ListBuffer * @author Martin Odersky * @since 2.1 */ +@deprecated(message = "Support for trait App is deprecated in Scala 3. Please refer to https://docs.scala-lang.org/scala3/book/methods-main-methods.html.", since = "3.8.0") trait App extends DelayedInit { /** The time when the execution of this program started, in milliseconds since 1 diff --git a/library/src/scala/App.scala b/library/src/scala/App.scala index f1d098b2b942..8b7ffae4df62 100644 --- a/library/src/scala/App.scala +++ b/library/src/scala/App.scala @@ -39,19 +39,19 @@ import scala.collection.mutable.ListBuffer * before the main method has been executed.''''' * * Future versions of this trait will no longer extend `DelayedInit`. - * + * * In Scala 3, the `DelayedInit` feature was dropped. `App` exists only in a limited form * that also does not support command line arguments and will be deprecated in the future. - * + * * [[https://docs.scala-lang.org/scala3/book/methods-main-methods.html @main]] methods are the * recommended scheme to generate programs that can be invoked from the command line in Scala 3. - * + * * {{{ * @main def runMyProgram(args: String*): Unit = { * // your program here * } * }}} - * + * * If programs need to cross-build between Scala 2 and Scala 3, it is recommended to use an * explicit `main` method: * {{{ @@ -62,7 +62,7 @@ import scala.collection.mutable.ListBuffer * } * }}} */ -@nowarn("cat=deprecation") +@deprecated(message = "Support for trait App is deprecated in Scala 3. Please refer to https://docs.scala-lang.org/scala3/book/methods-main-methods.html.", since = "3.8.0") trait App extends DelayedInit { /** The time when the execution of this program started, in milliseconds since 1 diff --git a/tests/neg/i21207.scala b/tests/neg/i21207.scala index 3a257fe08139..3f14ae98ac8c 100644 --- a/tests/neg/i21207.scala +++ b/tests/neg/i21207.scala @@ -15,7 +15,7 @@ class C extends P { def g4(): Int = 4 } -object Test extends App { +object Test { val c = new C println(c.foo1) // error was omitted because of nullary fallback during ambiguous overload resolution println(c.foo2) // error, add parens diff --git a/tests/patmat/i12241.scala b/tests/patmat/i12241.scala index fe21eab4f3c3..0f1756ddd850 100644 --- a/tests/patmat/i12241.scala +++ b/tests/patmat/i12241.scala @@ -23,7 +23,7 @@ object EndpointInput { case class Empty[T]() extends EndpointInput[T] } -object Test extends App { +object Test { import EndpointInput._ def compare(left: EndpointInput[?], right: EndpointInput[?]): Boolean = diff --git a/tests/patmat/t2425.scala b/tests/patmat/t2425.scala index 8d925fb34918..82e117ca59f1 100644 --- a/tests/patmat/t2425.scala +++ b/tests/patmat/t2425.scala @@ -1,6 +1,6 @@ trait B class D extends B -object Test extends App { +object Test { def foo[T](bar: T) = { bar match { case _: Array[Array[?]] => println("array 2d") diff --git a/tests/patmat/t7466.scala b/tests/patmat/t7466.scala index a74bf4ee210f..061f145328cd 100644 --- a/tests/patmat/t7466.scala +++ b/tests/patmat/t7466.scala @@ -1,4 +1,4 @@ -object Test extends App { +object Test { val Yes1 = true val Yes2 = true val No1 = false diff --git a/tests/patmat/t9672.scala b/tests/patmat/t9672.scala index d29d270acddc..d3ad8be028a9 100644 --- a/tests/patmat/t9672.scala +++ b/tests/patmat/t9672.scala @@ -17,7 +17,7 @@ trait IntExpr { object SimpleExpr extends Hierarchy with If with Word with IntExpr //object OtherExpr extends Hierarchy with If with IntExpr -object Demo extends App { +object Demo { import SimpleExpr.* def func(expr: Expr) = expr match { case If(cond, yes, no) => cond diff --git a/tests/patmat/virtpatmat_reach_sealed_unsealed.scala b/tests/patmat/virtpatmat_reach_sealed_unsealed.scala index 13911dbd7869..042662379e62 100644 --- a/tests/patmat/virtpatmat_reach_sealed_unsealed.scala +++ b/tests/patmat/virtpatmat_reach_sealed_unsealed.scala @@ -2,7 +2,7 @@ sealed abstract class X sealed case class A(x: Int) extends X // test reachability on mixed sealed / non-sealed matches -object Test extends App { +object Test { val B: X = A(0) val C: X = A(1) diff --git a/tests/pos/i5970.scala b/tests/pos/i5970.scala index e2e79f6c3f11..668e42cbbad5 100644 --- a/tests/pos/i5970.scala +++ b/tests/pos/i5970.scala @@ -1,6 +1,6 @@ //> using options -Xfatal-warnings -deprecation -feature -object Test extends App { +object Test { case class Foo[T](t: T) def foo[T](ft: Unit|Foo[T]): T = { diff --git a/tests/pos/t2425.scala b/tests/pos/t2425.scala index 477d5467aab3..72b96873bff3 100644 --- a/tests/pos/t2425.scala +++ b/tests/pos/t2425.scala @@ -1,6 +1,6 @@ trait B class D extends B -object Test extends App { +object Test { def foo[T](bar: T) = { bar match { case _: Array[Array[_]] => println("array 2d") diff --git a/tests/warn/i19302.scala b/tests/warn/i19302.scala index 1638b44104c1..6fdbf2706ceb 100644 --- a/tests/warn/i19302.scala +++ b/tests/warn/i19302.scala @@ -3,7 +3,7 @@ @deprecated("is deprecated", "n/a") class Thing(val value: Int) -object Main extends App { +object Main { def doo(): Option[Thing] = // warn Some(new Thing(1)) // warn diff --git a/tests/warn/i21207/usage.scala b/tests/warn/i21207/usage.scala index a5b6b6904cc1..30e55e5895cf 100644 --- a/tests/warn/i21207/usage.scala +++ b/tests/warn/i21207/usage.scala @@ -9,7 +9,7 @@ class C extends P { def g(i: Int): Int = 42 + i } -object Test extends App { +object Test { val over = Over() println(over.f) // nowarn Java val c = C() diff --git a/tests/warn/i7821.scala b/tests/warn/i7821.scala index 6ac46ef730bb..882d70a940dc 100644 --- a/tests/warn/i7821.scala +++ b/tests/warn/i7821.scala @@ -20,7 +20,7 @@ object MyXObject { } } -object Main extends App { +object Main { println(XObject.anX + XObject.anX) // prints 10 println(MyXObject.anX + MyXObject.anX) // infinite loop } diff --git a/tests/warn/i9166.scala b/tests/warn/i9166.scala index 34a42987f6aa..01a30e41c5fb 100644 --- a/tests/warn/i9166.scala +++ b/tests/warn/i9166.scala @@ -1,5 +1,5 @@ //> using options -Wimplausible-patterns -object UnitTest extends App { +object UnitTest { def foo(m: Unit) = m match { case runtime.BoxedUnit.UNIT => println("ok") // warn }