You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// in file HelloYou.scalaobjectHelloYouextendsApp {
if (args.size ==0)
println("Hello, you")
else
println("Hello, "+ args(0))
}
Compile with scalac HelloYou.scala then run with scala HelloYou Spam
Output
Compilation succeeds, but running scala HelloYou Spam crashes:
CLICK TO EXPAND
➜ scala HelloYou Spam
java.lang.NullPointerException
at java.base/java.lang.reflect.Array.getLength(Native Method)
at scala.collection.ArrayOps$.size$extension(ArrayOps.scala:202)
at Hello$.<clinit>(Hello.scala:2)
at Hello.main(Hello.scala)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at dotty.tools.runner.RichClassLoader$.run$extension$$anonfun$1(ScalaClassLoader.scala:36)
at dotty.tools.runner.ScalaClassLoader$.asContext(ScalaClassLoader.scala:80)
at dotty.tools.runner.RichClassLoader$.dotty$tools$runner$RichClassLoader$$$asContext$extension(ScalaClassLoader.scala:18)
at dotty.tools.runner.RichClassLoader$.run$extension(ScalaClassLoader.scala:36)
at dotty.tools.runner.CommonRunner.run(ObjectRunner.scala:23)
at dotty.tools.runner.CommonRunner.run$(ObjectRunner.scala:13)
at dotty.tools.runner.ObjectRunner$.run(ObjectRunner.scala:48)
at dotty.tools.runner.CommonRunner.runAndCatch(ObjectRunner.scala:30)
at dotty.tools.runner.CommonRunner.runAndCatch$(ObjectRunner.scala:13)
at dotty.tools.runner.ObjectRunner$.runAndCatch(ObjectRunner.scala:48)
at dotty.tools.MainGenericRunner$.run$1(MainGenericRunner.scala:212)
at dotty.tools.MainGenericRunner$.main(MainGenericRunner.scala:267)
at dotty.tools.MainGenericRunner.main(MainGenericRunner.scala)
Expectation
scala HelloYou Spam should work correctly and print Hello, Spam.
Works as expected when compiled and run with Scala 2.
The text was updated successfully, but these errors were encountered:
OK, I also thought that it's probably not a bug, but changed in Scala 3. Weird, it still does compile though! So it's natural to expect it to work.
Just to mention: some newcomers come across these examples in the docs, and they don't know the difference between Scala 2 and 3, or why a piece of code (a Hello world example at that!) straight from the official docs fails. It's not a good look for the language! The docs page starts with Scala 2, and you have to scroll all the way down to see Scala 3.
Just to mention: some newcomers come across these examples in the docs, and they don't know the difference between Scala 2 and 3, or why a piece of code (a Hello world example at that!) straight from the official docs fails. It's not a good look for the language! The docs page starts with Scala 2, and you have to scroll all the way down to see Scala 3.
We definitely hear your concerns so hopefully the situation will begin to improve soon with scala/docs.scala-lang#2430
Uh oh!
There was an error while loading. Please reload this page.
Compiler version
3.1.2
Minimized code
Taken from the docs
Compile with
scalac HelloYou.scala
then run withscala HelloYou Spam
Output
Compilation succeeds, but running
scala HelloYou Spam
crashes:CLICK TO EXPAND
Expectation
scala HelloYou Spam
should work correctly and printHello, Spam
.Works as expected when compiled and run with Scala 2.
The text was updated successfully, but these errors were encountered: