Open m8nmueller opened 4 months ago
I have a follow-up crash when I fix that problem (by adding type Result[+V] = V
to Stream
), though they don't seem to be directly related (this one also happens in a much later phase).
Again it involves two files, but this time, it only happens when compiling one after another (so scalac Stream.scala
followed by scalac test.scala
). I could simplify the type parameters a bit but the Family/Result types seem to be involved, as the crash vanishes when I remove them.
File Stream.scala
trait StreamOps:
self: Family =>
type Family
type Result[+W]
trait PullReaderStreamOps extends StreamOps:
self: Family =>
def parallelismHint: Int
def fold(): Result[Unit]
File test.scala
def test(stream: PullReaderStreamOps): Int = stream.parallelismHint
Another Edit: Dropping the second file, even reading the first (scalac -decompile PullReaderStreamOps.tasty
) fails with the same dotty.tools.dotc.core.RecursionOverflow thrown from the UncaughtExceptionHandler in thread "main"
.
It looks like the original issue doesn't crash with nightly anymore, however both the original snippet and the new snippet crash with -Ytest-pickler
. Which is just a shorthand for testing decompilation i.e. the same thing as described in the last comment, just easier to test.
I managed to minimize it even further with -Ytest-pickler
Code:
//> using scala 3.nightly
//> using options -Ytest-pickler
trait Parent:
type Family
trait Child extends Parent:
self: Family =>
Crash:
Thanks for your help!
When you look at the tasty generated for your example, it contains the following definition:
The type reference TYPEREFsymbol 4
makes the unpickler recurse endlessly:
If, instead, I add an override type Family
to child, the tasty looks like below. Since the self type references the symbol from its own template (24: TYPEREFsymbol 40
), this seems to be cacheable.
Somehow the typer manages to trace the self type to the type definition (though it is arguably cyclic and self: this.Family
is rejected). If the type definition happens to be in the same class this will also be correctly unpickled.
But I don't understand the compiler well enough to track it down completely. I guess, the type reference to the Family
type should actually reference it from Parent
, not from Child
itself.
Compiler version
3.4.2
Minimized code
I tried to minimize as much as possible, but the crash is solved when either removing
map
orfold
. If the two files are merged together, the compile still crashes, but it prints a type error before. I know that the self types ofStream
andPullReaderStream
do not work out, but that will be my business :).File Stream.scala:
File PullStream.scala
Output (click arrow to expand)