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

In mixed compilation, Java parser can't handle JUnit annotation #20026

Closed
SethTisue opened this issue Mar 26, 2024 · 5 comments · Fixed by #21650
Closed

In mixed compilation, Java parser can't handle JUnit annotation #20026

SethTisue opened this issue Mar 26, 2024 · 5 comments · Fixed by #21650
Assignees
Milestone

Comments

@SethTisue
Copy link
Member

This came up at Lightbend over at akka/alpakka-kafka#1727

% cat S.scala
class S

% cat J.java
//> using scala 3.4.0
//> using dep org.junit.jupiter:junit-jupiter-api:5.10.2
@TestInstance(org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS)
class J { }

% scala-cli compile .
Compiling project (Scala 3.4.0, JVM (17))
[error] ./J.java:6:1
[error] ')' expected but eof found.

Next, I will see if I can construct a reproducer that doesn't involve an external library.

@SethTisue SethTisue added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Mar 26, 2024
@SethTisue SethTisue changed the title Java parser can't handle JUnit annotation In mixed compilation, Java parser can't handle JUnit annotation Mar 26, 2024
@som-snytt
Copy link
Contributor

The linked source is ordinary sbt build, in a Java package, with a correct import. That works in a trivial sbt project.

@SethTisue
Copy link
Member Author

SethTisue commented Mar 26, 2024

The linked source is ordinary sbt build, in a Java package, with a correct import. That works in a trivial sbt project.

I successfully reproduced the problem in sbt first before switching to scala-cli. Note that you do have to have both Scala and Java sources.

@som-snytt
Copy link
Contributor

No doubt it's one of those things.

➜  i20026-annot git:(master) cat src/main/scala/main.scala

class C {
}
➜  i20026-annot git:(master) cat ./src/main/java/trial/J.java

package trial;

import org.junit.jupiter.api.TestInstance;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class J { }
➜  i20026-annot git:(master) cat build.sbt

scalaVersion := "3.4.0"

ThisBuild / scalacOptions ++= Seq(
  //"-Vprint:all",
)

ThisBuild / libraryDependencies ++= Seq(
  "org.junit.jupiter" % "junit-jupiter-api" % "5.10.2"
)
➜  i20026-annot git:(master) sbt compile
[info] welcome to sbt 1.9.9 (Eclipse Adoptium Java 21.0.2)
[info] loading project definition from .../i20026-annot/project
[info] loading settings for project i20026-annot from build.sbt ...
[info] set current project to i20026-annot
[info] Executing in batch mode. For better performance use sbt's shell
[info] compiling 1 Scala source and 1 Java source to .../i20026-annot/target/scala-3.4.0/classes ...
[success] Total time: 3 s, completed Mar 26, 2024, 12:41:13 PM

@SethTisue
Copy link
Member Author

The plot thickens! The difference between your version and mine is the presence or absence of package trial;.

Which is peculiar, since naturally the original alpakka-kafka code does have a package declaration! So this seems to be rather fragile/subtle...

@SethTisue
Copy link
Member Author

SethTisue commented Apr 8, 2024

@som-snytt when you were looking into this (thank you!), did you discover whether there's a workaround?

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

Successfully merging a pull request may close this issue.

5 participants