This is not a Scala compiler error, but it is, of course, a limitation of Scala type output. The compiler wants to determine the binding on X , S[T] before solving for X , but the reference mentions a variable of type T , which is therefore fixed in Nothing and comes from there. It does not review T times when X was completely resolved ... Currently, type inference always goes from left to right in this case.
If your example accurately reflects your real situation, then there is a simple fix,
def apply[T](x : S[T]) = x.doSomething
Here T will be deduced so that Minimal will correspond to S[T] directly, and not through an intermediate variable of a limited type.
Update
Joshua's solution also avoids the problem of type T inference, but in a completely different way.
def apply[T, X <% S[T]](x : X) = x.doSomething
desugars to,
def apply[T, X](x : X)(implicit conv : X => S[T]) = x.doSomething
Variables such as T and X can now be resolved independently (since T no longer mentioned in X bound). This means that X is output as Minimal immediately, and T is resolved as part of an implicit search for a value of type X => S[T] to satisfy the implicit argument conv . conforms in scala.Predef produces the values ββof this form, and in the context ensures that, given an argument of type Minimal , T will be displayed as Int. You can view this as an instance of functional dependencies when working in Scala.
source share