Skip to content

refactor: replace deprecated extends App with explicit main method#1131

Merged
He-Pin merged 3 commits into
apache:mainfrom
He-Pin:remove-deprecated-extends-app
Jul 6, 2026
Merged

refactor: replace deprecated extends App with explicit main method#1131
He-Pin merged 3 commits into
apache:mainfrom
He-Pin:remove-deprecated-extends-app

Conversation

@He-Pin

@He-Pin He-Pin commented Jul 6, 2026

Copy link
Copy Markdown
Member

Motivation

extends App is deprecated in Scala 3. Replace with explicit def main(args: Array[String]): Unit method for forward compatibility.

Modification

Replace object X extends App { ... } with object X { def main(args: Array[String]): Unit = { ... } } in doc example and test 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

@pjfanning pjfanning left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@He-Pin He-Pin requested a review from pjfanning July 6, 2026 08:38
@He-Pin He-Pin marked this pull request as draft July 6, 2026 10:09
He-Pin added 3 commits July 6, 2026 23:36
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
@He-Pin He-Pin force-pushed the remove-deprecated-extends-app branch from 9df3346 to 58bf526 Compare July 6, 2026 15:45
@He-Pin He-Pin marked this pull request as ready for review July 6, 2026 15:49

@pjfanning pjfanning left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@He-Pin He-Pin merged commit 454e08d into apache:main Jul 6, 2026
6 checks passed
@He-Pin He-Pin deleted the remove-deprecated-extends-app branch July 6, 2026 16:40
@He-Pin He-Pin requested a review from pjfanning July 6, 2026 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants