-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Members on Atom and Type include inherited methods from Any (#12099)
* Test members on Atom and Type include inherited methods from Any * Add test for consistency between Meta.get_type_methods and interop members on Type. * Type has methods from Any as members * Atom has instance methods from Any as members * Update AtomInteropTest * Update TypeMembersTest * Member names are not qualified * GetTypeMethodsNode delegates to Type.getMethods * Update Meta_Spec test * Fix Locale.predefined_locale_fields * Update Array_Spec test * Fix constants in RuntimeTypesTest * Remove member key size test from ExecCompilerTest * Remove prop size test from DebuggingEnsoTest * Fix constants in RuntimeErrorsTest * Update engine/runtime-integration-tests/src/test/java/org/enso/interpreter/test/interop/AtomInteropTest.java Co-authored-by: Jaroslav Tulach <[email protected]> * Add test for members from Number hierarchy * Include methods from the whole type hierarchy * Collect expected methods * Keep overriden methods. * Type.Invoke member uses InvokeCallableNode * Don't replace instance methods with static methods from eigen type * Add minimal reproducer for failing RUntimeErrorsTest * Add tests for MethodResolverNode * Add MethodInvocationOnTypeConsistencyTest * Add ArgumentMappingTest * Use resolveFunction from InvokeMethodNode * Extract shouldPrependSyntheticSelfArg from InvokeMethodNode * Ignore consistency tests * Methods are found on eigen types * When invoking members on type, the type must be first argument * Add TypeMembersTest.builtinMethodIsPresent * Fix slow context access error * When invoking members on type, the type must be first argument * fmt --------- Co-authored-by: Jaroslav Tulach <[email protected]>
- Loading branch information
1 parent
ba5f651
commit 6790780
Showing
20 changed files
with
1,116 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
155 changes: 155 additions & 0 deletions
155
...ntime-integration-tests/src/test/java/org/enso/interpreter/test/MethodResolutionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
package org.enso.interpreter.test; | ||
|
||
import static org.enso.test.utils.ContextUtils.createDefaultContext; | ||
import static org.enso.test.utils.ContextUtils.evalModule; | ||
import static org.enso.test.utils.ContextUtils.executeInContext; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.hamcrest.Matchers.notNullValue; | ||
|
||
import org.enso.interpreter.Constants.Names; | ||
import org.enso.interpreter.node.callable.resolver.MethodResolverNode; | ||
import org.enso.interpreter.runtime.callable.UnresolvedSymbol; | ||
import org.enso.interpreter.runtime.callable.function.Function; | ||
import org.enso.interpreter.runtime.data.Type; | ||
import org.enso.test.utils.ContextUtils; | ||
import org.graalvm.polyglot.Context; | ||
import org.graalvm.polyglot.Value; | ||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
public final class MethodResolutionTest { | ||
private static MethodResolverNode methodResolverNode; | ||
private static Context ctx; | ||
|
||
@BeforeClass | ||
public static void initCtx() { | ||
ctx = createDefaultContext(); | ||
executeInContext( | ||
ctx, | ||
() -> { | ||
methodResolverNode = MethodResolverNode.getUncached(); | ||
return null; | ||
}); | ||
} | ||
|
||
@AfterClass | ||
public static void disposeCtx() { | ||
ctx.close(); | ||
ctx = null; | ||
} | ||
|
||
@Test | ||
public void resolveStaticMethodFromAny() { | ||
var myTypeVal = | ||
evalModule( | ||
ctx, | ||
""" | ||
from Standard.Base import all | ||
type My_Type | ||
method self = 42 | ||
main = My_Type | ||
"""); | ||
executeInContext( | ||
ctx, | ||
() -> { | ||
var myType = unwrapType(myTypeVal); | ||
var symbol = UnresolvedSymbol.build("to_display_text", myType.getDefinitionScope()); | ||
var func = methodResolverNode.executeResolution(myType, symbol); | ||
assertThat("to_display_text method is found", func, is(notNullValue())); | ||
assertSingleSelfArgument(func); | ||
return null; | ||
}); | ||
} | ||
|
||
@Test | ||
public void resolveInstanceMethodFromMyType() { | ||
var myTypeVal = | ||
evalModule( | ||
ctx, | ||
""" | ||
type My_Type | ||
method self = 42 | ||
main = My_Type | ||
""", | ||
"Module", | ||
"main"); | ||
executeInContext( | ||
ctx, | ||
() -> { | ||
var myType = unwrapType(myTypeVal); | ||
var symbol = UnresolvedSymbol.build("method", myType.getDefinitionScope()); | ||
var func = methodResolverNode.executeResolution(myType, symbol); | ||
assertThat("method is found", func, is(notNullValue())); | ||
assertSingleSelfArgument(func); | ||
return null; | ||
}); | ||
} | ||
|
||
@Test | ||
public void resolveStaticMethodFromMyType() { | ||
var myTypeVal = | ||
evalModule( | ||
ctx, | ||
""" | ||
type My_Type | ||
method = 42 | ||
main = My_Type | ||
""", | ||
"Module", | ||
"main"); | ||
executeInContext( | ||
ctx, | ||
() -> { | ||
var myType = unwrapType(myTypeVal); | ||
var symbol = UnresolvedSymbol.build("method", myType.getDefinitionScope()); | ||
var func = methodResolverNode.executeResolution(myType, symbol); | ||
assertThat("method is found", func, is(notNullValue())); | ||
assertSingleSelfArgument(func); | ||
return null; | ||
}); | ||
} | ||
|
||
@Test | ||
public void resolveExtensionMethodFromMyType() { | ||
var myTypeVal = | ||
evalModule( | ||
ctx, | ||
""" | ||
type My_Type | ||
My_Type.method = 42 | ||
main = My_Type | ||
""", | ||
"Module", | ||
"main"); | ||
executeInContext( | ||
ctx, | ||
() -> { | ||
var myType = unwrapType(myTypeVal); | ||
var symbol = UnresolvedSymbol.build("method", myType.getDefinitionScope()); | ||
var func = methodResolverNode.executeResolution(myType, symbol); | ||
assertThat("method is found", func, is(notNullValue())); | ||
assertSingleSelfArgument(func); | ||
return null; | ||
}); | ||
} | ||
|
||
private void assertSingleSelfArgument(Function func) { | ||
assertThat("Has single self argument", func.getSchema().getArgumentsCount(), is(1)); | ||
assertThat( | ||
"Has single self argument", | ||
func.getSchema().getArgumentInfos()[0].getName(), | ||
is(Names.SELF_ARGUMENT)); | ||
} | ||
|
||
private Type unwrapType(Value val) { | ||
var unwrapped = ContextUtils.unwrapValue(ctx, val); | ||
return (Type) unwrapped; | ||
} | ||
} |
Oops, something went wrong.