When compiling a willingly faulty Scala code implying a missing open
modifier, my compiler doesn't notify any warning or error. This seems to contradict this line in the Scala book :
In Scala 3 extending non-abstract classes in other files is restricted. In order to allow this, the base class needs to be marked as open
Here is my code :
animal.scala
package animal:
class Animal(name: String, specie: String):
override def toString: String = s"$name of specie $specie"
def doNoise: Unit = println("I could be anyone, really.")
cat.scala
import animal.Animal
class Cat(name: String) extends Animal(name, "cat"):
override def doNoise: Unit = println("Meow.")
@main def run(): Unit =
val c = Cat("felix")
println(c)
c.doNoise
I'm running scalac *.scala
to compile all of that which runs just fine even though Cat
and Animal
are not defined in the same file and Animal
is not marked as open
. Am I missing something ?
Thanks in advance for your help :)
P.S.
When I type scala
in my command line, i'm greeted with Welcome to Scala 3.4.2
.
From Odersky himself:
it should arrive in 3.6, later this year. It is already enabled under
-source future
.