Open
Description
class Bippy[A](val value: A) extends AnyVal
trait Foo[A] {
def m(x: A): Int
}
trait Bar[A] extends Foo[A] {
def m(x: A): Int
}
object Main {
def create[A] = new Bar[Bippy[A]] { def m(x: Bippy[A]) = 0 }
def main(args: Array[String]): Unit = create[Int]
}
java.lang.ClassFormatError: Duplicate method name&signature in class file Main$$anon$1
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at Main$.create(f.scala:12)
at Main$.main(f.scala:14)
at Main.main(f.scala)
Scala 2.12.3
There's a number of changes that make the error go away. But making it non-anonymous makes it a compile error:
class BippyBar[A] extends Bar[Bippy[A]] {
def m(x: Bippy[A]) = 0
}
error: bridge generated for member method m: (x: Bippy[A])Int in class BippyBar
which overrides method m: (x: A)Int in trait Bar
clashes with definition of the member itself;
both have erased type (x: Object)Int
def m(x: Bippy[A]) = 0
^
one error found
Activity
dwijnand commentedon Aug 9, 2017
The unminimised original is typelevel/cats#1802.
dwijnand commentedon May 1, 2019
There's history on these types of issues in #6260.
eed3si9n commentedon May 1, 2019
What's the expectation here? Are you asking that anonymous classes should be treated the same way as the named classes, and fail at compile time?
dwijnand commentedon May 1, 2019
Yes.