Skip to content

scala must not exit with 0 if the program threw an uncaught exception #15022

Closed
@sevaseva

Description

@sevaseva

Compiler version

3.1.0, 3.1.1, 3.1.2 as well as the tip of the main branch at the time of writing this.

On the other hand, this isn't affecting scala 2.13.4 (verified) and many/all other 2.x versions.

Minimized code

object Main {
    def main(args: Array[String]) = {
    	throw new RuntimeException()
   }
}

More concretely, in bash shell after building scala into scala3-3.2.0-RC1-bin-SNAPSHOT (with bin and lib in there):

scala3-3.2.0-RC1-bin-SNAPSHOT$ export SCALA_HOME=$(pwd)

scala3-3.2.0-RC1-bin-SNAPSHOT$ cat > a.scala << EOF
object Main {
    def main(args: Array[String]) = {
    	throw new RuntimeException()
   }
}
EOF

scala3-3.2.0-RC1-bin-SNAPSHOT$ cat a.scala
object Main {
    def main(args: Array[String]) = {
    	throw new RuntimeException()
   }
}

scala3-3.2.0-RC1-bin-SNAPSHOT$ bin/scalac a.scala

scala3-3.2.0-RC1-bin-SNAPSHOT$ bin/scala Main
java.lang.RuntimeException
	at Main$.main(a.scala:3)
	at Main.main(a.scala)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	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)

scala3-3.2.0-RC1-bin-SNAPSHOT$ echo $?
0

Output

That last output of 0 is the issue.

Expectation

The last command echo $? must print 1 or some other non-zero.
scala 2.13.4 does that.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions