Open
Description
reproduction steps
using Scala 2.13.2, when defining a class in the REPL, no default constructor is generated. Instead there is only the constructor which expects the reference to the surrounding object.
Welcome to Scala 2.13.2 (OpenJDK 64-Bit Server VM, Java 13.0.1).
Type in expressions for evaluation. Or try :help.
scala> class A
class A
scala> classOf[A].getConstructors()
val res2: Array[java.lang.reflect.Constructor[_]] = Array(public A($iw))
This was different in 2.13.1:
Welcome to Scala 2.13.1 (OpenJDK 64-Bit Server VM, Java 13.0.1).
Type in expressions for evaluation. Or try :help.
scala> class A
defined class A
scala> classOf[A].getConstructors()
res0: Array[java.lang.reflect.Constructor[_]] = Array(public A())
problem
I used to show akka examples in the repl for a course I am teaching. With Scala 2.13.2 it does not work anymore. I guess Props[PrintActor]
searches for the zero argument constructor of PrintActor
to create an instance - and can not find it.
Welcome to Scala 2.13.2 (OpenJDK 64-Bit Server VM, Java 13.0.1).
Type in expressions for evaluation. Or try :help.
scala> import akka.actor._
import akka.actor._
scala> val as = ActorSystem("as")
val as: akka.actor.ActorSystem = akka://as
scala> class PrintActor extends Actor {
| def receive = { case msg: Int => println(msg) }
| }
class PrintActor
scala> val printActor: ActorRef = as.actorOf(Props[PrintActor])
java.lang.IllegalArgumentException: no matching constructor found on class PrintActor for arguments []
at akka.util.Reflect$.error$1(Reflect.scala:86)
at akka.util.Reflect$.findConstructor(Reflect.scala:110)
... 37 elided
The example above works as expected with Scala 2.13.1.
Random note: -Yrepl-class-based
does not help.