Skip to content
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

Mixed compilation with .java sources causes cyclic inheritance error #21533

Open
WojciechMazur opened this issue Sep 3, 2024 · 6 comments
Open

Comments

@WojciechMazur
Copy link
Contributor

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

@WojciechMazur WojciechMazur added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label compat:java labels Sep 3, 2024
@Gedochao
Copy link
Contributor

Gedochao commented Sep 4, 2024

@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.

@Gedochao Gedochao added regression This worked in a previous version but doesn't anymore area:runner Issues tied to the scala runner command. and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Sep 4, 2024
@dwijnand
Copy link
Member

dwijnand commented Sep 4, 2024

Is this reproducible with straight scala-cli?

@Gedochao
Copy link
Contributor

Gedochao commented Sep 4, 2024

Is this reproducible with straight scala-cli?

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

@Gedochao
Copy link
Contributor

Gedochao commented Sep 4, 2024

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... 😕

@Gedochao Gedochao removed the regression This worked in a previous version but doesn't anymore label Sep 4, 2024
@tgodzik
Copy link
Contributor

tgodzik commented Sep 4, 2024

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

@Gedochao Gedochao changed the title Unable to extend Scala class in Java when using build server Mixed compilation with .java sources causes cyclic inheritance error Sep 23, 2024
@Gedochao Gedochao removed the area:runner Issues tied to the scala runner command. label Sep 23, 2024
@Gedochao
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants