title: Scala implicit parameter scope
body: <p>I've spent all morning reading up on how Scala scopes implicits, including the very excellent answer here: <a href="https://stackoverflow.com/questions/5598085/where-does-scala-look-for-implicits">Where does Scala look for implicits?</a></p>
  
  <p>But alas, I am still confused. Let me give an example of what I'm trying to do:</p>
  
  <pre><code>object Widget {
    implicit val xyz: Widget = new Widget("xyz")
  }
  class Widget(val name: String) {
    override def toString = name
  }
  class Example {
    def foo(s: String)(implicit w: Widget): Unit = {
      println(s"Got $s with $w")
    }
    def bar {
      foo("abc")  // Compiler error at this line
    }
  }
  
  object implicit_test {
    val x = new Example()
    x.bar
  }
  </code></pre>
  
  <p>So, I expect to see something like <code>Got abc with xyz</code>. Instead I get told <code>could not find implicit value for parameter w: Widget</code>. Now, strangely if I move the <code>Widget</code> class and object as well as the <code>Example</code> class <em>inside</em> the <code>implicit_test</code> object, then this works.</p>
  
  <p>Please explain to me again, if you will, how exactly Scala identifies which implicit val to use!</p>