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

AbstractMethodError when inheriting trait from java abstract class and referencing val from the trait #12456

Open
unkarjedy opened this issue Sep 7, 2021 · 5 comments
Milestone

Comments

@unkarjedy
Copy link

unkarjedy commented Sep 7, 2021

reproduction steps

using Scala (2.13.6),

trait ScalaTrait {
  def foo1: String
  def foo2: String = "default foo value 2"

  val val1: String
  val val2: String = "default val value 2"
}
public abstract class JavaAbstractClass implements ScalaTrait {
    public String javaFoo1() { return foo1(); }
    public String javaFoo2() { return foo2(); }

    public String javaVal1() { return val1(); }
    public String javaVal2() { return val2(); }
}
import scala.util.Try

object ScalaClass extends JavaAbstractClass {
  override def foo1: String = "implemented foo in scala 1"
  override val val1: String = "implemented val in scala 1"

  def main(args: Array[String]): Unit = {
    println(Try(javaFoo1()))
    println(Try(javaFoo2()))

    println(Try(javaVal1()))
    println(Try(javaVal2()))
  }
}

problem

The program compiles fine, but an exception is thrown at runtime:

Success(implemented foo in scala 1)
Success(default foo value 2)
Success(implemented val in scala 1)
Exception in thread "main" java.lang.AbstractMethodError: Method ScalaClass$.val2()Ljava/lang/String; is abstract
	at ScalaClass$.val2(ScalaClass.scala)
	at JavaAbstractClass.javaVal2(JavaAbstractClass.java:6)
	at ScalaClass$.$anonfun$main$4(ScalaClass.scala:12)
	at scala.util.Try$.apply(Try.scala:210)
	at ScalaClass$.main(ScalaClass.scala:12)
	at ScalaClass.main(ScalaClass.scala)

Expected result:

whether compilation failure or no runtime error

NOTE: I have to use an intermediate java class in my Scala classes hierarchy to workaround some other compiler issues.

@unkarjedy
Copy link
Author

similar issues:
#10534
#12224

@lrytz
Copy link
Member

lrytz commented Sep 8, 2021

Same in Scala 3.

These are valid issued, but I'm not sure if they will be considered high priority by core contributors any time soon.

NOTE: I have to use an intermediate java class in my Scala classes hierarchy to workaround some other compiler issues.

This sounds more important - is there a ticket for that?

@unkarjedy
Copy link
Author

unkarjedy commented Sep 8, 2021

is there a ticket for that

I am not sure, it's hard to create a minimal reproducible example.
It is mainly related to Kotlin interop.
We have some piece of library code, which is written in Kotlin and I didn't manage to use it in Scala.
Sometimes scala compiler can't resolve an overloaded method from Kotlin which uses extensions as parameters (when Java can).
Sometimes it tails with

java.lang.StackOverflowError
	at scala.reflect.internal.tpe.TypeMaps$SubstMap.apply(TypeMaps.scala:754)
	at scala.reflect.internal.tpe.TypeMaps$SubstSymMap.apply(TypeMaps.scala:820)
	at scala.reflect.internal.Types$TypeRef.mapOver(Types.scala:2371)
	at scala.reflect.internal.tpe.TypeMaps$SubstMap.apply(TypeMaps.scala:754)
	at scala.reflect.internal.tpe.TypeMaps$SubstSymMap.apply(TypeMaps.scala:820)
	at scala.reflect.internal.Types$TypeBounds.mapOver(Types.scala:1592)
	at scala.reflect.internal.tpe.TypeMaps$SubstMap.apply(TypeMaps.scala:754)
	at scala.reflect.internal.tpe.TypeMaps$SubstSymMap.apply(TypeMaps.scala:820)
	at scala.reflect.internal.tpe.TypeMaps$SubstSymMap.apply(TypeMaps.scala:788)
	at scala.reflect.internal.Symbols$Symbol.modifyInfo(Symbols.scala:1594)
	at scala.reflect.internal.Symbols.$anonfun$cloneSymbols$2(Symbols.scala:3770)
	at scala.reflect.internal.Symbols.cloneSymbols(Symbols.scala:3768)
	at scala.reflect.internal.Symbols.cloneSymbols$(Symbols.scala:3764)
	at scala.reflect.internal.SymbolTable.cloneSymbols(SymbolTable.scala:28)
	at scala.reflect.internal.tpe.TypeMaps$TypeMap.mapOver(TypeMaps.scala:140)
	at scala.reflect.internal.Types$ExistentialType.mapOver(Types.scala:3225)
	at scala.reflect.internal.tpe.TypeMaps$SubstMap.apply(TypeMaps.scala:754)
	at scala.reflect.internal.tpe.TypeMaps$SubstMap.apply(TypeMaps.scala:667)
	at scala.reflect.internal.Types$TypeRef.mapOver(Types.scala:2380)
	at scala.reflect.internal.tpe.TypeMaps$SubstMap.apply(TypeMaps.scala:754)
	at scala.reflect.internal.Types$Type.subst(Types.scala:747)
	at scala.reflect.internal.Types$Type.instantiateTypeParams(Types.scala:493)
	at scala.reflect.internal.Types$TypeRef.seenFromOwnerInstantiated$1(Types.scala:2499)
	at scala.reflect.internal.Types$TypeRef.relativize(Types.scala:2503)
	at scala.reflect.internal.Types$TypeRef.$anonfun$baseTypeSeqImpl$2(Types.scala:2629)
	at scala.reflect.internal.BaseTypeSeqs$BaseTypeSeq.map(BaseTypeSeqs.scala:157)
	at scala.reflect.internal.Types$TypeRef.baseTypeSeqImpl(Types.scala:2629)
	at scala.reflect.internal.Types.defineBaseTypeSeqOfTypeRef(Types.scala:2803)
	at scala.reflect.internal.Types.defineBaseTypeSeqOfTypeRef$(Types.scala:2794)
	at scala.reflect.internal.SymbolTable.defineBaseTypeSeqOfTypeRef(SymbolTable.scala:28)
	at scala.reflect.internal.Types$TypeRef.baseTypeSeq(Types.scala:2636)
	at scala.tools.nsc.typechecker.Implicits$ImplicitSearch.getClassParts$1(Implicits.scala:1348)
	at scala.tools.nsc.typechecker.Implicits$ImplicitSearch.getParts$1(Implicits.scala:1378)
	at scala.tools.nsc.typechecker.Implicits$ImplicitSearch.$anonfun$companionImplicitMap$12(Implicits.scala:1379)
	at scala.tools.nsc.typechecker.Implicits$ImplicitSearch.getParts$1(Implicits.scala:1379)
	at scala.tools.nsc.typechecker.Implicits$ImplicitSearch.getClassParts$1(Implicits.scala:1351)
	at scala.tools.nsc.typechecker.Implicits$ImplicitSearch.getParts$1(Implicits.scala:1378)
	at scala.tools.nsc.typechecker.Implicits$ImplicitSearch.$anonfun$companionImplicitMap$12(Implicits.scala:1379)
	at scala.tools.nsc.typechecker.Implicits$ImplicitSearch.getParts$1(Implicits.scala:1379)
	at scala.tools.nsc.typechecker.Implicits$ImplicitSearch.getClassParts$1(Implicits.scala:1351)
	at scala.tools.nsc.typechecker.Implicits$ImplicitSearch.getParts$1(Implicits.scala:1378)

I don't think that it's worth reporting, taking into account that many Java-interop issues are not considered high priority.

@unkarjedy
Copy link
Author

unkarjedy commented Sep 8, 2021

looks like the exception is from #11775

@jxnu-liguobin

This comment was marked as outdated.

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

No branches or pull requests

4 participants