scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

not found: type Serializable after Scala 2.13.6 upgrade up to 2.13.7+ #12740

Closed pomadchin closed 8 months ago

pomadchin commented 1 year ago

Reproduction steps

I was unable to get a locally reproducible / relatively easy project that fails. ~I could not reproduce it locally at all. 😭~ Thx team with all the help to reproduce it!

Scala version: 2.13.7+ SBT and JDK versions independent.

Code:

package test

package object X extends Serializable { }

object Test {
  def main(args: Array[String]): Unit = {

  }

}

Scasite: https://scastie.scala-lang.org/pomadchin/X8YFi5YuT9yUNTp1fpmNEA/1

Publish: $ ./sbt +publishLocal

Steps to try to reproduce locally with the https://github.com/PDAL/java project

$ git clone git@github.com:PDAL/java.git pdal-java
$ git checkout -f bug/scala-upd
$ cd pdal-java
$ docker run --rm -it -v $PWD:/pdal daunnc/pdal-ubuntu:2.5.1 bash
$ cd /pdal
$ ./sbt ++2.13 core-scala/publishLocal

I know that it makes this bug / feature report very hard to work with, but mb there is any chance to get some help tracing it? Any help / comments are really appreciated.

I spent a the whole weekend trying to catch it and was only able ("got lucky") to catch it in a smaller OSS project and reduce failure await times in CI.

Problem

In several projects (https://github.com/PDAL/java, https://github.com/locationtech/geotrellis/) after updating Scala 2.13.6 up to 2.13.7+ I get not found: type Serializable error on the package +publish command invocation, more specifically, on the Compile/doc stage.

The most unclear thing is that it may fail within some specific modules of a project, not in every module of a project, I was unable to catch the real issue / to find a simple reproducible way to catch it.

By experiments, I was able to double check that this behavior is not related to the SBT version and to the JDK version.

Code: https://github.com/PDAL/java/blob/bug/scala-upd/core-scala/src/main/scala/io/pdal/pipeline/package.scala#L19 Diff that triggers the CI error: https://github.com/PDAL/java/commit/f068ac26d59f893dce899dbe77e192f09d82400d CI Error: https://github.com/PDAL/java/actions/runs/4277401013/jobs/7446185708#step:6:201

[error] /__w/java/java/core-scala/src/main/scala/io/pdal/pipeline/package.scala:19:75: not found: type Serializable
[error] package object pipeline extends json.Implicits with syntax.Implicits with Serializable
[error]                                                                           ^
[error] one error found
...
[error] Scaladoc generation failed
[error]     at xsbt.Runner.run(ScaladocBridge.scala:50)
[error]     at xsbt.ScaladocBridge.run(ScaladocBridge.scala:21)
[error]     at sbt.internal.inc.AnalyzingCompiler.doc(AnalyzingCompiler.scala:154)
[error]     at sbt.internal.inc.AnalyzingCompiler.doc(AnalyzingCompiler.scala:133)
[error]     at sbt.Doc$.$anonfun$scaladoc$1(Doc.scala:52)
[error]     at sbt.Doc$.$anonfun$scaladoc$1$adapted(Doc.scala:40)
[error]     at sbt.RawCompileLike$.$anonfun$prepare$1(RawCompileLike.scala:79)
[error]     at sbt.RawCompileLike$.$anonfun$prepare$1$adapted(RawCompileLike.scala:72)
[error]     at sbt.RawCompileLike$.$anonfun$cached$4(RawCompileLike.scala:63)
[error]     at sbt.RawCompileLike$.$anonfun$cached$4$adapted(RawCompileLike.scala:61)
[error]     at sbt.util.Tracked$.$anonfun$inputChangedW$1(Tracked.scala:219)
[error]     at sbt.RawCompileLike$.$anonfun$cached$1(RawCompileLike.scala:68)
[error]     at sbt.RawCompileLike$.$anonfun$cached$1$adapted(RawCompileLike.scala:52)
[error]     at sbt.Defaults$.$anonfun$docTaskSettings$4(Defaults.scala:2156)
[error]     at scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error]     at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:62)
[error]     at sbt.std.Transform$$anon$4.work(Transform.scala:68)
[error]     at sbt.Execute.$anonfun$submit$2(Execute.scala:282)
[error]     at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:23)
[error]     at sbt.Execute.work(Execute.scala:[291])
[error]     at sbt.Execute.$anonfun$submit$1(Execute.scala:282)
[error]     at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)
[error]     at sbt.CompletionService$$anon$2.call(CompletionService.scala:64)
[error]     at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error]     at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
[error]     at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error]     at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
[error]     at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
[error]     at java.base/java.lang.Thread.run(Thread.java:829)
[error] (core-scala / Compile / doc) Scaladoc generation failed

Workarounds that work for now:

Ref to another project issue where I have the same problem https://github.com/locationtech/geotrellis/issues/3503

som-snytt commented 1 year ago

I wonder if package object X extends Serializable makes a difference. Serializable is a type alias in scala.package object.

pomadchin commented 1 year ago

@som-snytt wow a nice guess, it could be it, I can check it really quick.

However in some cases it could be caused by a trait, i.e. check this out (another project where I noticed the same behavior): https://github.com/locationtech/geotrellis/commit/b493b61430c51684ce4ff3f3bd1a00472e5992fe

som-snytt commented 1 year ago

This is the bell that rang https://github.com/scala/scala/pull/9661

SethTisue commented 1 year ago

miss the podcast ❤️ (the English-language one; I don't speak Russian)

pomadchin commented 1 year ago

👋 @SethTisue I miss it too ❤️

pomadchin commented 1 year ago

@som-snytt apparently it turned out to be not that easy to check 🤦 I added classes and they are not failing; only the only one causes failure (link to a diff to get error back).

But I think it is a very nice guess (https://github.com/scala/scala/pull/9661), it could be smth related to the loading ordering. That may explain why in some projects / modules package objects are compiling fine and in some are not, and why it's so hard to reproduce. 🤔

pomadchin commented 1 year ago

I was able to reproduce it in Scastie (https://scastie.scala-lang.org/pomadchin/X8YFi5YuT9yUNTp1fpmNEA/1), sadly still not locally; seems to be the fact that is a package object affects it indeed.

SethTisue commented 1 year ago

it reproduces for me locally with scala-cli and

//> using scala "2.13.10"                                                                           
package test
package object X extends Serializable { }                                                           
object Test {
  def main(args: Array[String]): Unit = {
  }
}

this fails during normal compilation, not even Scaladoc generation

pomadchin commented 1 year ago

Ha, yes, fails for me locally with scala-cli as well.

som-snytt commented 1 year ago

@SethTisue nice minimal rendition

@pomadchin I've forgotten if all inheritance for package objects is deprecated? Not to blame the victim. It may explain why it's not been reported. I fixed -Yimports for package objects, another underutilized feature.

pomadchin commented 1 year ago

@som-snytt I think package objects are deprecated and to be removed in general, since the top level expressions are legit in Scala 3.

Wooot there is a fix already? I think I read it too fast.

SethTisue commented 1 year ago

I've forgotten if all inheritance for package objects is deprecated?

@som-snytt Adriaan wanted that, but we ended up reverting it https://github.com/scala/scala-dev/issues/441

som-snytt commented 1 year ago

Thank-you both, I always forget which parallel universe we happen to find ourselves in.

som-snytt commented 1 year ago

~Wooot there is a fix already?~ I think I read it too fast.

Yes.

I may have coded it too fast.

pomadchin commented 1 year ago

@som-snytt woooot; incredible! I can try to test the PR later on all failing projects to double / triple check it.