Skip to content

Update dependencyanalyzer3 for Scala 3.5 #1628

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 23, 2024

Conversation

mbland
Copy link
Contributor

@mbland mbland commented Oct 21, 2024

Description

Avoids a future Scala 3.5 compatibility issue under Bzlmod. Part of #1482.

Motivation

PR #1604 added Scala 3.5 suppport. I updated my Bzlmod working branch to include those changes, and updated scala_3_5.bzl with dependencies I'd added or updated from scala_3_4.bzl. ./test_examples.sh then failed with the following error, which I recreated in the local examples/scala3 repo:

$ bazel build --repo_env=SCALA_VERSION=3.5.0 //...

ERROR: .../external/rules_scala~/third_party/dependency_analyzer/src/main/BUILD:4:39:
  scala @@rules_scala~//third_party/dependency_analyzer/src/main:dependency_analyzer
  failed: (Exit 1): scalac_bootstrap failed:
  error executing Scalac command
  (from target @@rules_scala~//third_party/dependency_analyzer/src/main:dependency_analyzer)
  bazel-out/.../bin/external/rules_scala~/src/java/io/bazel/rulesscala/scalac/scalac_bootstrap
    ... (remaining 1 argument skipped)

-- [E164] Declaration Error:
    external/rules_scala~/third_party/dependency_analyzer/src/main/io/bazel/rulesscala/dependencyanalyzer3/DependencyAnalyzer.scala:21:6
21 |  def init(options: List[String]): List[PluginPhase] =
   |      ^
   |error overriding method init in trait StandardPlugin of type (options: List[String]): List[dotty.tools.dotc.plugins.PluginPhase];
   |  method init of type (options: List[String]): List[dotty.tools.dotc.plugins.PluginPhase] needs `override` modifier

This may be because I bumped io_bazel_rules_scala_scala_library_2 from org.scala-lang:scala-library:2.13.12 to 2.13.14 in my Bzlmod branch. That's my guess based on information about the dotty packages from the following files:

  • third_party/utils/src/test/io/bazel/rulesscala/utils/Scala3CompilerUtils.scala
  • third_party/dependency_analyzer/src/test/analyzer_test_scala_3.bzl

It's interesting that Scala 3.{1,2,3,4} all passed with that scala-library version bump, but without this change, but I can't explain why.

Part of bazel-contrib#1482. Avoids a future Scala 3.5 compatibility issue under
Bzlmod.

PR bazel-contrib#1604 added Scala 3.5 suppport. I updated my Bzlmod working branch to
include those changes, and updated `scala_3_5.bzl` with dependencies
I'd added or updated from `scala_3_4.bzl`. `./test_examples.sh` then
failed with the following error, which I recreated in the local
`examples/scala3` repo:

```txt
$ bazel build --repo_env=SCALA_VERSION=3.5.0 //...

ERROR: .../external/rules_scala~/third_party/dependency_analyzer/src/main/BUILD:4:39:
  scala @@rules_scala~//third_party/dependency_analyzer/src/main:dependency_analyzer
  failed: (Exit 1): scalac_bootstrap failed:
  error executing Scalac command
  (from target @@rules_scala~//third_party/dependency_analyzer/src/main:dependency_analyzer)
  bazel-out/.../bin/external/rules_scala~/src/java/io/bazel/rulesscala/scalac/scalac_bootstrap
    ... (remaining 1 argument skipped)

-- [E164] Declaration Error:
    external/rules_scala~/third_party/dependency_analyzer/src/main/io/bazel/rulesscala/dependencyanalyzer3/DependencyAnalyzer.scala:21:6
21 |  def init(options: List[String]): List[PluginPhase] =
   |      ^
   |error overriding method init in trait StandardPlugin of type (options: List[String]): List[dotty.tools.dotc.plugins.PluginPhase];
   |  method init of type (options: List[String]): List[dotty.tools.dotc.plugins.PluginPhase] needs `override` modifier
```

This may be because I bumped `io_bazel_rules_scala_scala_library_2` from
`org.scala-lang:scala-library:2.13.12` to 2.13.14 in my Bzlmod branch.
That's my guess based on information about the `dotty` packages from the
following files:

- `third_party/utils/src/test/io/bazel/rulesscala/utils/Scala3CompilerUtils.scala`
- `third_party/dependency_analyzer/src/test/analyzer_test_scala_3.bzl`

It's interesting that Scala 3.{1,2,3,4} all passed with that
`scala-library` version bump, but without this change, but I can't
explain why.
Copy link
Collaborator

@liucijus liucijus left a comment

Choose a reason for hiding this comment

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

Thanks, @mbland!

@simuons simuons merged commit 8f69486 into bazel-contrib:master Oct 23, 2024
2 checks passed
@mbland mbland deleted the bzlmod-fix-scala3.5-example branch October 23, 2024 14:13
@WojciechMazur
Copy link
Contributor

It started to fail in Scala 3.5 because in this minor release we've added a def initialize(settings: List[String])(using Context) to replace def init(settings: List[String]). By having an additional context parameter we use reporter to correctly report warnings/errors, eg. when parsing passed settings. It was introduced in scala/scala3#20330
Because of this change def init needs to use override modifier explicitly. It's a good practice to have it also when overriding abstract methods.
Probably an additional @nowarn("deprecation") annotation should be added to the init method, because now it would report that we should use initialize instead.

@mbland
Copy link
Contributor Author

mbland commented Oct 23, 2024

@WojciechMazur Thanks for the explanation! Not having one was bugging me. Now this loop feels closed.

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.

4 participants