From e9761d2e18a838ba6eccbf4f4c1a36c1c90176b3 Mon Sep 17 00:00:00 2001 From: Dmitry Bushev Date: Tue, 19 Jan 2021 22:04:24 +0300 Subject: [PATCH] Add Null Check when Executing Host Values (#1413) add: extra null check, because isNull doesn't allow null arguments --- .../interop/syntax/HostValueToEnsoNode.java | 2 +- .../test/instrument/RuntimeServerTest.scala | 94 +++++++++++++++++++ 2 files changed, 95 insertions(+), 1 deletion(-) diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/syntax/HostValueToEnsoNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/syntax/HostValueToEnsoNode.java index 20e09d821a06..d07a1b00570c 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/syntax/HostValueToEnsoNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/syntax/HostValueToEnsoNode.java @@ -58,7 +58,7 @@ Text doString(String txt) { return Text.create(txt); } - @Specialization(guards = "nulls.isNull(o)") + @Specialization(guards = {"o != null", "nulls.isNull(o)"}) Atom doNull( Object o, @CachedLibrary(limit = "3") InteropLibrary nulls, diff --git a/engine/runtime/src/test/scala/org/enso/interpreter/test/instrument/RuntimeServerTest.scala b/engine/runtime/src/test/scala/org/enso/interpreter/test/instrument/RuntimeServerTest.scala index 04e47871a629..1aed8eea2faa 100644 --- a/engine/runtime/src/test/scala/org/enso/interpreter/test/instrument/RuntimeServerTest.scala +++ b/engine/runtime/src/test/scala/org/enso/interpreter/test/instrument/RuntimeServerTest.scala @@ -438,6 +438,100 @@ class RuntimeServerTest ) } + it should "push method with default arguments" in { + val contextId = UUID.randomUUID() + val requestId = UUID.randomUUID() + val moduleName = "Test.Main" + + val metadata = new Metadata + val idMain = metadata.addItem(49, 24) + val idMainFoo = metadata.addItem(65, 8) + + val code = + """from Builtins import all + | + |foo a=0 = a + 1 + | + |main = + | IO.println here.foo + |""".stripMargin.linesIterator.mkString("\n") + val contents = metadata.appendToCode(code) + val mainFile = context.writeMain(contents) + + // create context + context.send(Api.Request(requestId, Api.CreateContextRequest(contextId))) + context.receive shouldEqual Some( + Api.Response(requestId, Api.CreateContextResponse(contextId)) + ) + + // open file + context.send( + Api.Request(Api.OpenFileNotification(mainFile, contents, true)) + ) + context.receiveNone shouldEqual None + + // push main + context.send( + Api.Request( + requestId, + Api.PushContextRequest( + contextId, + Api.StackItem.ExplicitCall( + Api.MethodPointer(moduleName, "Test.Main", "main"), + None, + Vector() + ) + ) + ) + ) + context.receive(4) should contain theSameElementsAs Seq( + Api.Response(requestId, Api.PushContextResponse(contextId)), + Api.Response( + Api.ExpressionValuesComputed( + contextId, + Vector( + Api.ExpressionValueUpdate( + idMainFoo, + Some(Constants.INTEGER), + Some(Api.MethodPointer(moduleName, "Test.Main", "foo")), + Vector(ProfilingInfo.ExecutionTime(0)), + false + ) + ) + ) + ), + Api.Response( + Api.ExpressionValuesComputed( + contextId, + Vector( + Api.ExpressionValueUpdate( + idMain, + Some(Constants.NOTHING), + None, + Vector(ProfilingInfo.ExecutionTime(0)), + false + ) + ) + ) + ), + context.executionComplete(contextId) + ) + context.consumeOut shouldEqual List("1") + + // push foo call + context.send( + Api.Request( + requestId, + Api.PushContextRequest(contextId, Api.StackItem.LocalCall(idMainFoo)) + ) + ) + context.receive(2) should contain theSameElementsAs Seq( + Api.Response(requestId, Api.PushContextResponse(contextId)), + context.executionComplete(contextId) + ) + context.consumeOut shouldEqual List("1") + } + it should "send method pointer updates" in { val contextId = UUID.randomUUID() val requestId = UUID.randomUUID()