javac produces a compile error for valid java 7 codes: Cast vs Boolean Expression
bitter_fox
bitterfoxc at gmail.com
Mon Nov 25 21:32:33 PST 2013
Hi,
I found a javac bug.
Javac reject valid java 7 codes:
public class Test
{
static int a, b, c, d;
public static void main(String[] args)
{
boolean cond = (a < b & c > d);
/*
JavacParser#analyzeParens
LPAREN
IDENT(a) : skip
LT : depth = 1
IDENT(b) : skip
AMP : skip
IDENT(c) : skip
GT : depth = 0 -> type = true
IDENT(d) : skip
RPAREN : type == true -> return ParensResult.CAST
*/
}
}
This is a simple parened boolean expression.
But javac(JavacParser#analyzeParens) analyzes it into CAST expression from
above.
Today's JavacParser#analyzeParens take no thought that intersection type
for type parameter isn't accepted.
You should change JavacParser#analyzeParens like following.
--- a/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Mon
Nov 11 23:16:35 2013 -0800
+++ b/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Tue
Nov 26 14:27:43 2013 +0900
@@ -1536,7 +1536,14 @@
switch (tk) {
case COMMA:
type = true;
- case EXTENDS: case SUPER: case DOT: case AMP:
+ break;
+ case AMP:
+ if (depth > 0) {
+ // < ... & -> parens
+ // (for type parameter, intersection type isn't
accepted)
+ return ParensResult.PARENS;
+ }
+ case EXTENDS: case SUPER: case DOT:
//skip
break;
case QUES:
Regards,
bitter_fox
More information about the lambda-dev
mailing list