diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Any.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Any.enso index 6c067ab49328..1b88baa07f34 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Any.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Any.enso @@ -108,8 +108,8 @@ type Any == self that = # If there is No_Such_Conversion, then `self` and `that` are probably # host or polyglot values, so we just compare them with the default comparator. - eq_self = Panic.catch No_Such_Conversion (Comparable.from self) _-> Default_Comparator - eq_that = Panic.catch No_Such_Conversion (Comparable.from that) _-> Default_Comparator + eq_self = Comparable.from self + eq_that = Comparable.from that similar_type = Meta.is_same_object eq_self eq_that case similar_type of False -> False diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/callable/InvokeConversionNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/callable/InvokeConversionNode.java index 870dad08a70a..6af3ce73ee8d 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/callable/InvokeConversionNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/callable/InvokeConversionNode.java @@ -343,10 +343,18 @@ Object doFallback( Object that, Object[] arguments, @CachedLibrary(limit = "10") TypesLibrary methods, - @CachedLibrary(limit = "10") InteropLibrary interop) { - throw new PanicException( - EnsoContext.get(this).getBuiltins().error().makeNoSuchConversion(self, that, conversion), - this); + @CachedLibrary(limit = "10") InteropLibrary interop, + @Cached ConversionResolverNode conversionResolverNode) { + var ctx = EnsoContext.get(this); + var function = + conversionResolverNode.execute( + extractConstructor(self), ctx.getBuiltins().any(), conversion); + if (function == null) { + throw new PanicException( + ctx.getBuiltins().error().makeNoSuchConversion(self, that, conversion), this); + } else { + return invokeFunctionNode.execute(function, frame, state, arguments); + } } @Override diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/callable/resolver/ConversionResolverNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/callable/resolver/ConversionResolverNode.java index ca3c578cf303..5f15af18cc37 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/callable/resolver/ConversionResolverNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/callable/resolver/ConversionResolverNode.java @@ -60,6 +60,7 @@ Function resolveCached( @Specialization(replaces = "resolveCached") @CompilerDirectives.TruffleBoundary Function resolveUncached(Type target, Type self, UnresolvedConversion conversion) { - return conversion.resolveFor(target, self); + var ctx = EnsoContext.get(this); + return conversion.resolveFor(ctx, target, self); } } diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/callable/UnresolvedConversion.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/callable/UnresolvedConversion.java index 3c7c1bfefcb9..66212c1dbe7d 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/callable/UnresolvedConversion.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/callable/UnresolvedConversion.java @@ -42,7 +42,7 @@ public ModuleScope getScope() { * * @return the resolved function definition, or null if not found */ - public Function resolveFor(Type into, Type from) { + public Function resolveFor(EnsoContext ctx, Type into, Type from) { Type current = from; while (current != null) { Function candidate = scope.lookupConversionDefinition(current, into); @@ -52,7 +52,7 @@ public Function resolveFor(Type into, Type from) { current = current.getSupertype(); } } - return null; + return scope.lookupConversionDefinition(ctx.getBuiltins().any(), into); } @Override diff --git a/test/Tests/src/Semantic/Conversion_Spec.enso b/test/Tests/src/Semantic/Conversion_Spec.enso index 39327fc7a3ba..885032c1d760 100644 --- a/test/Tests/src/Semantic/Conversion_Spec.enso +++ b/test/Tests/src/Semantic/Conversion_Spec.enso @@ -3,9 +3,11 @@ from Standard.Base import all import project.Semantic.Conversion.Methods import project.Semantic.Conversion.Types -from Standard.Test import Test +from Standard.Test import Test, Test_Suite import Standard.Test.Extensions +polyglot java import java.lang.Object + type Foo Value foo type Bar @@ -70,6 +72,11 @@ spec = Not_Foo.from 4 . notfoo . should_equal "ANY!!!" Not_Foo.from (e -> e) . notfoo . should_equal "ANY!!!" Not_Foo.from [1,2,3].to_array . notfoo . should_equal "ANY!!!" + Not_Foo.from [1,2,3] . notfoo . should_equal "ANY!!!" + Test.specify "apply Any conversion to foreign object" <| + Not_Foo.from Object.new . notfoo . should_equal "ANY!!!" + Test.specify "apply Any conversion to type" <| + Not_Foo.from Boolean . notfoo . should_equal "ANY!!!" Test.specify "should call intrinsic object conversions for unimported constructors" <| Vector.from Methods.get_foo . should_equal ["foo"] Test.specify "should call extension conversions" <| @@ -104,3 +111,5 @@ spec = meta_from.rename "foo" 123 . should_equal "foo called" meta_from.rename "foo" . should_equal .foo + +main = Test_Suite.run_main spec