refactor: replace deprecated extends App with explicit main method#1131
Merged
Conversation
pjfanning
approved these changes
Jul 6, 2026
pjfanning
requested changes
Jul 6, 2026
pjfanning
left a comment
Member
There was a problem hiding this comment.
build issues
[error] -- [E039] Reference Error: /home/runner/work/pekko-http/pekko-http/http2-tests/src/test/scala/org/apache/pekko/http/scaladsl/Http2ServerTest.scala:58:96
[error] 58 | case HttpRequest(GET, Uri.Path("/image-page"), _, _, _) => imagePage
[error] | ^^^^^^^^^
[error] |forward reference to imagePage (defined on line 135) extends over the definition of syncHandler (on line 55)
[error] |
[error] | longer explanation available when compiling with `-explain`
[error] one error found
[127.671s][info][gc] GC(88) Pause Young (Normal) (G1 Evacuation Pause) 2317M->1503M(2902M) 135.420ms
[error] -- [E039] Reference Error: /home/runner/work/pekko-http/pekko-http/http-tests/src/test/scala/org/apache/pekko/http/scaladsl/server/TestServer.scala:69:21
[error] 69 | complete(index)
[error] | ^^^^^
[error] |forward reference to index (defined on line 119) extends over the definition of routes (on line 62)
[error] |
[error] | longer explanation available when compiling with `-explain`
[error] one error found
[error] (http2-tests / Test / compileIncremental) Compilation failed
[error] (http-tests / Test / compileIncremental) Compilation failed
[error] Total time: 116 s (0:01:56.0), completed 2026 Jul 6 06:41:18
He-Pin
added a commit
to He-Pin/incubator-pekko-http
that referenced
this pull request
Jul 6, 2026
Motivation: Moving lazy vals from object-level members into def main() body introduced forward reference compilation errors since local vals cannot reference later definitions in the same block. Modification: Move lazy val index/imagePage and def imagesBlock definitions before the code that references them (syncHandler/routes). Result: No more forward reference compilation errors. Tests: sbt "http2-tests / Test / compile" "http-tests / Test / compile" - success References: Fixes CI failures in PR apache#1131
Motivation:
`extends App` is deprecated in Scala 3. Replace with explicit `def main`
method for forward compatibility.
Modification:
Replace `object X extends App { ... }` with
`object X { def main(args: Array[String]): Unit = { ... } }`
in 14 test and example files.
Result:
No more usage of deprecated `scala.App` trait. Code is compatible with Scala 3.
Tests:
Not run - docs only
References:
None - Scala 3 compatibility
Motivation: Moving lazy vals from object-level members into def main() body introduced forward reference compilation errors since local vals cannot reference later definitions in the same block. Modification: Move lazy val index/imagePage and def imagesBlock definitions before the code that references them (syncHandler/routes). Result: No more forward reference compilation errors. Tests: sbt "http2-tests / Test / compile" "http-tests / Test / compile" - success References: Fixes CI failures in PR apache#1131
Motivation: PR 1131 replaces deprecated Scala extends App usage with explicit main methods, but moving Http2ClientApp logic into main turned the singleRequest helper into a local method used before its definition. Modification: Move singleRequest back to object scope as a private helper while keeping the explicit main method. Result: Http2ClientApp keeps the PR's explicit main entry point and compiles without the local forward reference error. Tests: - rtk sbt "++2.13.18!" "docs / Test / compile" - passed - rtk sbt "++3.3.8!" "docs / Test / compile" - passed - rtk sbt "++3.8.4!" "docs / Test / compile" - passed - rtk scalafmt --mode diff-ref=origin/main - passed - rtk scalafmt --list --mode diff-ref=origin/main - passed - rtk git diff --check - passed - rtk sbt "docs / Test / headerCheck" - passed References: Refs apache#1131
9df3346 to
58bf526
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
extends Appis deprecated in Scala 3. Replace with explicitdef main(args: Array[String]): Unitmethod for forward compatibility.Modification
Replace
object X extends App { ... }withobject X { def main(args: Array[String]): Unit = { ... } }in doc example and test files.Result
No more usage of deprecated
scala.Apptrait. Code is compatible with Scala 3.Tests
Not run - docs only
References
None - Scala 3 compatibility