bug
bug copied to clipboard
Compilation error (`None.get`) when adding `private val` to a case class field
Scala version: 2.13.13
private[zio] final case class FiberRefStack[@specialized(SpecializeInt) A] private[FiberRefs] (
private val headFiberId: FiberId.Runtime, // Doesn't compile with the `private val` but does compile without it
headValue: A,
headVersion: Int,
tail: List[FiberRefStackEntry[?]],
depth: Int
)
If we remove the private val of the private val headFiberId the code compiles. It seems to me that this private val headFiberId is valid Scala code and should compile
Reproducer: https://github.com/guizmaii/zio/pull/1
Note that I don't manage to reproduce the error in scastie: https://scastie.scala-lang.org/wynbilFLRTWlyVL3fjT7WQ
Unlike the PR code, the Scastie example is missing an @inline def accessor to the field that is marked (or not) as private val, so it is at the intersection of private val, specialize, and @inline def that is causing the error. This Scastie thus show the error https://scastie.scala-lang.org/jBdfI5ofRA2KxBPnCmTHAg
Not sure what the scastie intends to convey, but the zio scala_bug branch compileJVM fails. (Edit: the second scastie is missing specialized(Int).)
I see the code is trying to sort case class params by correlating non-method param accessors (which have correct sorting) with case accessor methods (unsorted and name-mangled).
A quick debug println shows the mismatch
NOACC in class FiberRefStack for method headFiberId$access$0 among List((zio$FiberRefs$FiberRefStack$$headFiberId,0), (headVersion,2), (headValue,1), (depth,4), (tail,3)) from List(value headValue, value headVersion, value tail, value depth, method headFiberId$access$0) and name List(zio$FiberRefs$FiberRefStack$$headFiberId, headValue, headVersion, tail, depth) or [zio$FiberRefs$FiberRefStack$$headFiberId ,headValue ,headVersion ,tail ,depth ]
it's looking for headFiberId prefix, not suffix. If access$0 is the private val mangling, I don't know offhand where the other mangling is introduced. The example snippet doesn't fail standalone.
So this is the reproucer, right?
object example {
final case class Toto[@specialized(Int) A] (
private val a: String,
b: A,
) {
@inline def theA: String = a
}
def toto[A](a: A): Toto[A] = Toto("", a)
}
@lrytz Yes, I think that the minimal reproducer
I should have said thanks for the reproductions. The inline is relevant. I took a look but have been occupied elsewhere.