Skip to content

Commit

Permalink
Add Null Check when Executing Host Values (#1413)
Browse files Browse the repository at this point in the history
add: extra null check, because isNull doesn't allow
null arguments
  • Loading branch information
4e6 authored and iamrecursion committed Feb 10, 2021
1 parent 13c6609 commit b549f34
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit b549f34

Please sign in to comment.