This was originaly intended as a Scala 3 bug report, but I decided to sent it here instead to gather some feedback first. Because I understand an error report like this is not much actionable. Perhaps other people are experiencing similiar issues and could add their observations or examples of error reports?
I experience frequent failures of clean
followed by compile
or test
, which is something which has always worked to me in Scala 2.
Also I think number of times I need to rebuild my project because incremental compilation is failing has increased compared to Scala 2.13.
Compiler version
3.4.1
Minimized code
I am unable to provide a minimized code. This happens in a large project only. It happens quite frequently, perhaps once in 5 builds. When I perform clean
followed with compile
or test
from SBT, I often get errors on first run. The errors are nonsensical errors telling me classes which exist are missing from class-path and similar issues. When I repeat compile
or test
, the project usually completes building.
Output
[error] java.lang.AssertionError: assertion failed: trait Configuration has non-class parent: TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class gamatron)),object config),ConfigurationBase)
While:
trait ConfigurationBase
trait Configuration extends ConfigurationBase {
Configuration.init()
}
Deja-vu from another post…
Regarding Q1 and Q4, there is nothing stopping you from experimenting - so just remove those bits of code that rely on Scala 3.4.1 and try building against earlier versions in the Scala 3 series.
Likewise for reducing the size of your codebase - delete some files and comment out the bits wouldn’t compile because of the deletions.
You don’t have to commit your experiments.
Regarding Q2 and Q3, did it immediately happen while you were working up through those older Scala versions? Did you have a period of time where the build wasn’t flaky? Sure you haven’t upgraded something on the way? Unlikely that this is the case, given that you’ve tried it on more than one computer, unless you upgraded on both…
I forgot Q0 and Q8:
- Did you try turning it off and on again?
- Have you being playing the Three Body Game recently? (For all those readers of Liu Cixin).
I think it might be this. One difference between Scala 2 and Scala 3 is for Scala 2 IDE is using built-in parser, while for Scala 3 it uses presentation compiler. While I do not think the presentation compiler is writing anything, still there might be some interaction, perhaps it might prevent the compiler running from SBT to create files or something like that?
Another error I have just seen is below. This happened while I was viewing files in IDE while waiting for the SBT build to complete.
clean;compile
[success] Total time: 2 s, completed 4 Apr 2024, 14:04:03
[info] compiling 464 Scala sources and 9 Java sources to C:\Dev\tempi\target\scala-3.4.1\classes ...
[error] error writing C:\Dev\tempi\target\scala-3.4.1\classes\net\gamatron\json\JsDeclarations$.class: java.nio.file.NoSuchFileException C:\Dev\tempi\target\scala-3.4.1\classes\net\gamatron\json\JsDeclarations$.class
[error] error writing C:\Dev\tempi\target\scala-3.4.1\classes\net\gamatron\json\JsDeclarations.class: java.nio.file.NoSuchFileException C:\Dev\tempi\target\scala-3.4.1\classes\net\gamatron\json\JsDeclarations.class
[error] error writing C:\Dev\tempi\target\scala-3.4.1\classes\net\gamatron\json\JsDeclarations.tasty: java.nio.file.NoSuchFileException C:\Dev\tempi\target\scala-3.4.1\classes\net\gamatron\json\JsDeclarations.tasty
[error] error writing C:\Dev\tempi\target\scala-3.4.1\classes\net\gamatron\json\Schema$$anon$1.class: java.nio.file.NoSuchFileException C:\Dev\tempi\target\scala-3.4.1\classes\net\gamatron\json\Schema$$anon$1.class
[error] error writing C:\Dev\tempi\target\scala-3.4.1\classes\net\gamatron\json\Schema$$anon$2.class: java.nio.file.NoSuchFileException C:\Dev\tempi\target\scala-3.4.1\classes\net\gamatron\json\Schema$$anon$2.class
Hmm - are you running a ~compile
in SBT from the command line at the same time as using IntelliJ?
I have to be careful when I’m running SBT externally at the same time as using IntelliJ (as opposed to IntelliJ using it internally as part of its build). As I recall, I think that even if IntelliJ uses its own build mechanism, this gets confused by an external SBT build.
I am used to use sbt shell while working in IntelliJ. I never had issues with this in Scala 2.13. It seems Scala 3 is different in this respect.
I have now tried sbt from terminal with IDE not running. I have seen no issues in 10 rebuilds. Once I launched the IDE and browsed the files while SBT was building, I got 2 failures from 10 attempts. I was not compiling / building from the IDE at the same time SBT is building. just reading, switching and navigating between files.
The error I see most often is:
package.class is out of sync with its TASTy file. Loaded TASTy file. Try cleaning the project to fix this issue
Sounds like this is an IDE problem.
A suggestion:
-
Turn off builds
in the sbt shell section of your IntelliJ settings under Build, Execution, Deployment > Build Tools > sbt, but leave project reload
enabled. I build in IntelliJ this way from moment to moment, running individual test suites. I use external SBT builds to run all test suites, do full coverage, mutation testing, check merges and to make releases.
-
Don’t run an incremental SBT compile externally while working in IntelliJ and remember to rebuild when you switch back from using SBT from the command line.
-
Make sure you are up to date with IntelliJ and the Scala plugin.
Good luck!
IntelliJ is just not there yet with Scala 3. (I thought everyone knew that… )
In version 2024.1 they advertise better Scala-3 support.
2 Likes