title: How to infer the right type parameter from a projection type?
body: <p>I have some troubles having Scala to infer the right type from a type projection.</p>
  
  <p>Consider the following:</p>
  
  <pre><code>trait Foo {
    type X
  }
  
  trait Bar extends Foo {
    type X = String
  }
  
  def baz[F &lt;: Foo](x: F#X): Unit = ???
  </code></pre>
  
  <p>Then the following compiles fine:</p>
  
  <pre><code>val x: Foo#X = ???    
  baz(x)
  </code></pre>
  
  <p>But the following won't compile:</p>
  
  <pre><code>val x: Bar#X = ???    
  baz(x)
  </code></pre>
  
  <p>Scala sees the "underlying type String" for <code>x</code>, but has lost the information that <code>x</code> is a <code>Bar#X</code>. It works fine if I annotate the type:</p>
  
  <pre><code>baz[Bar](x)
  </code></pre>
  
  <p>Is there a way to make Scala infer the right type parameter for <code>baz</code>?<br>
  If not, what is the general answer that makes it impossible?</p>