Skip to content

Path generated for implicit conversion leads to NoSuchMethodError #13160

@lrytz

Description

@lrytz

Requires separate compilation

T.scala

trait T {
  object i {
    class C
    private object C {
      import scala.language.implicitConversions
      implicit def c2i(a: C): Int = 42
    }
  }
}

object O {
  def foo(x: Int): String = "hi"
}

U.scala

object Test extends T {
  def main(): Unit = {
    println(O.foo(new i.C))
  }
}
➜ sandbox sc T.scala && sc U.scala && sr Test
> scala compile --server=false -S 2.13 -d . -release 8 T.scala
> scala compile --server=false -S 2.13 -d . -release 8 U.scala
> scala run -S 2.13 -cp . -M Test
Exception in thread "main" java.lang.NoSuchMethodError: 'T$i$C$ T$i$.T$i$$C()'
	at Test$.main(U.scala:3)
	at Test.main(U.scala)

An implicit conversion gets added in O.foo(new i.C) and we get O.foo(Test.this.i.C.c2i(new Test.this.i.C())). This code is not valid, the object C is not accessible.

In a later phase the compiler calls makeNotPrivate on the symbol for C, which results in the T$i$$C name being emitted.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions