Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation error (None.get) when adding private val to a case class field #12988

Closed
guizmaii opened this issue Apr 20, 2024 · 5 comments · Fixed by scala/scala#10763
Closed
Assignees
Milestone

Comments

@guizmaii
Copy link

guizmaii commented Apr 20, 2024

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: guizmaii/zio#1

Note that I don't manage to reproduce the error in scastie: https://scastie.scala-lang.org/wynbilFLRTWlyVL3fjT7WQ

@diesalbla
Copy link

diesalbla commented Apr 20, 2024

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

@som-snytt
Copy link

som-snytt commented Apr 20, 2024

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.

@lrytz
Copy link
Member

lrytz commented Apr 22, 2024

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 lrytz added this to the Backlog milestone Apr 22, 2024
@guizmaii
Copy link
Author

@lrytz Yes, I think that the minimal reproducer

@som-snytt
Copy link

I should have said thanks for the reproductions. The inline is relevant. I took a look but have been occupied elsewhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants