Skip to content
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

Closed
1 task
JaroslavTulach opened this issue May 30, 2023 · 2 comments · Fixed by #7848
Closed
1 task

Methods with type parameter are reported as errorneous #6885

JaroslavTulach opened this issue May 30, 2023 · 2 comments · Fixed by #7848
Assignees
Milestone

Comments

@JaroslavTulach
Copy link
Member

JaroslavTulach commented May 30, 2023

During work on #6682 I realized that following Enso program:

type Maybe a
    Nothing
    Some unwrap:a

    get : a
    get self = self.unwrap

yields an error:

Compiler encountered errors:
Unnamed[5:11-5:11]: The name `a` could not be found.

that's wrong. The a is defined by the type and shall be a known type variable thru-out the whole body of Maybe type.

Tasks

Preview Give feedback
@JaroslavTulach JaroslavTulach added this to the Beta Release milestone May 30, 2023
@jdunkerley jdunkerley moved this from ❓New to 📤 Backlog in Issues Board May 30, 2023
@JaroslavTulach JaroslavTulach moved this from 📤 Backlog to ⚙️ Design in Issues Board Jun 13, 2023
@JaroslavTulach
Copy link
Member Author

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);
+    }
+  }
 }

@JaroslavTulach JaroslavTulach moved this from ⚙️ Design to 📤 Backlog in Issues Board Jul 25, 2023
@JaroslavTulach JaroslavTulach moved this from 📤 Backlog to 👁️ Code review in Issues Board Sep 20, 2023
@github-project-automation github-project-automation bot moved this from 👁️ Code review to 🟢 Accepted in Issues Board Sep 20, 2023
@enso-bot
Copy link

enso-bot bot commented Sep 21, 2023

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

Discord
Discord is the easiest way to communicate over voice, video, and text. Chat, hang out, and stay close with your friends and communities.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant