-
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
Parse inline function signatures #8470
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR claims to fix #6166. It seems to do so, but it also does something with default
. That doesn't seem to be in scope of #6166...
More consistent handling of default arguments. default is a valid identifier, and only has special meaning when it isn't bound in scope. Since distinguishing the builtin default from an identifier called default cannot be done until alias analysis has been performed, default is now represented in the AST as a regular identifier.
... OK, can we see how the default
behaves in the runtime? For example by modifying the ExecCompilerTest
?
engine/runtime-parser/src/main/java/org/enso/compiler/core/TreeToIr.java
Outdated
Show resolved
Hide resolved
("->" (Ident Integer)) | ||
"=" (Ident that))); | ||
// Edge case | ||
test!("number -> Integer = 23", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also add such a test to ExecCompilerTest?
@JaroslavTulach I added tests for |
@Test | ||
public void inlineReturnSignatureWithoutArguments() throws Exception { | ||
var module = ctx.eval("enso", """ | ||
the_number -> Integer = 23 | ||
"""); | ||
var result = module.invokeMember("eval_expression", "the_number"); | ||
assertEquals("Function-return syntax can be used with 0 arguments", 23, result.asInt()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should also get a test when there is more than 0 arguments 🙂
I'd be happy to add a test case, may I push to your branch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to add a following patch:
Subject: [PATCH] add 2 more compiler test cases
---
Index: engine/runtime/src/test/java/org/enso/compiler/ExecCompilerTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/engine/runtime/src/test/java/org/enso/compiler/ExecCompilerTest.java b/engine/runtime/src/test/java/org/enso/compiler/ExecCompilerTest.java
--- a/engine/runtime/src/test/java/org/enso/compiler/ExecCompilerTest.java (revision 45ed77d513735bce59e2c8739a55a38560a69ccb)
+++ b/engine/runtime/src/test/java/org/enso/compiler/ExecCompilerTest.java (revision 7273a5c43575d2e913caa18f9a4edc071d6df135)
@@ -199,6 +199,29 @@
assertEquals("10 % 3 is one", 1, result.asInt());
}
+ @Test
+ public void inlineReturnSignature() throws Exception {
+ var module = ctx.eval("enso", """
+ foo (x : Integer) (y : Integer) -> Integer = 10*x + y
+ """);
+ var foo = module.invokeMember("eval_expression", "foo");
+ assertTrue("foo a function", foo.canExecute());
+ assertEquals(45, foo.execute(4, 5).asInt());
+ }
+
+ @Test
+ public void inlineReturnSignatureOnMemberMethod() throws Exception {
+ var module = ctx.eval("enso", """
+ type My_Type
+ Value x
+
+ foo self (y : Integer) z -> Integer = 100*z + 10*y + self.x
+ """);
+ var instance = module.invokeMember("eval_expression", "My_Type.Value 1");
+ var result = instance.invokeMember("foo", 2, 3);
+ assertEquals(321, result.asInt());
+ }
+
@Test
public void inlineReturnSignatureWithoutArguments() throws Exception {
var module = ctx.eval("enso", """
Tests are passing with it.
@kazcw May I push it to this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@radeusgd Sure.
var returnSignature = fn.getReturns(); | ||
if (returnSignature != null) { | ||
var returnType = translateType(returnSignature.getType()); | ||
// TODO(#8240): Make use of return type declaration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Description
Implements #6166.
Important Notes
default
arguments.default
is a valid identifier, and only has special meaning when it isn't bound in scope. Since distinguishing the builtindefault
from an identifier calleddefault
cannot be done until alias analysis has been performed,default
is now represented in the AST as a regular identifier.TreeToIr
: RemoveinsideTypeAscription
. It was only used for bug-for-bug compatibility with the old parser during the transition.Checklist
Please ensure that the following checklist has been satisfied before submitting the PR:
Screenshots/screencasts have been attached, if there are any visual changes. For interactive or animated visual changes, a screencast is preferred.Scala,
Java,
and
Rust
style guides. In case you are using a language not listed above, follow the Rust style guide.
./run ide build
.