Hello, I get a “weird” deferred inline in a very specific case. I will try to be as accurate as possible.
I have a refineValue
method which ask for a Constraint[A, B]
with 2 inline methods: assert(A)
and getMessage(A)
:
implicit inline def refineValue[A, B, C <: Constraint[A, B]](value: A)(using inline constraint: C): Constrained[A, B] = {
constraint.getMessage()
// The below code is the "real" code but the above line is more minimal (for the sample) and has the same bug
// Constrained(compileTime.preAssert[A, B, C](value, constraint))
}
And I’m trying to use this method in a custom shapeless Typeable[A]
:
class ConstrainedTypeable[A, B, C <: Constraint[A, B]](using typeA: Typeable[A], tag: ClassTag[A], constraint: C) extends Typeable[A ==> B] {
override inline def cast(t: Any): Option[A ==> B] = {
refineValue[A, B, C](typeA.cast(t).get)
None
}
override def describe: String = s"${typeA.describe} ==> $tag"
}
inline given [A, B, C <: Constraint[A, B]] (using Typeable[A], ClassTag[A], C): Typeable[A ==> B] = new ConstrainedTypeable
but when I try to compile it I get:
Deferred inline method getMessage in trait Constraint cannot be invoked
I tried to re-create a more minimal example without success so here is the snapshot of the non-working code:
The error seem to be related to the non-inline nature of Typeable#cast
. For example, if I override this trait instead of Typeable:
trait TestTypeable[A] {
inline def cast(t: Any): Option[A]
def describe: String
}
it compiles.