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
@main deftest():Unit= {
varx:String|Null=null
x =""vari:Int=1try {
i match {
case _ => {
x =nullthrownewException()
}
}
x =""
}
catch {
case (e: Exception) => {}
}
x.replace("", "")
}
Output
Compiling the program with -Yexplicit-nulls results in the following error at runtime
java.lang.NullPointerException:Cannot invoke "String.replace(java.lang.CharSequence, java.lang.CharSequence)" because "x" is null
at test$package$.test(test.scala:17)
at test.main(test.scala:1)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
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:215)
at dotty.tools.MainGenericRunner$.process(MainGenericRunner.scala:270)
at dotty.tools.MainGenericRunner$.main(MainGenericRunner.scala:281)
at dotty.tools.MainGenericRunner.main(MainGenericRunner.scala)
Expectation
The program should have been rejected.
The text was updated successfully, but these errors were encountered:
Compiler version
3.6.0-RC1-bin-SNAPSHOT-git-e9d4831
Minimized code
Related to #21380
Output
Compiling the program with
-Yexplicit-nulls
results in the following error at runtimeExpectation
The program should have been rejected.
The text was updated successfully, but these errors were encountered: