Skip to content

Structural Type invocation can result fail during reflective lookup due to bridging #10414

Open
@retronym

Description

@retronym

The residual, and hard-to-fix, part of #10334. scala/scala#5977 restored parity with 2.11 with respect to the way this problem manifest with lambdas, but the core issue remains unsolved:

  def t3(): Unit = {
    val f1 = new T[A] {
      def m(x: A) = "f1-a"
      def m(x: B) = "f1-b"
       // the m(Object)Object bridge method invokes (A)Object
    }

    val f2 = new T[B] {
      def m(x: A) = "f2-a"
      def m(x: B) = "f2-b"
       // the (Object)Object bridge method invokes (B)Object
    }

    val g1: T[C] = f1
    val g2: T[C] = f2

    assert(g1.m(new C) == "f1-a")
    assert(g2.m(new C) == "f2-b")

    val s1: { def m(s: C): Object } = g1
    val s2: { def m(s: C): Object } = g2

    // the reflective lookup doesn't find `m(C)Object`
    try {
      s1.m(new C) // should invoke `m(A)Object`
      throw new Error()
    } catch {
      case _: java.lang.NoSuchMethodException =>
    }

    // the reflective lookup doesn't find `m(C)Object`
    try {
      s2.m(new C) // should invoke `m(B)Object`
      throw new Error()
    } catch {
      case _: java.lang.NoSuchMethodException =>
    }
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixed in Scala 3This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)structural types

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions