Open
Description
Compiler version
3.7.1
Minimized code
//> using scala 3.7.1
trait Ctx
object Foo extends Selectable:
type Fields = (x: Ctx ?=> Int, y: Ctx ?=> Int)
def selectDynamic(name: String): Ctx ?=> Int =
(ctx: Ctx) ?=> 1
@main def test =
given Ctx = new Ctx {}
val x: Int = Foo.x
println(x)
Output
% scala test.scala
Compiling project (Scala 3.7.1, JVM (21))
Compiled project (Scala 3.7.1, JVM (21))
Exception in thread "main" java.lang.ClassCastException: class java.lang.Integer cannot be cast to class scala.Function1 (java.lang.Integer is in module java.base of loader 'bootstrap'; scala.Function1 is in unnamed module of loader 'app')
at test$package$.test(test.scala:13)
at test.main(test.scala:11)
Expectation
Should work.
For reference, regular functions work
//> using scala 3.7.1
trait Ctx
object Foo extends Selectable:
type Fields = (x: Ctx => Int, y: Ctx => Int)
def selectDynamic(name: String): Ctx => Int =
(ctx: Ctx) => 1
@main def test =
val ctx = new Ctx {}
val x: Int = Foo.x(ctx)
println(x)
% scala test2.scala
Compiling project (Scala 3.7.1, JVM (21))
Compiled project (Scala 3.7.1, JVM (21))
1