Skip to content

Compiler accepts class as non-abstract, then runtime system fails saying the class is abstract #13087

Closed
@jphmrst

Description

@jphmrst

Compiler version

3.0.1

Minimized code

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[_]]:
      NNbuilder[S, T, K, A, DDD[Set[S],T,K[A]], NN[S,T,A,K,?], Unit] =
    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]
}

@main def run: Unit = {
  val builder = NN.newBuilder[String, Char, Int, Set]
  builder += ()
  builder.result()
}

Output (from sbt)

[info] compiling 1 Scala source to /home/jm/Lib/Scala/scratch/target/scala-3.0.1/classes ...
[info] done compiling
[info] running run 
[error] (run-main-56) java.lang.AbstractMethodError: Receiver class NNNbuilder does not define or inherit an implementation of the resolved method 'abstract scala.collection.mutable.Growable addOne(java.lang.Object)' of interface scala.collection.mutable.Growable.
[error] java.lang.AbstractMethodError: Receiver class NNNbuilder does not define or inherit an implementation of the resolved method 'abstract scala.collection.mutable.Growable addOne(java.lang.Object)' of interface scala.collection.mutable.Growable.
[error] 	at scala.collection.mutable.Growable.$plus$eq(Growable.scala:36)
[error] 	at scala.collection.mutable.Growable.$plus$eq$(Growable.scala:36)
[error] 	at AbstractNNNbuilder.$plus$eq(Main.scala:29)
[error] 	at Main$package$.run(Main.scala:45)
[error] 	at run.main(Main.scala:43)
[error] 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[error] 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
[error] 	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[error] 	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
[error] stack trace is suppressed; run last Compile / bgRun for the full output
[error] Nonzero exit code: 1

Expectation

The compiler and RTS should agree that class NNNbuilder is not abstract.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions