Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always try to resolve conversion for Any type #6184

Merged
merged 4 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Any.enso
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -52,7 +52,7 @@ public Function resolveFor(Type into, Type from) {
current = current.getSupertype();
}
}
return null;
return scope.lookupConversionDefinition(ctx.getBuiltins().any(), into);
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
Expand Down