File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed
main/scala/org/scijava/plugins/scripting/scala
test/java/org/scijava/plugins/scripting/scala Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,13 @@ class ScalaAdaptedScriptEngine(engine: ScriptEngine) extends AbstractScriptEngin
2525 @ throws[ScriptException ]
2626 override def eval (script : String , context : ScriptContext ): AnyRef =
2727 emulateBinding(context)
28- evalInner(script, context)
28+ val r = evalInner(script, context)
29+ // Scala returns `Unit` when no value is returned. Script Engine (or the
30+ // Java side) expects `null` when no value was returned.
31+ // Anything else return as is.
32+ r match
33+ case _ : Unit => null
34+ case x => x
2935
3036 private def emulateBinding (context : ScriptContext ): Unit =
3137
Original file line number Diff line number Diff line change @@ -74,6 +74,17 @@ public void testBasic() throws Exception {
7474 }
7575 }
7676
77+ @ Test
78+ public void testEmptyReturnValue () throws Exception {
79+ try (final Context context = new Context (ScriptService .class )) {
80+ final ScriptService scriptService = context .getService (ScriptService .class );
81+ final ScriptModule m = scriptService .run ("hello.scala" , "print(\" 3\" )" , true ).get ();
82+ final Void expected = null ;
83+ final Object actual = m .getReturnValue ();
84+ assertEquals (expected , actual );
85+ }
86+ }
87+
7788 @ Test
7889 public void testPutDouble () throws Exception {
7990 try (final Context context = new Context (ScriptService .class )) {
You can’t perform that action at this time.
0 commit comments