Skip to content

AbstractMethodError when base class method overloads generic method from trait #8681

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

Open
scabug opened this issue Jun 25, 2014 · 5 comments
Labels
backend erasure fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)
Milestone

Comments

@scabug
Copy link

scabug commented Jun 25, 2014

Repro steps:

Welcome to Scala version 2.10.3 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_25).
Type in expressions to have them evaluated.
Type :help for more information.

scala> :paste
// Entering paste mode (ctrl-D to finish)

trait SimpleTrait[T] {
  def myMethod(t: T): Int
  def doIt(t: T): Unit = {
    myMethod(t)
 }
}

abstract class SimpleClass[T] extends SimpleTrait[T] {
  def myMethod(t: String): Int = 5
}

class BadClass extends SimpleClass[String]

(new BadClass).doIt("foobar")

// Exiting paste mode, now interpreting.

java.lang.AbstractMethodError: BadClass.myMethod(Ljava/lang/Object;)I
	at SimpleTrait$class.doIt(<console>:13)
	at SimpleClass.doIt(<console>:17)
...
@scabug
Copy link
Author

scabug commented Jun 25, 2014

Imported From: https://issues.scala-lang.org/browse/SI-8681?orig=1
Reporter: Jason Liszka (jliszka)
Affected Versions: 2.10.3, 2.11.1

@scabug
Copy link
Author

scabug commented Jun 26, 2014

@retronym said (edited on Jun 26, 2014 7:58:07 AM UTC):
The analagous Java code compiles and runs successfully. Crucially, a bridge method is added to BadClass.

public class Test {
	interface SimpleTrait<T> {
	  int myMethod(T t);
	  default void doIt(T t) {
	    myMethod(t);
	  }
	}

	static abstract class SimpleClass<T> implements SimpleTrait<T> {
	  public int myMethod(String t) { return 5; }
	}

	static class BadClass extends SimpleClass<String> {}

	
	public static void main(String... args) {
		new BadClass().doIt("");
	}
}
% javap -v -classpath . 'Test$BadClass'
...
  public int myMethod(java.lang.Object);
    descriptor: (Ljava/lang/Object;)I
    flags: ACC_PUBLIC, ACC_BRIDGE, ACC_SYNTHETIC
    Code:
      stack=2, locals=2, args_size=2
         0: aload_0
         1: aload_1
         2: checkcast     #2                  // class java/lang/String
         5: invokespecial #3                  // Method Test$SimpleClass.myMethod:(Ljava/lang/String;)I
         8: ireturn
      LineNumberTable:
        line 13: 0

@SethTisue
Copy link
Member

same in 2.12.4

@SethTisue
Copy link
Member

Not fixed in Scala 2.13.5, and not fixed in Scala 3.0.0-RC1 either.

@joroKr21
Copy link
Member

Possibly related to #12209 and scala/scala3#10079 see for another case where variance causes confusion of this kind. I think it's a conceptual problem - we check for overriding pairs on method definition but both this and the ticket I linked show that we may have to do it also in subclasses. But I can't tell if that is practical.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend erasure fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)
Projects
None yet
Development

No branches or pull requests

5 participants