I have this code:
class Action[T]
class Insert[T] extends Action[T]
case class Quoted[T]()
implicit def unquote[T](q: Quoted[T]): T = {
throw new Exception("Success")
}
def test[A <: Action[_]](a: A): A = {
return a
}
try {
test[Insert[String]](Quoted[Insert[String]])
test(unquote(Quoted[Insert[String]]))
// test(Quoted[Insert[String]]) // does not compile
} catch {
case e: Exception => print(e.getMessage())
}
Commented line fails during compilation with:
error: inferred type arguments [ScalaFiddle.Quoted[ScalaFiddle.Insert[String]]] do not conform to method test's type parameter bounds [A <: ScalaFiddle.Action[_]]
test(Quoted[Insert[String]])
error: type mismatch;
found : ScalaFiddle.Quoted[ScalaFiddle.Insert[String]]
required: A
test(Quoted[Insert[String]])
Is there any way to make it compile without specifying type parameter or explicitly using conversion function as in previous two lines?