Skip to content

Commit

Permalink
More type-safe search for the right Date constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach committed Apr 15, 2022
1 parent b228c4d commit 1252ec0
Showing 1 changed file with 7 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import com.oracle.truffle.api.TruffleLanguage;
import com.oracle.truffle.api.TruffleLanguage.Env;
import com.oracle.truffle.api.TruffleLogger;
import com.oracle.truffle.api.interop.InteropException;
import com.oracle.truffle.api.interop.InteropLibrary;
import com.oracle.truffle.api.nodes.Node;
import org.enso.compiler.Compiler;
import org.enso.compiler.PackageRepository;
Expand Down Expand Up @@ -476,21 +474,14 @@ public long clockTick() {
public Optional<AtomConstructor> getDateConstructor() {
if (date == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
ensureModuleIsLoaded("Standard.Base.Data.Time.Date");
Optional<Module> dateModule = findModule("Standard.Base.Data.Time.Date");
final String stdDateModuleName = "Standard.Base.Data.Time.Date";
final String stdDateConstructorName = "Date";
ensureModuleIsLoaded(stdDateModuleName);
Optional<Module> dateModule = findModule(stdDateModuleName);
if (dateModule.isPresent()) {
try {
InteropLibrary iop = InteropLibrary.getUncached();
Object constrDate = iop.invokeMember(dateModule.get(), "get_constructor", "Date");
if (constrDate instanceof AtomConstructor) {
date = Optional.of((AtomConstructor) constrDate);
}
} catch (InteropException ex) {
throw new IllegalStateException(ex);
}
if (date == null) {
date = Optional.empty();
}
date = Optional.ofNullable(dateModule.get().getScope().getConstructors().get(stdDateConstructorName));
} else {
date = Optional.empty();
}
}
return date;
Expand Down

0 comments on commit 1252ec0

Please sign in to comment.