Details
-
Enhancement
-
Resolution: Fixed
-
P4
-
8
-
b01
-
Verified
Description
Consider an obviously erroneous code like this:
---
public class Test {
Runnable r = (void args) -> args;
}
---
Many errors are produced for this code:
---
$ javac Test.java
Test.java:2: error: illegal start of expression
Runnable r = (void args) -> args;
^
Test.java:2: error: ')' expected
Runnable r = (void args) -> args;
^
Test.java:2: error: ';' expected
Runnable r = (void args) -> args;
^
Test.java:2: error: illegal start of type
Runnable r = (void args) -> args;
^
4 errors
---
And the AST for this is quite distorted (there is no lambda, etc.) The AST should ideally look like a lambda, whose parameter has type 'void', and limited number of more obvious errors should be produced.
The reason for the current behavior is that the parser does not parse the lambda as a lambda, but rather as a parenthesized expression, which fails much worse. The AST is also inconsistent with the similar case where 'void' is used as a method parameter's type (but seeJDK-8026374).
This is with jdk8/tl/langtools:
---
$ hg tip
changeset: 2186:f3ca12d680f3
tag: tip
user: jfranck
date: Mon Nov 11 17:26:09 2013 +0100
summary: 8027375: javac asserts on nested erroneous annotations
---
---
public class Test {
Runnable r = (void args) -> args;
}
---
Many errors are produced for this code:
---
$ javac Test.java
Test.java:2: error: illegal start of expression
Runnable r = (void args) -> args;
^
Test.java:2: error: ')' expected
Runnable r = (void args) -> args;
^
Test.java:2: error: ';' expected
Runnable r = (void args) -> args;
^
Test.java:2: error: illegal start of type
Runnable r = (void args) -> args;
^
4 errors
---
And the AST for this is quite distorted (there is no lambda, etc.) The AST should ideally look like a lambda, whose parameter has type 'void', and limited number of more obvious errors should be produced.
The reason for the current behavior is that the parser does not parse the lambda as a lambda, but rather as a parenthesized expression, which fails much worse. The AST is also inconsistent with the similar case where 'void' is used as a method parameter's type (but see
This is with jdk8/tl/langtools:
---
$ hg tip
changeset: 2186:f3ca12d680f3
tag: tip
user: jfranck
date: Mon Nov 11 17:26:09 2013 +0100
summary: 8027375: javac asserts on nested erroneous annotations
---