Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate method name&signature involving overloading, generics, AnyVal & anonymous classes #10458

Open
dwijnand opened this issue Aug 9, 2017 · 4 comments

Comments

@dwijnand
Copy link
Member

dwijnand commented Aug 9, 2017

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
@dwijnand
Copy link
Member Author

dwijnand commented Aug 9, 2017

The unminimised original is typelevel/cats#1802.

@dwijnand
Copy link
Member Author

dwijnand commented May 1, 2019

There's history on these types of issues in #6260.

@eed3si9n
Copy link
Member

eed3si9n commented 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
Copy link
Member Author

dwijnand commented May 1, 2019

Yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants