title: Unexpected "recursive value needs type" compile error (triggered by local implicits)
body: <p>I just encountered an unexpected compile error "recursive value xx needs type".  Trying to simplify, I came up with the following code that doesn't compile with Scala 2.12.3:</p>
  
  <pre><code>class Wrapped[A](val inner: A)(implicit val ctag: ClassTag[A]){
    type Inner = A
    def classInfo: String = ctag.toString
  }
  object Implicits {
    val W = new Wrapped(1234)
    implicit val InnerSeq: Seq[W.Inner] = Seq(1,2)
    implicit val InnerSet: Set[W.Inner] = Set(1,2) // Error: recursive value W needs type
  }
  </code></pre>
  
  <p>I would assume that the type of <code>W</code> is well defined. But it seems that due to the type <code>W</code> occurring in the return type of the local implicit values, <code>W</code> is considered recursive even if the implicits are not used in creation of <code>W</code>.</p>
  
  <p>The strange thing is that removing the second value <code>InnerSet</code> makes the code compile. So one implicit val referring <code>W.Inner</code> is OK, while two or more is a no-go.</p>
  
  <p>Removing the implicit <code>ClassTag</code> dependency for the Wrapper also makes the code compile.</p>
  
  <p>It is easy to get around the problem by moving W to a separate trait, but it would be good to know what's going on here. Why does the code compile with only one implicit in scope?</p>
  
  <p><strong>Update:</strong></p>
  
  <p>In the last preview version of Dotty, the compiler behaves more consistently and doesn't allow any implicits referring W.inner in scope at all:</p>
  
  <pre><code>[error] -- [E045] Syntax Error: 
  [error] 9 |  implicit val InnerSeq: Seq[W.Inner] = Seq(1,2)
  [error]   |                             ^
  [error]   |                             cyclic reference involving value W
  [error] one error found
  </code></pre>