Compilation error when using an inline method inside a non-inline block with unknown generic types

Hello, to add shapeless compatibility to my project, I’m trying to create a given instance which call an inline method in one of its methods:

  inline given [A, B, C <: Constraint[A, B]] (using typeA: Typeable[A], tag: ClassTag[A], constraint: C): Typeable[A ==> B] with {

    //refineValue is inline
    override def cast(t: Any): Option[A ==> B] = typeA.cast(t).map(refineValue[A, B, C](_))

    override def describe: String = s"${typeA.describe} ==> $tag"

I get the following error:

method refineValue is declared as erased, but is in fact used

How can I work around this error ?

Note: it works without anonymous class/instance. Here is a working part of my Circe support:

  inline given[A, B, C <: Constraint[A, B]](using inputDecoder: Decoder[A], c: C): Decoder[A ==> B] = inputDecoder
    .map(refineValue[A, B, C](_)) //refineValue is inline

I don’t know if it will help in this case, but have you tried increasing the value of -Xmax-inlines ? (see given instance is declared as erased, but is in fact used · Issue #13044 · lampepfl/dotty · GitHub)

Hello, I tried to change the -Xmax-inlines to 33 and more without success. I still have the same error.

Also I forgot to indicate but I’m using Scala 3.0.0.

EDIT: It also doesn’t work in Scala 3.0.1

Update on the issue: The error seems to occur when calling an inline method in a non-inline one with unknown/imprecise generic types.

inline def test[A]: Unit = inlineFoo[A] //OK
def test: Unit = inlineFoo[Something] //OK
def test[A]: Unit = inlineFoo[A] //Error

For now I didn’t find a workaround for the third case.

What type signature does inlineFoo have?
Perhaps you need a context bound def test[A: quoted.Type]: Unit?

It happens no matter the body. For example, inlineFoo can be:

inline def inlineFoo[A] = ???  

And it will still behave as described above.

Using an implicit quoted.Type doesn’t solve the issue. I assume it’s because the compiler tries to evaluate the generic type at compile-time but can’t.

So I tried another approach on my issue. I created a new thread because I got a different problem.