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

"value getOffsetStatic is not a member of object scala.runtime.LazyVals" while testing Java-only library with ScalaTest + Scala 3.4.1 #7553

Open
lespea opened this issue May 6, 2024 · 9 comments

Comments

@lespea
Copy link

lespea commented May 6, 2024

steps

Repo showing steps / code: https://github.com/lespea/sbt-1.10-issue

(steps supplementary provided by @eed3si9n)

  1. make a Java-only library, and thus set autoScalaLibrary := false on the subproject
  2. but use the latest Scala 3.4.x only for testing
  3. using ScalaTest 3.2.18, which is published with Scala 3.1.3

problem

Compiling project with 1.10.0 fails with. Works with 1.9.9

[error] value getOffsetStatic is not a member of object scala.runtime.LazyVals
[error] Bad symbolic reference. A signature in /Users/username/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.1.3/scala3-library_3-3.1.3.jar(scala/runtime/LazyVals.tasty)
[error] refers to Waiting/T in object scala.runtime.LazyVals which is not available.
[error] It may be completely missing from the current classpath, or the version on
[error] the classpath might be incompatible with the version used when compiling /Users/username/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.1.3/scala3-library_3-3.1.3.jar(scala/runtime/LazyVals.tasty).
[error] Bad symbolic reference. A signature in /Users/username/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.1.3/scala3-library_3-3.1.3.jar(scala/runtime/LazyVals.tasty)
[error] refers to LazyValControlState/T in object scala.runtime.LazyVals which is not available.
[error] It may be completely missing from the current classpath, or the version on
[error] the classpath might be incompatible with the version used when compiling /Users/username/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.1.3/scala3-library_3-3.1.3.jar(scala/runtime/LazyVals.tasty).
[error] value Evaluating is not a member of object scala.runtime.LazyVals
[error] value NullValue is not a member of object scala.runtime.LazyVals
[error] value objCAS is not a member of object scala.runtime.LazyVals
[error] value countDown is not a member of scala.runtime.LazyVals.Waiting
[error] scala.runtime.LazyVals.Waiting does not have a constructor
[error] value getOffsetStatic is not a member of object scala.runtime.LazyVals
[error] value Evaluating is not a member of object scala.runtime.LazyVals
[error] value NullValue is not a member of object scala.runtime.LazyVals
[error] value objCAS is not a member of object scala.runtime.LazyVals
[error] value countDown is not a member of scala.runtime.LazyVals.Waiting
[error] scala.runtime.LazyVals.Waiting does not have a constructor
[error] value getOffsetStatic is not a member of object scala.runtime.LazyVals
[error] value Evaluating is not a member of object scala.runtime.LazyVals
[error] value NullValue is not a member of object scala.runtime.LazyVals
[error] value objCAS is not a member of object scala.runtime.LazyVals
[error] value countDown is not a member of scala.runtime.LazyVals.Waiting
[error] scala.runtime.LazyVals.Waiting does not have a constructor
[error] value getOffsetStatic is not a member of object scala.runtime.LazyVals
[error] value Evaluating is not a member of object scala.runtime.LazyVals
[error] value NullValue is not a member of object scala.runtime.LazyVals
[error] value objCAS is not a member of object scala.runtime.LazyVals
[error] value countDown is not a member of scala.runtime.LazyVals.Waiting
[error] scala.runtime.LazyVals.Waiting does not have a constructor
[error] 26 errors found
[error] (Test / compileIncremental) Compilation failed
[error] Total time: 4 s, completed May 6, 2024, 12:04:01 PM

expectation

Code continues to compile

workaround

libraryDependencies += "org.scala-lang" %% "scala3-library" % scalaVersion.value % Test

Version info

  • sbt --version
    • sbt version in this project: 1.10.0
    • sbt script version: 1.10.0
  • uname -a
    • Darwin LMHWTM9L2H 23.4.0 Darwin Kernel Version 23.4.0: Fri Mar 15 00:10:42 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6000 arm64
  • java --version
    • openjdk 21.0.3 2024-04-16 LTS
    • OpenJDK Runtime Environment Temurin-21.0.3+9 (build 21.0.3+9-LTS)
    • OpenJDK 64-Bit Server VM Temurin-21.0.3+9 (build 21.0.3+9-LTS, mixed mode)
@lespea lespea added the Bug label May 6, 2024
@eed3si9n
Copy link
Member

eed3si9n commented May 7, 2024

@lespea Thanks for a report with repro project!

@eed3si9n
Copy link
Member

eed3si9n commented May 7, 2024

So I am not exactly sure how it has worked in sbt 1.9.9, but looking at sbt 1.10.0:

> show Test/externalDependencyClasspath
....
[info] * Attributed(~/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.1.3/scala3-library_3-3.1.3.jar)
[info] * Attributed(~/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.8/scala-library-2.13.8.jar)
....

The classpath shows scala3-library_3 3.1.3, and scala-library 2.13.8. I think sbt 1.10.0 not compiling is more correct behavior than sbt 1.9.9.

@eed3si9n eed3si9n closed this as not planned Won't fix, can't repro, duplicate, stale May 7, 2024
@lespea
Copy link
Author

lespea commented May 7, 2024

🤔 hmm interesting. Good catch that it was using the older 3.1.3 library even though I was specifying 3.4.1. I guess I thought it was possible to use old scala 3 libraries with newer versions of scala 3 but I guess not? Now I'm sort of in a pickle as I updated our internal stuff to 3.4 already but apparently I shouldn't have.

@lespea
Copy link
Author

lespea commented May 7, 2024

Oh I read your message too fast.

Okay so the dependency list is the same in both cases so I don't think that's it? Are there some changes I need to make in the config so that it compiles? I'm guessing the issue is that no scala libs are being declared for build but in test it is using scala? And interesting it's saying the scala 3.1.3 library and not the one I declared, 3.4.1? (in the error message above: scala3-library_3-3.1.3.jar).

sbt 1.9.9

sbt:sbt10issue> show Test/externalDependencyClasspath
[info] * Attributed(/Users/Z001J31/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scalatest/scalatest_3/3.2.18/scalatest_3-3.2.18.jar)
[info] * Attributed(/Users/Z001J31/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scalatest/scalatest-core_3/3.2.18/scalatest-core_3-3.2.18.jar)
[info] * Attributed(/Users/Z001J31/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scalatest/scalatest-featurespec_3/3.2.18/scalatest-featurespec_3-3.2.18.jar)
[info] * Attributed(/Users/Z001J31/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scalatest/scalatest-flatspec_3/3.2.18/scalatest-flatspec_3-3.2.18.jar)
[info] * Attributed(/Users/Z001J31/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scalatest/scalatest-freespec_3/3.2.18/scalatest-freespec_3-3.2.18.jar)
[info] * Attributed(/Users/Z001J31/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scalatest/scalatest-funsuite_3/3.2.18/scalatest-funsuite_3-3.2.18.jar)
[info] * Attributed(/Users/Z001J31/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scalatest/scalatest-funspec_3/3.2.18/scalatest-funspec_3-3.2.18.jar)
[info] * Attributed(/Users/Z001J31/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scalatest/scalatest-propspec_3/3.2.18/scalatest-propspec_3-3.2.18.jar)
[info] * Attributed(/Users/Z001J31/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scalatest/scalatest-refspec_3/3.2.18/scalatest-refspec_3-3.2.18.jar)
[info] * Attributed(/Users/Z001J31/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scalatest/scalatest-wordspec_3/3.2.18/scalatest-wordspec_3-3.2.18.jar)
[info] * Attributed(/Users/Z001J31/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scalatest/scalatest-diagrams_3/3.2.18/scalatest-diagrams_3-3.2.18.jar)
[info] * Attributed(/Users/Z001J31/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scalatest/scalatest-matchers-core_3/3.2.18/scalatest-matchers-core_3-3.2.18.jar)
[info] * Attributed(/Users/Z001J31/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scalatest/scalatest-shouldmatchers_3/3.2.18/scalatest-shouldmatchers_3-3.2.18.jar)
[info] * Attributed(/Users/Z001J31/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scalatest/scalatest-mustmatchers_3/3.2.18/scalatest-mustmatchers_3-3.2.18.jar)
[info] * Attributed(/Users/Z001J31/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.1.3/scala3-library_3-3.1.3.jar)
[info] * Attributed(/Users/Z001J31/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scalactic/scalactic_3/3.2.18/scalactic_3-3.2.18.jar)
[info] * Attributed(/Users/Z001J31/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scalatest/scalatest-compatible/3.2.18/scalatest-compatible-3.2.18.jar)
[info] * Attributed(/Users/Z001J31/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/modules/scala-xml_3/2.1.0/scala-xml_3-2.1.0.jar)
[info] * Attributed(/Users/Z001J31/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.8/scala-library-2.13.8.jar)

sbt 1.10.0

sbt:sbt10issue> show Test/externalDependencyClasspath
[info] * Attributed(/Users/Z001J31/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scalatest/scalatest_3/3.2.18/scalatest_3-3.2.18.jar)
[info] * Attributed(/Users/Z001J31/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scalatest/scalatest-core_3/3.2.18/scalatest-core_3-3.2.18.jar)
[info] * Attributed(/Users/Z001J31/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scalatest/scalatest-featurespec_3/3.2.18/scalatest-featurespec_3-3.2.18.jar)
[info] * Attributed(/Users/Z001J31/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scalatest/scalatest-flatspec_3/3.2.18/scalatest-flatspec_3-3.2.18.jar)
[info] * Attributed(/Users/Z001J31/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scalatest/scalatest-freespec_3/3.2.18/scalatest-freespec_3-3.2.18.jar)
[info] * Attributed(/Users/Z001J31/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scalatest/scalatest-funsuite_3/3.2.18/scalatest-funsuite_3-3.2.18.jar)
[info] * Attributed(/Users/Z001J31/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scalatest/scalatest-funspec_3/3.2.18/scalatest-funspec_3-3.2.18.jar)
[info] * Attributed(/Users/Z001J31/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scalatest/scalatest-propspec_3/3.2.18/scalatest-propspec_3-3.2.18.jar)
[info] * Attributed(/Users/Z001J31/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scalatest/scalatest-refspec_3/3.2.18/scalatest-refspec_3-3.2.18.jar)
[info] * Attributed(/Users/Z001J31/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scalatest/scalatest-wordspec_3/3.2.18/scalatest-wordspec_3-3.2.18.jar)
[info] * Attributed(/Users/Z001J31/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scalatest/scalatest-diagrams_3/3.2.18/scalatest-diagrams_3-3.2.18.jar)
[info] * Attributed(/Users/Z001J31/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scalatest/scalatest-matchers-core_3/3.2.18/scalatest-matchers-core_3-3.2.18.jar)
[info] * Attributed(/Users/Z001J31/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scalatest/scalatest-shouldmatchers_3/3.2.18/scalatest-shouldmatchers_3-3.2.18.jar)
[info] * Attributed(/Users/Z001J31/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scalatest/scalatest-mustmatchers_3/3.2.18/scalatest-mustmatchers_3-3.2.18.jar)
[info] * Attributed(/Users/Z001J31/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.1.3/scala3-library_3-3.1.3.jar)
[info] * Attributed(/Users/Z001J31/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scalactic/scalactic_3/3.2.18/scalactic_3-3.2.18.jar)
[info] * Attributed(/Users/Z001J31/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scalatest/scalatest-compatible/3.2.18/scalatest-compatible-3.2.18.jar)
[info] * Attributed(/Users/Z001J31/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/modules/scala-xml_3/2.1.0/scala-xml_3-2.1.0.jar)
[info] * Attributed(/Users/Z001J31/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.8/scala-library-2.13.8.jar)

I double checked and there's no change to show Test/dependencyClasspath between 1.9.9 and 1.10.0 either.

@eed3si9n
Copy link
Member

eed3si9n commented May 7, 2024

Normally sbt will try to include the right scala library (scala3-library, or scala-library) but you specified:

autoScalaLibrary := false

so it just picked whatever that was in the transitive dependency graph.

@lespea
Copy link
Author

lespea commented May 7, 2024

Okay so I played with the build.sbt a bit and here are my findings:

val sVersion = "3.4.1"

lazy val root = project
  .in(file("."))
  .settings(
    name := "sbt10issue",
    version := "0.1.0",
    scalaVersion := sVersion,
    autoScalaLibrary := false,
    // Doesn't work
    Test / autoScalaLibrary := true,
    // Doesn't work
    Test / scalaVersion := sVersion,
    libraryDependencies ++= Seq(
      "org.scalatest" %% "scalatest" % "3.2.18" % Test,
      // Have to manually add this
      "org.scala-lang" %% "scala3-library" % sVersion % Test
    )
  )

Is there a way to make either of the doesn't work settings make it "just work" or do I just need to manually add the scala library as a dep for testing in all my java-only libs (that still use scala for testing). If so that's not a big deal but might be worth adding to the documentation whatever the appropriate fix is?

Also sorry if there's already a better way of doing this I'm just missing.

@eed3si9n
Copy link
Member

eed3si9n commented May 7, 2024

ok, so to clarify the goal here, you want to:

  1. make a Java-only library, and thus set autoScalaLibrary := false on the subproject
  2. but use the latest Scala 3.4.x only for testing
  3. using ScalaTest 3.2.18, which is published with Scala 3.1.3

I think this "test Java library" was a blind spot of modern Scala 3.x and 2.13.x + sbt.

Is there a way to make either of the doesn't work settings make it "just work" or do I just need to manually add the scala library as a dep for testing in all my java-only libs (that still use scala for testing). If so that's not a big deal but might be worth adding to the documentation whatever the appropriate fix is?

In the short term, my guess is that you'd have to manually add scala3-library, but we should add documentation around this, and perhaps try to implement Test / autoScalaLibrary := true or something like that in the future.

@eed3si9n eed3si9n reopened this May 7, 2024
@eed3si9n eed3si9n changed the title Compile error with 1.10.0 when autoScalaLibrary is false "value getOffsetStatic is not a member of object scala.runtime.LazyVals" while testing Java-only library with ScalaTest + Scala 3.4.1 May 7, 2024
@lespea
Copy link
Author

lespea commented May 7, 2024

Yeah that's basically my use case I guess I should have been more clear about that from the get-go. Sounds good if you can figure out an elegant way to make that work but for now I'll just add the dep as testing. Appreciate your help!

@ekrich
Copy link
Contributor

ekrich commented May 10, 2024

That is the configuration of lightbend/config as well. A Java library with Scala test. At one time adding Scala tests was considered a safe way to introduce Scala as a way that was not super critical and allowed people to learn and see the benefits of Scala. It uses an old version of Scala so it hasn't hit this. https://github.com/lightbend/config/blob/main/build.sbt

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

3 participants