Permalink
Browse files

Consider method-scoped companions in the implicit scope.

Fixes SI-4975.

I'll reproduce a relevant snippet of dialogue from Namers#companionSymbolOf:

/** The companion class or companion module of `original`.
   *  Calling .companionModule does not work for classes defined inside methods.
   *
   *  !!! Then why don't we fix companionModule? Does the presence of these
   *  methods imply all the places in the compiler calling sym.companionModule are
   *  bugs waiting to be reported? If not, why not? When exactly do we need to
   *  call this method?
   */
  def companionSymbolOf(original: Symbol, ctx: Context): Symbol = {

This was one such bug.
  • Loading branch information...
retronym committed May 20, 2012
1 parent 1f5584f commit 03e6d929ee639de292daa778dde514e1b7014eac
Showing with 13 additions and 1 deletion.
  1. +1 −1 src/compiler/scala/tools/nsc/typechecker/Implicits.scala
  2. +12 −0 test/files/pos/t4975.scala
@@ -929,7 +929,7 @@ trait Implicits {
}
case None =>
if (pre.isStable) {
- val companion = sym.companionModule
+ val companion = companionSymbolOf(sym, context)
companion.moduleClass match {
case mc: ModuleClassSymbol =>
val infos =
View
@@ -0,0 +1,12 @@
+object ImplicitScope {
+ class A[T]
+
+ def foo {
+ trait B
+ object B {
+ implicit def ab = new A[B]
+ }
+
+ implicitly[A[B]] // Error
+ }
+}

0 comments on commit 03e6d92

Please sign in to comment.