Skip to content

Commit

Permalink
Convert values returned from polyglot calls into Enso Date - when isDate
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach committed Jul 12, 2022
1 parent fc2dca2 commit f16d07e
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit f16d07e

Please sign in to comment.