Skip to content

Commit

Permalink
Nested type declaration shall yield a syntax error (#4011)
Browse files Browse the repository at this point in the history
Nested type declaration shall yield a syntax error

# Important Notes
Now the Radek's sample:
```
type Foo
type Bar

main = 42
```
yields
```bash
$ enso --run test.enso
In module test:
Compiler encountered errors:
test.enso[2:9-2:16]: Unexpected declaration in the body of a type.
Aborting due to 1 errors and 0 warnings.
Execution finished with an error: Compilation aborted due to errors.
```
  • Loading branch information
JaroslavTulach authored Dec 30, 2022
1 parent 0041b64 commit af57d14
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion engine/runtime/src/main/java/org/enso/compiler/TreeToIr.java
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,10 @@ private List<IR> translateTypeBodyExpression(Tree exp, List<IR> appendTo) {
var inputAst = maybeManyParensed(exp);
return switch (inputAst) {
case null -> appendTo;
case Tree.TypeDef def -> translateModuleSymbol(def, (List) appendTo);
case Tree.TypeDef def -> {
var ir = translateSyntaxError(def, IR$Error$Syntax$UnexpectedDeclarationInType$.MODULE$);
yield cons(ir, appendTo);
}
case Tree.ArgumentBlockApplication app -> appendTo;
case Tree.TypeSignature sig -> {
var isMethod = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,16 @@ public void testSelf1() throws Exception {
""");
}

@Test
public void testPanic_184119084() throws Exception {
parseTest("""
type Foo
type Bar
main = 42
""");
}

@Test
public void testMetadataRaw() throws Exception {
parseTest("""
Expand Down

0 comments on commit af57d14

Please sign in to comment.