diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/EqualsComplexNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/EqualsComplexNode.java index 845fb9cfd5..50a4cdd231 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/EqualsComplexNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/EqualsComplexNode.java @@ -1,5 +1,22 @@ package org.enso.interpreter.node.expression.builtin.meta; +import java.time.LocalDateTime; +import java.time.ZonedDateTime; + +import org.enso.interpreter.dsl.AcceptsError; +import org.enso.interpreter.node.expression.builtin.interop.syntax.HostValueToEnsoNode; +import org.enso.interpreter.node.expression.builtin.ordering.CustomComparatorNode; +import org.enso.interpreter.runtime.EnsoContext; +import org.enso.interpreter.runtime.Module; +import org.enso.interpreter.runtime.callable.UnresolvedConversion; +import org.enso.interpreter.runtime.callable.UnresolvedSymbol; +import org.enso.interpreter.runtime.callable.atom.Atom; +import org.enso.interpreter.runtime.data.EnsoFile; +import org.enso.interpreter.runtime.data.Type; +import org.enso.interpreter.runtime.error.WarningsLibrary; +import org.enso.interpreter.runtime.library.dispatch.TypesLibrary; +import org.enso.interpreter.runtime.scope.ModuleScope; + import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.GenerateUncached; @@ -14,21 +31,6 @@ import com.oracle.truffle.api.interop.UnsupportedMessageException; import com.oracle.truffle.api.interop.UnsupportedTypeException; import com.oracle.truffle.api.library.CachedLibrary; import com.oracle.truffle.api.nodes.Node; -import java.time.LocalDateTime; -import java.time.ZonedDateTime; -import org.enso.interpreter.dsl.AcceptsError; -import org.enso.interpreter.node.expression.builtin.interop.syntax.HostValueToEnsoNode; -import org.enso.interpreter.node.expression.builtin.ordering.CustomComparatorNode; -import org.enso.interpreter.runtime.EnsoContext; -import org.enso.interpreter.runtime.Module; -import org.enso.interpreter.runtime.callable.UnresolvedConversion; -import org.enso.interpreter.runtime.callable.UnresolvedSymbol; -import org.enso.interpreter.runtime.callable.atom.Atom; -import org.enso.interpreter.runtime.data.EnsoFile; -import org.enso.interpreter.runtime.data.Type; -import org.enso.interpreter.runtime.error.WarningsLibrary; -import org.enso.interpreter.runtime.library.dispatch.TypesLibrary; -import org.enso.interpreter.runtime.scope.ModuleScope; @GenerateUncached public abstract class EqualsComplexNode extends Node { @@ -316,6 +318,7 @@ public abstract class EqualsComplexNode extends Node { @CachedLibrary("otherHashMap") InteropLibrary otherInterop, @CachedLibrary(limit = "5") InteropLibrary entriesInterop, @Cached EqualsNode equalsNode, + @Cached HostValueToEnsoNode keyToEnsoNode, @Cached HostValueToEnsoNode valueToEnsoNode) { try { int selfHashSize = (int) selfInterop.getHashSize(selfHashMap); @@ -326,7 +329,7 @@ public abstract class EqualsComplexNode extends Node { Object selfEntriesIter = selfInterop.getHashEntriesIterator(selfHashMap); while (entriesInterop.hasIteratorNextElement(selfEntriesIter)) { Object selfKeyValue = entriesInterop.getIteratorNextElement(selfEntriesIter); - Object key = entriesInterop.readArrayElement(selfKeyValue, 0); + Object key = keyToEnsoNode.execute(entriesInterop.readArrayElement(selfKeyValue, 0)); Object selfValue = valueToEnsoNode.execute(entriesInterop.readArrayElement(selfKeyValue, 1)); if (otherInterop.isHashEntryExisting(otherHashMap, key) diff --git a/engine/runtime/src/test/java/org/enso/interpreter/test/HashCodeTest.java b/engine/runtime/src/test/java/org/enso/interpreter/test/HashCodeTest.java index c82099c95d..102fe13ef8 100644 --- a/engine/runtime/src/test/java/org/enso/interpreter/test/HashCodeTest.java +++ b/engine/runtime/src/test/java/org/enso/interpreter/test/HashCodeTest.java @@ -1,13 +1,9 @@ package org.enso.interpreter.test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import com.oracle.truffle.api.interop.InteropLibrary; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; + import org.enso.interpreter.node.expression.builtin.interop.syntax.HostValueToEnsoNode; import org.enso.interpreter.node.expression.builtin.meta.EqualsNode; import org.enso.interpreter.node.expression.builtin.meta.HashCodeNode; @@ -16,13 +12,16 @@ import org.enso.interpreter.runtime.EnsoContext; import org.graalvm.polyglot.Context; import org.graalvm.polyglot.Value; import org.junit.AfterClass; -import org.junit.Before; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import org.junit.BeforeClass; import org.junit.experimental.theories.DataPoints; import org.junit.experimental.theories.Theories; import org.junit.experimental.theories.Theory; import org.junit.runner.RunWith; +import com.oracle.truffle.api.interop.InteropLibrary; + @RunWith(Theories.class) public class HashCodeTest extends TestBase { private static Context context; diff --git a/engine/runtime/src/test/java/org/enso/interpreter/test/ValuesGenerator.java b/engine/runtime/src/test/java/org/enso/interpreter/test/ValuesGenerator.java index 1c49bfdcb7..fd002f64f4 100644 --- a/engine/runtime/src/test/java/org/enso/interpreter/test/ValuesGenerator.java +++ b/engine/runtime/src/test/java/org/enso/interpreter/test/ValuesGenerator.java @@ -13,6 +13,7 @@ import java.time.ZoneOffset; import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.EnumSet; import java.util.HashMap; import java.util.List; @@ -577,6 +578,15 @@ class ValuesGenerator { collect.add(v("maps-" + expr, imports, expr, "Map").type()); } } + if (languages.contains(Language.JAVA)) { + collect.add(ctx.asValue(Collections.emptyMap())); + collect.add(ctx.asValue(Collections.singletonMap("A", 1))); + var map = new HashMap(); + map.put("A", 1); + map.put("B", 2); + map.put("C", 3); + collect.add(ctx.asValue(map)); + } return collect; }