Frequent clean;compile issues

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


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.


[error] java.lang.AssertionError: assertion failed: trait Configuration has non-class parent: TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class gamatron)),object config),ConfigurationBase)


trait ConfigurationBase
trait Configuration extends ConfigurationBase {

Things I’d try…

  1. If you revert the Scala version to something earlier, does the problem go away?
  2. Did the problem start as soon as you went to 3.4.1 or later?
  3. If later, then what did you change?
  4. If you leave your project’s build file unchanged and replace your source code with something simpler, does the problem go away?
  5. If you checkout and build your project on another computer, does the problem go away?
  6. Do you have some long running session running at the same time as your build that might be using the same class path?
  7. Did you upgrade your xz utilities recently? :japanese_goblin:
  1. I might try 3.3.3 for most day-to-day operations, but because of Cannot use Dynamic with native Scala.js class / trait · Issue #19528 · scala/scala3 · GitHub 3.4.1 is the only version which can build the complete project
  2. the project is freshly ported from Scala 2.13. It was never running on anything else than 3.4.1. Older Scala 3 versions were only used during conversion effort, not for a day-to-day work
  3. no idea. This sounds quite hard to try.
  4. I use two computers regularly and I see the issue on both of them
  5. I do not think so. The only thing which could be running in presentation compiler used for IntelliJ IDE.
  6. I have upgraded many utilities so that I have Scala 3 versions of them. Yet the issue that clean;compile fails is new for me and specific to Scala 3, I do not remember this ever hapenning to me with Scala 2

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:

  1. Did you try turning it off and on again?
  2. Have you being playing the Three Body Game recently? (For all those readers of Liu Cixin). :smile:

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.

[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

Reported as

Sounds like this is an IDE problem.

A suggestion:

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

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

  3. 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… :smiley: )

In version 2024.1 they advertise better Scala-3 support.