Skip to content

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

Open
@jphmrst

Description

@jphmrst

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixed in Scala 3This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)runtime crash

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions