Reproduction steps
Scala version: 2.13.16
class B(private[this] var x :Int)
val x = MethodHandles.lookup().findVarHandle(
classOf[B], "x", classOf[Int]
)
def set[@specialized(Int) X](v :VarHandle, owner :Any, value :X) :Unit =
v.set(owner, value)
Problem
[info] compiling 2 Scala sources to C:\Users\turin\porn\test\target\scala-2.13\classes ...
[error] C:\Users\turin\porn\test\src\main\scala\Test.scala:80:16: type mismatch;
[error] found : value.type (with underlying type Int)
[error] required: X
[error] v.set(owner, value)
[error] ^
The same applies if it's a method in a @specialized class where X is the class type parameter, not a method type parameter.
Is there any chance this might get fixed? There are no feasible workarounds that I can come up with.
The main problem is that Java methods with polymorphic signatures tend to be those which are required by highly performant code. For example, if I hide VarHandle.setRelease in a virtual method it completely defeats the purpose because virtual methods have full memory barriers before and after the call. The only actually usable solution is full manual specialization for every supported type of whole methods using a VarHandle, which is horrendous. I am still mostly on Scala 2 in a huge part because of specialization and a complete lack of any placeholder solution other than the Stepper case (which is, ironically, @specialized).
Reproduction steps
Scala version: 2.13.16
Problem
The same applies if it's a method in a @specialized class where
Xis the class type parameter, not a method type parameter.Is there any chance this might get fixed? There are no feasible workarounds that I can come up with.
The main problem is that Java methods with polymorphic signatures tend to be those which are required by highly performant code. For example, if I hide
VarHandle.setReleasein a virtual method it completely defeats the purpose because virtual methods have full memory barriers before and after the call. The only actually usable solution is full manual specialization for every supported type of whole methods using aVarHandle, which is horrendous. I am still mostly on Scala 2 in a huge part because of specialization and a complete lack of any placeholder solution other than theSteppercase (which is, ironically,@specialized).