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

ClassFormatError in specialized classes with override val mixins #9965

Open
scabug opened this issue Oct 15, 2016 · 2 comments
Open

ClassFormatError in specialized classes with override val mixins #9965

scabug opened this issue Oct 15, 2016 · 2 comments

Comments

@scabug
Copy link

scabug commented Oct 15, 2016

Not sure if this construct should be supported or not, but in the latter case I guess the compiler should complain instead.

object Playground extends App {
	trait I[@specialized T] {
		def fun :T=>T
		def m(value :T) :T
	}

	trait M[@specialized T] extends I[T]{
		override def fun = m _
	}

	trait V[@specialized T] extends I[T] {
		abstract override val fun = super.fun
	}

	class B[@specialized T] extends I[T] with M[T] with V[T] {
		override def m(value :T) = value
	}

	val subject = new B[Int]
	println(subject.fun(42))
}

Produces

Exception in thread "main" java.lang.ClassFormatError: Duplicate method name&signature in class file Playground$B$mcI$sp
	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 sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	at Playground.main(Playground.scala)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
@scabug
Copy link
Author

scabug commented Oct 15, 2016

Imported From: https://issues.scala-lang.org/browse/SI-9965?orig=1
Reporter: Marcin Mościcki (mmoscicki)
Affected Versions: 2.11.8

@scabug
Copy link
Author

scabug commented Oct 15, 2016

Marcin Mościcki (mmoscicki) said:
Oh, it seems it's slightly more serious, as simple override val instead of abstract override val is enough:

trait V[@specialized T] extends I[T] {
    override val fun = m _
}

And simplified whole snippet:

trait I[@specialized T] {
	def fun :T=>T
	def m(value :T) :T
}

trait M[@specialized T] extends I[T]{
	override def fun = m _
}

trait V[@specialized T] extends I[T] {
	override val fun = m _
}

class B[@specialized T] extends I[T] with M[T] with V[T] {
	override def m(value :T) = value
}

class C extends B[Int] {
	override def m(value: Int): Int = value
}

val subject = new B[Int]
println(subject.fun(42))

@scabug scabug added the quickfix label Apr 7, 2017
@SethTisue SethTisue added this to the Backlog milestone Jan 14, 2024
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