AbstractMethodError when mixing in trait nested in object - only when compiled and imported

自作多情 提交于 2019-12-05 15:51:31

It's clearly a bug.

If you:

java.lang.AbstractMethodError: $line13.$read$$iw$$iw$$iw$$iw$$iw$$iw$$anon$1.foo()I
  ... 33 elided

scala> :javap -p $line13.$read$$iw$$iw$$iw$$iw$$iw$$iw$$anon$1
Compiled from "<console>"
public final class $line13.$read$$iw$$iw$$iw$$iw$$iw$$iw$$anon$1 implements p.Base,p.Impls$ConcreteImpl {
  public java.lang.Object foo();
  public $line13.$read$$iw$$iw$$iw$$iw$$iw$$iw$$anon$1();
}

It doesn't have a foo with result type Int.

Offhand, I can't imagine the difference in the REPL, but we're about to watch a movie... You can try it in Ammonite, however.

Most such bugs are due to the fact that REPL is a resident compiler, but it's not obvious how that affects compilation with existing class files.

Edit:

It works the first time using fully-qualified names, but then after exhibiting the failure, fully-qualified fails again.

scala> (new p.Base with p.Impls.ConcreteImpl).foo // show
//works
res0: Int = 1

scala> import p._
import p._

scala> import Impls._
import Impls._

scala> (new Base with ConcreteImpl).foo // show
// fails
java.lang.AbstractMethodError: $anon$1.foo()I
  ... 33 elided

scala> (new p.Base with p.Impls.ConcreteImpl).foo // show
// also fails
java.lang.AbstractMethodError: $anon$1.foo()I
  ... 33 elided

That's clearly a resident compiler bug. (The classes are in package p here.)

Edit: Actually SI-9689.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!