There is a "private option" -Yinfer-argument-types
that lets you:
scala> trait T { def f(i: Int) }
defined trait T
scala> new T { def f(i) = 2 * i }
res1: T = $anon$1@7915e83
You're asking for an option that would do the equivalent of:
scala> new T { def f() = 2 * i }
except with type parameters instead of value parameters.
I'm not sure what the semantics would be in your example. The method has a type param, but throw if it's not the type I expect?
Edit: Maybe you mean this:
scala> trait T { def f[ @specialized(Int) A](a: A): A = ??? }
defined trait T
scala> new T { def f(i: Int) = 2*i }
res0: T{def f(i: Int): Int} = $anon$1@50844aeb
scala> res7 f 7
warning: there were 1 feature warning(s); re-run with -feature for details
res8: Int = 14
There is no type param on the specialized method.
Update: This is probably the first appearance of elided REPL stack traces on SO:
scala> res7 f "hi!"
warning: there were 1 feature warning(s); re-run with -feature for details
scala.NotImplementedError: an implementation is missing
at scala.Predef$.$qmark$qmark$qmark(Predef.scala:229)
at $anon$1.f(<console>:9)