scala/scala3

Mixed compilation with `.java` sources causes cyclic inheritance error

Opened this issue ยท 6 comments

Compiler version

All Scala versions (both Scala 3 and Scala 2)

Minimized code

Important: Compiles correctly when build server is not used (scala --server=false), otherwise compilation of java source yields cyclic inheritance error

// ReporterDefs.scala
class ConsoleReporter extends ConsoleReporter.AbstractConsoleReporter
object ConsoleReporter{
  abstract class AbstractConsoleReporter 
}

abstract class AbstractReporter
// Reporters.java
class Reporters {
  abstract class Works extends AbstractReporter{};
  abstract class Fails1 extends ConsoleReporter{};
  abstract class Fails2 extends ConsoleReporter.AbstractConsoleReporter{};
}

Output

[error] cyclic inheritance involving ConsoleReporter
[error]   abstract class Fails1 extends ConsoleReporter{};
[error]                                 ^^^^^^^^^^^^^^^

Expectation

Should compile also when build server is used

@tgodzik any clue?
This looks like some quirk of Bloop, but it'd be weird if we didn't have it reported before ๐Ÿค”

I suppose we have to consider this a regression, since scala_legacy (the old runner) doesn't rely on the build server.

Is this reproducible with straight scala-cli?

Is this reproducible with straight scala-cli?

Yep. Tested on scala-cli 1.5.0 and 1.5.0-17-g00e4c88c1-SNAPSHOT.

Interesting... I just tested with SBT and I'm getting the same error.

sbt compile
# [info] welcome to sbt 1.10.1 (Eclipse Adoptium Java 17)
# [info] loading global plugins from /Users/pchabelski/.sbt/1.0/plugins
# [info] loading project definition from /Users/pchabelski/IdeaProjects/scala-cli-tests-2/untitled/mixed-compilation-repro/dest/project
# [info] loading settings for project dest from build.sbt ...
# [info] set current project to dest (in build file:/Users/pchabelski/IdeaProjects/scala-cli-tests-2/untitled/mixed-compilation-repro/dest/)
# [info] Executing in batch mode. For better performance use sbt's shell
# [info] compiling 1 Scala source and 1 Java source to /Users/pchabelski/IdeaProjects/scala-cli-tests-2/untitled/mixed-compilation-repro/dest/target/scala-3.5.0/classes ...
# [error] /Users/pchabelski/IdeaProjects/scala-cli-tests-2/untitled/mixed-compilation-repro/dest/src/main/java/Reporters.java:4:33: cyclic inheritance involving ConsoleReporter
# [error] ConsoleReporter
# [error]                ^
# [error] (Compile / compileIncremental) javac returned non-zero exit code
# [error] Total time: 2 s, completed Sep 4, 2024, 12:23:27 PM

Apparently the same also happens with Bazel... (cc @WojciechMazur)

I'm no longer convinced this is to be treated as a regression, we seem to have had this bug for a while... ๐Ÿ˜•

From what I see server=false doesn't compile Java files:

.scala-build
โ””โ”€โ”€ example-scala-3.5_1bc5085640
   โ””โ”€โ”€ classes
      โ””โ”€โ”€ main
         โ”œโ”€โ”€ exa
         โ”‚  โ”œโ”€โ”€ AbstractReporter.class
         โ”‚  โ”œโ”€โ”€ AbstractReporter.tasty
         โ”‚  โ”œโ”€โ”€ ConsoleReporter$.class
         โ”‚  โ”œโ”€โ”€ ConsoleReporter$AbstractConsoleReporter.class
         โ”‚  โ”œโ”€โ”€ ConsoleReporter.class
         โ”‚  โ””โ”€โ”€ ConsoleReporter.tasty
         โ”œโ”€โ”€ example$package$.class
         โ”œโ”€โ”€ example$package.class
         โ”œโ”€โ”€ example$package.tasty
         โ”œโ”€โ”€ logHelpers.class
         โ”œโ”€โ”€ logHelpers.tasty
         โ”œโ”€โ”€ O$.class
         โ”œโ”€โ”€ O$LogHelper$.class
         โ”œโ”€โ”€ O$LogHelper.class
         โ”œโ”€โ”€ O.class
         โ””โ”€โ”€ O.tasty

Edit: I have some additional files here, but there are not compiled java files

This is not related to the runner.
The only reason the error doesn't pop with --server=false is that --server=false ignores .java files right now.
Also see:

Since this happens in Bazel as well, I don't think it's Bloop-related.
We should investigate on the compiler side of things.