Skip to content

Commit

Permalink
Turn missing body in a binding into a syntax error (#6107)
Browse files Browse the repository at this point in the history
Test and fix for #5903.
  • Loading branch information
JaroslavTulach authored Mar 28, 2023
1 parent 3ca0a17 commit d1c52fe
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions engine/runtime/src/main/java/org/enso/compiler/TreeToIr.java
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,9 @@ private IR.Expression translateFunction(Tree fun, IR.Name name, java.util.List<A
block.copy$default$7()
);
}
if (body == null) {
body = translateSyntaxError(fun, IR$Error$Syntax$UnexpectedExpression$.MODULE$);
}
return new IR$Expression$Binding(name, body,
getIdentifiedLocation(fun), meta(), diag()
);
Expand Down Expand Up @@ -842,6 +845,9 @@ yield switch (op.codeRepr()) {
case Tree.Assignment assign -> {
var name = buildNameOrQualifiedName(assign.getPattern());
var expr = translateExpression(assign.getExpr(), false);
if (expr == null) {
expr = translateSyntaxError(assign, IR$Error$Syntax$UnexpectedExpression$.MODULE$);
}
yield new IR$Expression$Binding(name, expr, getIdentifiedLocation(tree), meta(), diag());
}
case Tree.ArgumentBlockApplication body -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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 org.junit.BeforeClass;
import org.junit.Test;
Expand Down Expand Up @@ -46,4 +47,21 @@ public void testCaseOfWithNegativeConstant() throws Exception {
var none = run.execute(33);
assertEquals("none", none.asString());
}

@Test
public void testHalfAssignment() throws Exception {
var module = ctx.eval("enso", """
run value =
x = 4
y =
z = 5
""");
var run = module.invokeMember("eval_expression", "run");
try {
var never = run.execute(-1);
fail("Unexpected result: " + never);
} catch (PolyglotException ex) {
assertEquals("Syntax error: Unexpected expression.", ex.getMessage());
}
}
}

0 comments on commit d1c52fe

Please sign in to comment.