diff --git a/engine/runtime-compiler/src/main/java/org/enso/compiler/context/MethodResolutionAlgorithm.java b/engine/runtime-compiler/src/main/java/org/enso/compiler/context/MethodResolutionAlgorithm.java
index c1f25ccc248f..5d886424e600 100644
--- a/engine/runtime-compiler/src/main/java/org/enso/compiler/context/MethodResolutionAlgorithm.java
+++ b/engine/runtime-compiler/src/main/java/org/enso/compiler/context/MethodResolutionAlgorithm.java
@@ -11,8 +11,7 @@
*
* - in the runtime ({@link
* org.enso.interpreter.runtime.scope.ModuleScope#lookupMethodDefinition}),
- *
- in the type checker ({@link
- * org.enso.compiler.pass.analyse.types.MethodTypeResolver#lookupMethodDefinition}).
+ *
- in the type checker ({@link org.enso.compiler.pass.analyse.types.MethodTypeResolver}).
*
*
* To ensure that all usages stay consistent, they should all rely on the logic implemented in
diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/scope/ModuleScope.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/scope/ModuleScope.java
index 8cfeb1837a2d..91400a4502d9 100644
--- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/scope/ModuleScope.java
+++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/scope/ModuleScope.java
@@ -7,7 +7,9 @@
import java.util.*;
import java.util.function.Supplier;
import java.util.stream.Collectors;
+import org.enso.compiler.context.CommonModuleScopeShape;
import org.enso.compiler.context.CompilerContext;
+import org.enso.compiler.context.MethodResolutionAlgorithm;
import org.enso.interpreter.runtime.EnsoContext;
import org.enso.interpreter.runtime.Module;
import org.enso.interpreter.runtime.callable.function.Function;
@@ -20,7 +22,8 @@
/** A representation of Enso's per-file top-level scope. */
@ExportLibrary(TypesLibrary.class)
-public final class ModuleScope implements EnsoObject {
+public final class ModuleScope
+ implements EnsoObject, CommonModuleScopeShape {
private final Type associatedType;
private final Module module;
private final Map> polyglotSymbols;
@@ -88,21 +91,40 @@ public Module getModule() {
*/
@CompilerDirectives.TruffleBoundary
public Function lookupMethodDefinition(Type type, String name) {
- var definedWithAtom = type.getDefinitionScope().getMethodForType(type, name);
- if (definedWithAtom != null) {
- return definedWithAtom;
+ return methodResolutionAlgorithm.lookupMethodDefinition(type, name);
+ }
+
+ private final RuntimeMethodResolution methodResolutionAlgorithm = new RuntimeMethodResolution();
+
+ private class RuntimeMethodResolution
+ extends MethodResolutionAlgorithm {
+ @Override
+ protected ModuleScope findDefinitionScope(Type type) {
+ return type.getDefinitionScope();
}
- var definedHere = getMethodForType(type, name);
- if (definedHere != null) {
- return definedHere;
+ @Override
+ protected ModuleScope getCurrentModuleScope() {
+ return ModuleScope.this;
}
- return imports.stream()
- .map(scope -> scope.getExportedMethod(type, name))
- .filter(Objects::nonNull)
- .findFirst()
- .orElse(null);
+ @Override
+ protected Function findExportedMethodInImportScope(
+ ImportExportScope importExportScope, Type type, String methodName) {
+ return importExportScope.getExportedMethod(type, methodName);
+ }
+
+ @Override
+ protected Function onMultipleDefinitionsFromImports(
+ String methodName, List> methodFromImports) {
+ assert !methodFromImports.isEmpty();
+ return methodFromImports.get(0).resolvedType();
+ }
+ }
+
+ @Override
+ public Collection getImports() {
+ return imports;
}
/**