From f16d07e640c12721eb329a797a19c7b46bbf3fbc Mon Sep 17 00:00:00 2001 From: Jaroslav Tulach Date: Tue, 12 Jul 2022 10:14:53 +0200 Subject: [PATCH] Convert values returned from polyglot calls into Enso Date - when isDate --- .../node/callable/InvokeMethodNode.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/callable/InvokeMethodNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/callable/InvokeMethodNode.java index 50541de4d019..6bb476ed2739 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/callable/InvokeMethodNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/callable/InvokeMethodNode.java @@ -23,6 +23,7 @@ import org.enso.interpreter.runtime.Context; import org.enso.interpreter.runtime.callable.UnresolvedSymbol; import org.enso.interpreter.runtime.callable.argument.CallArgumentInfo; +import org.enso.interpreter.runtime.callable.atom.Atom; import org.enso.interpreter.runtime.callable.function.Function; import org.enso.interpreter.runtime.data.ArrayRope; import org.enso.interpreter.runtime.data.text.Text; @@ -198,6 +199,21 @@ Stateful doPolyglot( } } Object res = hostMethodCallNode.execute(polyglotCallType, symbol.getName(), self, args); + if (!(res instanceof Atom)) { + if (interop.isDate(res)) { + final Context ctx = Context.get(this); + var dateConstructor = ctx.getDateConstructor(); + if (dateConstructor.isPresent()) { + try { + var hostLocalDate = interop.asDate(res); + var guestLocalDate = ctx.getEnvironment().asGuestValue(hostLocalDate); + res = dateConstructor.get().newInstance(guestLocalDate); + } catch (UnsupportedMessageException ex) { + res = dateConstructor.get().newInstance(res); + } + } + } + } if (anyWarnings) { anyWarningsProfile.enter(); res = WithWarnings.prependTo(res, accumulatedWarnings);