Skip to content

Problematic interaction between @static and inline functions with given parameters #16255

Open
@CoolDalek

Description

@CoolDalek

Compiler version

3.2.0 and 3.2.1

Minimized code

import java.lang.invoke.{MethodHandles, VarHandle}
import scala.annotation.static
import scala.reflect.{ClassTag, classTag}

class Wrapper(private val underlying: Int)
object Wrapper:
  @static private val vh = Helper.createVH[Wrapper, Int]("underlying")
object Helper:
  inline def createVH[Wrapper: ClassTag, Var: ClassTag](name: String): VarHandle =
    MethodHandles.lookup().findVarHandle(
      classTag[Wrapper].runtimeClass,
      name,
      classTag[Var].runtimeClass,
    )

Output

java.lang.IllegalArgumentException: Could not find proxy for val evidence$1$proxy1: scala.reflect.ClassTag in [value evidence$1$proxy1, value vh, object Wrapper, package <empty>, package <root>], encl = package <empty>, owners = package <empty>, package <root>; enclosures = package <empty>, package <root> while running MegaPhase{lambdaLift, elimStaticThis, countOuterAccesses} on filename.scala

Expectation

Code compiles, the compiler generates static field vh, code from createVH gets inlined into static initializer of the field.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions