Here is the code:
sealed trait Tr
final case class A(a: String) extends Tr
final case class B(b: String) extends Tr
def markWithType[Type <: Tr](tr: Type): Type = tr match {
//Compile error
//Expression of type A doesn't conform to expected type Type
case A(a) => A("A:" + a)
//Compile error
//Expression of type B doesn't conform to expected type Type
case B(b) => B("B:" + b)
}
The problem is it does not compile. I want to preserve Type <: Tr
and make it compiling successfully. Is there a way to do that?
I'm pretty sure shapeless can be helpful here.