Skip to content

Commit

Permalink
Search constructors when resolving UnresolvedSymbol
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach committed Dec 29, 2023
1 parent 27431c1 commit 23bc507
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.enso.interpreter.runtime.EnsoContext;
import org.enso.interpreter.runtime.callable.Annotation;
import org.enso.interpreter.runtime.callable.UnresolvedConversion;
import org.enso.interpreter.runtime.callable.UnresolvedSymbol;
import org.enso.interpreter.runtime.callable.argument.ArgumentDefinition;
import org.enso.interpreter.runtime.callable.argument.ArgumentDefinition.ExecutionMode;
import org.enso.interpreter.runtime.callable.argument.CallArgument;
Expand Down Expand Up @@ -238,7 +239,7 @@ String expectedTypeMessage() {
}

abstract static class TypeCheckNode extends ReadArgumentCheckNode {
private final Type expectedType;
final Type expectedType;
@Child IsValueOfTypeNode checkType;
@CompilerDirectives.CompilationFinal private String expectedTypeMessage;
@CompilerDirectives.CompilationFinal private LazyCheckRootNode lazyCheck;
Expand All @@ -254,6 +255,19 @@ Object doPanicSentinel(VirtualFrame frame, PanicSentinel panicSentinel) {
throw panicSentinel;
}

@Specialization(guards = "found != null")
Object doUnresolvedSymbol(
VirtualFrame frame,
UnresolvedSymbol symbol,
@Cached(neverDefault = false, value = "symbol.resolveFor(this, expectedType)")
Pair<Function, Type> found) {
if (found.getLeft().isFullyApplied()) {
return found.getLeft();
} else {
throw panicAtTheEnd(found.getLeft());
}
}

@Specialization(rewriteOn = InvalidAssumptionException.class)
Object doCheckNoConversionNeeded(VirtualFrame frame, Object v)
throws InvalidAssumptionException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ public Function lookupMethodDefinition(Type type, String name) {
return definedHere.get();
}

var constructedHere = type.getConstructors().get(name);
if (constructedHere != null) {
return constructedHere.getConstructorFunction();
}

return imports.stream()
.map(scope -> scope.getExportedMethod(type, name))
.filter(Objects::nonNull)
Expand Down

0 comments on commit 23bc507

Please sign in to comment.