-
Notifications
You must be signed in to change notification settings - Fork 323
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
Check types of lazy (constructor) arguments #6883
Labels
Comments
5 tasks
Basic test written: enso$ git diff engine/runtime/src/test/java/org/enso/interpreter/test/SignatureTest.java
diff --git engine/runtime/src/test/java/org/enso/interpreter/test/SignatureTest.java engine/runtime/src/test/java/org/enso/interpreter/test/SignatureTest.java
index 6ec4136f48..3d79a8d457 100644
--- engine/runtime/src/test/java/org/enso/interpreter/test/SignatureTest.java
+++ engine/runtime/src/test/java/org/enso/interpreter/test/SignatureTest.java
@@ -2,6 +2,7 @@ package org.enso.interpreter.test;
import java.net.URI;
import java.net.URISyntaxException;
+import java.util.ArrayList;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.PolyglotException;
@@ -96,6 +97,96 @@ public class SignatureTest extends TestBase {
assertTrue("Yields Error value", yieldsError.isException());
}
+ @Test
+ public void runtimeCheckOfLazyAscribedFunctionSignature() throws Exception {
+ final URI uri = new URI("memory://neg_lazy.enso");
+ final Source src = Source.newBuilder("enso", """
+ from Standard.Base import Integer, IO
+
+ build (~zero : Integer) =
+ neg (~a : Integer) = zero - a
+ neg
+
+ make arr = build <|
+ IO.println "returning"+(arr.at 0 . to_text)
+ arr.at 0
+ """, uri.getHost())
+ .uri(uri)
+ .buildLiteral();
+
+ var module = ctx.eval(src);
+
+ var zeroValue = new Object[] { 0 };
+ var neg = module.invokeMember("eval_expression", "make").execute((Object)zeroValue);
+
+ zeroValue[0] = "Wrong";
+ var error = neg.execute(-5);
+ assertEquals("Just ten as the zeroValue[0] is always read again", 10, error.asInt());
+
+ var five = neg.execute(-5);
+ assertEquals("Five", 5, five.asInt());
+
+ try {
+ var res = neg.execute("Hi");
+ fail("Expecting an exception, not: " + res);
+ } catch (PolyglotException e) {
+ assertTypeError("`a`", "Integer", "Text", e.getMessage());
+ }
+ zeroValue[0] = 5;
+ var fifteen = neg.execute(-10);
+ assertEquals("Five + Ten as the zeroValue[0] is always read again", 15, fifteen.asInt());
+
+ zeroValue[0] = 0;
+ var ten = neg.execute(-10);
+ assertEquals("Just ten as the zeroValue[0] is always read again", 10, ten.asInt());
+ }
+
+ @Test
+ public void runtimeCheckOfLazyAscribedConstructorSignature() throws Exception {
+ final URI uri = new URI("memory://neg_lazy_const.enso");
+ final Source src = Source.newBuilder("enso", """
+ from Standard.Base import Integer, IO, Polyglot
+
+ type Lazy
+ Value (~zero : Integer)
+
+ neg self (~a : Integer) = self.zero - a
+
+ make arr = Lazy.Value <|
+ Polyglot.invoke arr "add" [ arr.length ]
+ arr.at 0
+ """, uri.getHost())
+ .uri(uri)
+ .buildLiteral();
+
+ var module = ctx.eval(src);
+
+ var zeroValue = new ArrayList<Integer>();
+ zeroValue.add(0);
+ var lazy = module.invokeMember("eval_expression", "make").execute((Object)zeroValue);
+ assertEquals("No read from zeroValue, still size 1", 1, zeroValue.size());
+
+ var five = lazy.invokeMember("neg", -5);
+ assertEquals("Five", 5, five.asInt());
+ assertEquals("One read from zeroValue, size 2", 2, zeroValue.size());
+
+ try {
+ var res = lazy.invokeMember("neg", "Hi");
+ fail("Expecting an exception, not: " + res);
+ } catch (PolyglotException e) {
+ assertTypeError("`a`", "Integer", "Text", e.getMessage());
+ }
+ zeroValue.set(0, 5);
+ var fifteen = lazy.invokeMember("neg", -10);
+ assertEquals("Five + Ten as the zeroValue[0] is never read again", 10, fifteen.asInt());
+ assertEquals("One read from zeroValue, size 2", 2, zeroValue.size());
+
+ zeroValue.set(0, 0);
+ var ten = lazy.invokeMember("neg", -9);
+ assertEquals("Just nine as the zeroValue[0] is always read again", 9, ten.asInt());
+ assertEquals("One read from zeroValue, size 2", 2, zeroValue.size());
+ }
+
@Test
public void runtimeCheckOfAscribedInstanceMethodSignature() throws Exception {
final URI uri = new URI("memory://twice_instance.enso"); |
Jaroslav Tulach reports a new STANDUP for yesterday (2023-09-04): Progress: - investigating "suggestion DB & conversions": #7716 (comment)
Next Day: bugfixing
|
2 tasks
github-project-automation
bot
moved this from 🔧 Implementation
to 🟢 Accepted
in Issues Board
Sep 6, 2023
Jaroslav Tulach reports a new STANDUP for yesterday (2023-09-05): Progress: - thinking about yjs: https://github.com/yjs/yjs
Next Day: Planning & bugfixing
|
5 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Follow up of #6682:
one can instantiate
Some
with non-Integer
values. That shouldn't be possible and should yield an error. Similar checks shall be performed for suspended method arguments.The text was updated successfully, but these errors were encountered: