-
Notifications
You must be signed in to change notification settings - Fork 326
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
Methods with type parameter are reported as errorneous #6885
Comments
Here is a test: diff --git engine/runtime/src/test/java/org/enso/compiler/ExecCompilerTest.java engine/runtime/src/test/java/org/enso/compiler/ExecCompilerTest.java
index 85fd720aee..795111a8eb 100644
--- engine/runtime/src/test/java/org/enso/compiler/ExecCompilerTest.java
+++ engine/runtime/src/test/java/org/enso/compiler/ExecCompilerTest.java
@@ -1,20 +1,23 @@
package org.enso.compiler;
-import java.io.OutputStream;
+import java.io.ByteArrayOutputStream;
import java.nio.file.Paths;
import org.enso.polyglot.RuntimeOptions;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.PolyglotException;
import org.junit.AfterClass;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
public class ExecCompilerTest {
private static Context ctx;
+ private static final ByteArrayOutputStream out = new ByteArrayOutputStream();
@BeforeClass
public static void initEnsoContext() {
@@ -25,7 +28,10 @@ public class ExecCompilerTest {
RuntimeOptions.LANGUAGE_HOME_OVERRIDE,
Paths.get("../../distribution/component").toFile().getAbsolutePath()
)
- .logHandler(OutputStream.nullOutputStream())
+ .option(RuntimeOptions.STRICT_ERRORS, "true")
+ .logHandler(out)
+ .out(out)
+ .err(out)
.allowAllAccess(true)
.build();
assertNotNull("Enso language is supported", ctx.getEngine().getLanguages().get("enso"));
@@ -36,6 +42,11 @@ public class ExecCompilerTest {
ctx.close();
}
+ @Before
+ public void cleanTheOutput() {
+ out.reset();
+ }
+
@Test
public void testCaseOfWithNegativeConstant() throws Exception {
var module = ctx.eval("enso", """
@@ -60,12 +71,13 @@ public class ExecCompilerTest {
y =
z = 5
""");
- var run = module.invokeMember("eval_expression", "run");
try {
- var never = run.execute(-1);
- fail("Unexpected result: " + never);
+ var run = module.invokeMember("eval_expression", "run");
+ var never = run.execute(-1);
+ fail("Unexpected result: " + never);
} catch (PolyglotException ex) {
- assertEquals("Syntax error: Unexpected expression.", ex.getMessage());
+ assertEquals("Compilation aborted due to errors.", ex.getMessage());
+ assertNotEquals("Expecting error in:\n" + out, -1, out.toString().indexOf("error: Unexpected expression."));
}
}
@@ -116,4 +128,25 @@ public class ExecCompilerTest {
var err = run.execute(0);
assertEquals("Error: Module is not a part of a package.", err.asString());
}
+
+ @Test
+ public void typeVariableInAMethod() throws Exception {
+ var module = ctx.eval("enso", """
+ type Maybe a
+ Nothing
+ Some unwrap:a
+
+ get : a
+ get self = self.unwrap
+
+ run x = Maybe.Some x . get
+ """);
+ try {
+ var run = module.invokeMember("eval_expression", "run");
+ var six = run.execute(6);
+ assertEquals(6, six.asInt());
+ } catch (PolyglotException e) {
+ fail("Shouldn't throw an exception: " + e.getMessage() + "\n" + out);
+ }
+ }
} |
2 tasks
Jaroslav Tulach reports a new STANDUP for yesterday (2023-09-20): Progress: - Fixed by #7848
Next Day: Getting ready for next week's GraalVM workshop
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
During work on #6682 I realized that following Enso program:
yields an error:
that's wrong. The
a
is defined by thetype
and shall be a known type variable thru-out the whole body ofMaybe
type.Tasks
The text was updated successfully, but these errors were encountered: