The real problem is that your intToView
method fundamentally doesn't make sense and can't be usefully implemented.
Right now it effectively says "give me an integer and tell me a subtype of View
, and I'll give you an instance of that subtype". But this isn't possible, because I can invent some pretty messed-up classes that extend View
. For example:
class NamedView(val name: String) extends View
The type signature of your intToView
method promises that the following should work:
val viewName: String = intToView[NamedView](13).name
What could this possibly be? How could you implement intToView
in such a way that it would know how to create a NamedView
, which I've just made up on the spot?
So ???
has allowed you to write a method that compiles but doesn't make sense. This is a dangerous situation to be in, since it means the compiler is liable to do all kinds of stupid things down the line.
In this case the stupid thing it does is decide that what it really has here is an implicit conversion from Int
to Nothing
, and of course Nothing
is a subtype of RichView[_]
, so it also has an implicit conversion from Int
to RichView[_]
. Then you give it another implicit conversion from Int
to RichView[_]
and it chokes.
The simplest solution in this case is to remove the type parameter from intToView
:
implicit def intToView(i: Int): View = ???
Whether this will work in your real use case depends on exactly what you're trying to do.