Skip to content

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

Open
@dwijnand

Description

@dwijnand
Member
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

dwijnand commented on Aug 9, 2017

@dwijnand
MemberAuthor

The unminimised original is typelevel/cats#1802.

dwijnand

dwijnand commented on May 1, 2019

@dwijnand
MemberAuthor

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

eed3si9n

eed3si9n commented on May 1, 2019

@eed3si9n
Member

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

dwijnand commented on May 1, 2019

@dwijnand
MemberAuthor

Yes.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @eed3si9n@dwijnand

        Issue actions

          Duplicate method name&signature involving overloading, generics, AnyVal & anonymous classes · Issue #10458 · scala/bug