I've got a class that depends on an HList
, has a polymorphic function and a method to map this function over the list. The strange thing is that this method can only be invoked on a val
, otherwise the compilation fails:
import shapeless._
import shapeless.ops.hlist.Mapper
class C[L <: HList](l: L) {
object f extends Poly1 {
implicit def whatever[T] = at[T]{_ => ()}
}
def g(implicit m: Mapper[f.type,L]) = ()
}
val c = new C(1 :: "s" :: HNil)
// this line compiles:
val v1 = c.g
// compilation fails if c is inlined:
val v2 = (new C(1 :: "s" :: HNil)).g
// error: could not find implicit value for parameter m:
// Mapper[_1.f.type, Int :: String :: HNil]]]
Is there a way to overcome such behaviour while keeping f
inside C
? I've tried to extract the method g
to another class or object, but it didn't help.