Skip to content

Compiler accepts a class as non-abstract, then the runtime system fails reporting that class as abstract #12431

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
jphmrst opened this issue Jul 15, 2021 · 4 comments
Labels
fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) runtime crash
Milestone

Comments

@jphmrst
Copy link

jphmrst commented Jul 15, 2021

reproduction steps

using Scala 2.13.6,

import scala.collection.mutable.Builder

class DDD[S,T,A]

trait NN[S, T, A, K[_], +D <: DDD[Set[S],T,K[A]]]
class NNN[S, T, K[_], A] extends NN[S, T, A, K, DDD[Set[S],T,K[A]]]

object NN {
  def newBuilder[S, T, A, K[_]] =
    new NNNbuilder[S, T, K, A]
}

// Remove the type parameter E, hardcoding in E := Unit, and the issue
// goes away.
trait NNbuilder
  [S, T, K[_], A, +D <: DDD[Set[S],T,K[A]], +N <: NN[S,T,A,K,D], E]
    extends Builder[Unit, N] {
  def clear(): Unit = throw new UnsupportedOperationException()
  final def addOne(builder: E): this.type = this
}

// Unfold this class defn, and the issue goes away
abstract class AbstractNNNbuilder
  [S, T, K[_], A, +D <: DDD[Set[S],T,K[A]], +N <: NN[S,T,A,K,D], E]
    extends NNbuilder[S,T,K,A,D,N,E]

class NNNbuilder[S, T, K[_], A] extends AbstractNNNbuilder[
  S, T, K, A, DDD[Set[S], T, K[A]], NNN[S, T, K, A], Unit
] {
  override def result(): NNN[S, T, K, A] = new NNN[S, T, K, A]
}

object Test {
  def main(args: Array[String]): Unit = {
    val builder = NN.newBuilder[String, Char, Int, Set]
    builder += ()
    builder.result()
  }
}

problem

I believe the compiler is correct that the class does not need to be marked abstract; I would it expect it to generate code which the RTS accepts.

See also dotty issue

@jphmrst
Copy link
Author

jphmrst commented Jul 15, 2021

I should add --- the comments refer to things I'd tried in Scala3. I didn't try them here; just reporting the bug here as requested in the dotty ticket.

@joroKr21
Copy link
Member

Related? #8681, #12209, scala/scala3#10079

@SethTisue
Copy link
Member

the error is:

java.lang.AbstractMethodError: Method NNNbuilder.addOne(Ljava/lang/Object;)Lscala/collection/mutable/Growable; is abstract
  at NNNbuilder.addOne(<console>)
  at scala.collection.mutable.Growable.$plus$eq(Growable.scala:36)
  at scala.collection.mutable.Growable.$plus$eq$(Growable.scala:36)
  at AbstractNNNbuilder.$plus$eq(<console>:23)
  at Test$.main(<console>:36)
  ... 32 elided

@SethTisue
Copy link
Member

(Surely this isn't anywhere near minimized...?)

@dwijnand dwijnand added the fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) label Sep 22, 2021
@SethTisue SethTisue added this to the Backlog milestone Sep 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) runtime crash
Projects
None yet
Development

No branches or pull requests

4 participants