8198479: JDK build is broken by 8194892

Reviewed-by: sundar
This commit is contained in:
Vicente Romero 2018-02-21 00:29:04 -05:00
parent 6287aead09
commit 4b6ab35c85
15 changed files with 75 additions and 417 deletions

View File

@ -43,10 +43,11 @@ import com.sun.tools.javac.tree.*;
import com.sun.tools.javac.tree.JCTree.*;
import com.sun.tools.javac.util.*;
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag;
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
import com.sun.tools.javac.util.JCDiagnostic.Error;
import com.sun.tools.javac.util.JCDiagnostic.Warning;
import com.sun.tools.javac.util.List;
import com.sun.tools.javac.util.JCDiagnostic.Fragment;
import com.sun.tools.javac.util.List;
import static com.sun.tools.javac.parser.Tokens.TokenKind.*;
import static com.sun.tools.javac.parser.Tokens.TokenKind.ASSERT;
@ -289,31 +290,9 @@ public class JavacParser implements Parser {
/** Skip forward until a suitable stop token is found.
*/
protected void skip(boolean stopAtImport, boolean stopAtMemberDecl, boolean stopAtIdentifier, boolean stopAtStatement, boolean stopAtLambdaBody) {
protected void skip(boolean stopAtImport, boolean stopAtMemberDecl, boolean stopAtIdentifier, boolean stopAtStatement) {
while (true) {
switch (token.kind) {
case ARROW:
if (stopAtLambdaBody) {
//find end of lambda expression; this could be either a comma or an rparen (if in method context),
//or a semi colon (if in assignment context).
int depth = 0;
while (true) {
switch (token.kind) {
case EOF:
case LBRACE: depth++; break;
case RBRACE: depth--; break;
case COMMA:
case RPAREN:
case SEMI:
if (depth == 0) {
return;
}
break;
}
nextToken();
}
}
break;
case SEMI:
nextToken();
return;
@ -1097,8 +1076,7 @@ public class JavacParser implements Parser {
break;
case LPAREN:
if (typeArgs == null && (mode & EXPR) != 0) {
LambdaClassfier lambdaClassifier = new LambdaClassfier();
ParensResult pres = analyzeParens(lambdaClassifier);
ParensResult pres = analyzeParens();
switch (pres) {
case CAST:
accept(LPAREN);
@ -1117,15 +1095,9 @@ public class JavacParser implements Parser {
mode = EXPR;
JCExpression t1 = term3();
return F.at(pos).TypeCast(t, t1);
case BAD_LAMBDA:
Assert.checkNonNull(lambdaClassifier.diagFragment);
t = syntaxError(pos, List.nil(), Errors.InvalidLambdaParameterDeclaration(lambdaClassifier.diagFragment));
skip(false, false, false, false, true);
break;
case IMPLICIT_LAMBDA:
case EXPLICIT_LAMBDA:
case IMPLICIT_LAMBDA_ALL_VAR:
t = lambdaExpressionOrStatement(true, pres != ParensResult.IMPLICIT_LAMBDA, pos);
t = lambdaExpressionOrStatement(true, pres == ParensResult.EXPLICIT_LAMBDA, pos);
break;
default: //PARENS
accept(LPAREN);
@ -1537,17 +1509,15 @@ public class JavacParser implements Parser {
* matching '>' and see if the subsequent terminal is either '.' or '::'.
*/
@SuppressWarnings("fallthrough")
ParensResult analyzeParens(LambdaClassfier lambdaClassifier) {
ParensResult analyzeParens() {
int depth = 0;
boolean type = false;
outer: for (int lookahead = 0 ; ; lookahead++) {
Token lookaheadToken = S.token(lookahead);
TokenKind tk = lookaheadToken.kind;
TokenKind tk = S.token(lookahead).kind;
switch (tk) {
case COMMA:
type = true;
break;
case FINAL: case EXTENDS: case SUPER: case DOT: case AMP:
case EXTENDS: case SUPER: case DOT: case AMP:
//skip
break;
case QUES:
@ -1564,8 +1534,7 @@ public class JavacParser implements Parser {
return ParensResult.CAST;
} else if (peekToken(lookahead, LAX_IDENTIFIER)) {
//Type, Identifier/'_'/'assert'/'enum' -> explicit lambda
lambdaClassifier.addExplicitParameter();
lookahead++; //skip Identifier
return ParensResult.EXPLICIT_LAMBDA;
}
break;
case LPAREN:
@ -1578,29 +1547,24 @@ public class JavacParser implements Parser {
}
break;
case RPAREN:
if (peekToken(lookahead, ARROW)) {
//this is a lambda
return lambdaClassifier.result();
} else {
// if we have seen something that looks like a type,
// then it's a cast expression
if (type) return ParensResult.CAST;
// otherwise, disambiguate cast vs. parenthesized expression
// based on subsequent token.
switch (S.token(lookahead + 1).kind) {
/*case PLUSPLUS: case SUBSUB: */
case BANG: case TILDE:
case LPAREN: case THIS: case SUPER:
case INTLITERAL: case LONGLITERAL: case FLOATLITERAL:
case DOUBLELITERAL: case CHARLITERAL: case STRINGLITERAL:
case TRUE: case FALSE: case NULL:
case NEW: case IDENTIFIER: case ASSERT: case ENUM: case UNDERSCORE:
case BYTE: case SHORT: case CHAR: case INT:
case LONG: case FLOAT: case DOUBLE: case BOOLEAN: case VOID:
return ParensResult.CAST;
default:
return ParensResult.PARENS;
}
// if we have seen something that looks like a type,
// then it's a cast expression
if (type) return ParensResult.CAST;
// otherwise, disambiguate cast vs. parenthesized expression
// based on subsequent token.
switch (S.token(lookahead + 1).kind) {
/*case PLUSPLUS: case SUBSUB: */
case BANG: case TILDE:
case LPAREN: case THIS: case SUPER:
case INTLITERAL: case LONGLITERAL: case FLOATLITERAL:
case DOUBLELITERAL: case CHARLITERAL: case STRINGLITERAL:
case TRUE: case FALSE: case NULL:
case NEW: case IDENTIFIER: case ASSERT: case ENUM: case UNDERSCORE:
case BYTE: case SHORT: case CHAR: case INT:
case LONG: case FLOAT: case DOUBLE: case BOOLEAN: case VOID:
return ParensResult.CAST;
default:
return ParensResult.PARENS;
}
case UNDERSCORE:
case ASSERT:
@ -1608,23 +1572,17 @@ public class JavacParser implements Parser {
case IDENTIFIER:
if (peekToken(lookahead, LAX_IDENTIFIER)) {
// Identifier, Identifier/'_'/'assert'/'enum' -> explicit lambda
if (Feature.LOCAL_VARIABLE_TYPE_INFERENCE.allowedInSource(source) &&
lookaheadToken.name() == names.var) {
lambdaClassifier.addImplicitVarParameter();
} else {
lambdaClassifier.addExplicitParameter();
}
lookahead++; //skip Identifier
} else if ((!type && peekToken(lookahead, COMMA)) || peekToken(lookahead, RPAREN)) {
lambdaClassifier.addImplicitParameter();
return ParensResult.EXPLICIT_LAMBDA;
} else if (peekToken(lookahead, RPAREN, ARROW)) {
// Identifier, ')' '->' -> implicit lambda
return ParensResult.IMPLICIT_LAMBDA;
}
type = false;
break;
case FINAL:
case ELLIPSIS:
//those can only appear in explicit, non-var, lambdas
lambdaClassifier.addExplicitParameter();
lookahead++; //skip Identifier
break;
//those can only appear in explicit lambdas
return ParensResult.EXPLICIT_LAMBDA;
case MONKEYS_AT:
type = true;
lookahead += 1; //skip '@'
@ -1656,9 +1614,7 @@ public class JavacParser implements Parser {
case LBRACKET:
if (peekToken(lookahead, RBRACKET, LAX_IDENTIFIER)) {
// '[', ']', Identifier/'_'/'assert'/'enum' -> explicit lambda
lambdaClassifier.addExplicitParameter();
lookahead += 2; //skip ']' Identifier
break;
return ParensResult.EXPLICIT_LAMBDA;
} else if (peekToken(lookahead, RBRACKET, RPAREN) ||
peekToken(lookahead, RBRACKET, AMP)) {
// '[', ']', ')' -> cast
@ -1687,15 +1643,12 @@ public class JavacParser implements Parser {
// '>', '&' -> cast
return ParensResult.CAST;
} else if (peekToken(lookahead, LAX_IDENTIFIER, COMMA) ||
peekToken(lookahead, LAX_IDENTIFIER, RPAREN, ARROW)) {
peekToken(lookahead, LAX_IDENTIFIER, RPAREN, ARROW) ||
peekToken(lookahead, ELLIPSIS)) {
// '>', Identifier/'_'/'assert'/'enum', ',' -> explicit lambda
// '>', Identifier/'_'/'assert'/'enum', ')', '->' -> explicit lambda
lambdaClassifier.addExplicitParameter();
lookahead++; //skip Identifier
break;
} else if (peekToken(lookahead, ELLIPSIS)) {
// '>', '...' -> explicit lambda
break; //this is handled in the outer switch
return ParensResult.EXPLICIT_LAMBDA;
}
//it looks a type, but could still be (i) a cast to generic type,
//(ii) an unbound method reference or (iii) an explicit lambda
@ -1713,61 +1666,6 @@ public class JavacParser implements Parser {
}
}
class LambdaClassfier {
ParensResult kind;
Fragment diagFragment;
void addExplicitParameter() {
reduce(ParensResult.EXPLICIT_LAMBDA);
}
void addImplicitVarParameter() {
reduce(ParensResult.IMPLICIT_LAMBDA_ALL_VAR);
}
void addImplicitParameter() {
reduce(ParensResult.IMPLICIT_LAMBDA);
}
private void reduce(ParensResult newKind) {
if (kind == null) {
kind = newKind;
} else if (kind != newKind && kind != ParensResult.BAD_LAMBDA) {
ParensResult currentKind = kind;
kind = ParensResult.BAD_LAMBDA;
switch (currentKind) {
case EXPLICIT_LAMBDA:
if (newKind == ParensResult.IMPLICIT_LAMBDA) {
diagFragment = Fragments.ImplicitAndExplicitNotAllowed;
} else if (newKind == ParensResult.IMPLICIT_LAMBDA_ALL_VAR) {
diagFragment = Fragments.VarAndExplicitNotAllowed;
}
break;
case IMPLICIT_LAMBDA:
if (newKind == ParensResult.EXPLICIT_LAMBDA) {
diagFragment = Fragments.ImplicitAndExplicitNotAllowed;
} else if (newKind == ParensResult.IMPLICIT_LAMBDA_ALL_VAR) {
diagFragment = Fragments.VarAndImplicitNotAllowed;
}
break;
case IMPLICIT_LAMBDA_ALL_VAR:
if (newKind == ParensResult.EXPLICIT_LAMBDA) {
diagFragment = Fragments.VarAndExplicitNotAllowed;
} else if (newKind == ParensResult.IMPLICIT_LAMBDA) {
diagFragment = Fragments.VarAndImplicitNotAllowed;
}
break;
default:
throw new AssertionError("unexpected option for field kind");
}
}
}
ParensResult result() {
return kind;
}
}
/** Accepts all identifier-like tokens */
protected Filter<TokenKind> LAX_IDENTIFIER = t -> t == IDENTIFIER || t == UNDERSCORE || t == ASSERT || t == ENUM;
@ -1775,15 +1673,7 @@ public class JavacParser implements Parser {
CAST,
EXPLICIT_LAMBDA,
IMPLICIT_LAMBDA,
IMPLICIT_LAMBDA_ALL_VAR,
BAD_LAMBDA,
PARENS;
}
enum BAD_LAMBDA_KIND {
EXPLICIT_AND_VAR,
IMPLICIT_AND_VAR,
EXPLICIT_AND_IMPLICIT,
PARENS
}
JCExpression lambdaExpressionOrStatement(boolean hasParens, boolean explicitParams, int pos) {
@ -2006,9 +1896,6 @@ public class JavacParser implements Parser {
List<JCAnnotation> nextLevelAnnotations = typeAnnotationsOpt();
if (token.kind == LBRACKET) {
if (t == null) {
log.error(token.pos, Errors.VarNotAllowedArray);
}
int pos = token.pos;
nextToken();
t = bracketsOptCont(t, pos, nextLevelAnnotations);
@ -2407,7 +2294,7 @@ public class JavacParser implements Parser {
if (token.pos == lastErrPos)
return stats.toList();
if (token.pos <= endPosTable.errorEndPos) {
skip(false, true, true, true, false);
skip(false, true, true, true);
lastErrPos = token.pos;
}
stats.addAll(stat);
@ -3246,7 +3133,7 @@ public class JavacParser implements Parser {
while (token.kind != EOF) {
if (token.pos <= endPosTable.errorEndPos) {
// error recovery
skip(checkForImports, false, false, false, false);
skip(checkForImports, false, false, false);
if (token.kind == EOF)
break;
}
@ -3383,7 +3270,7 @@ public class JavacParser implements Parser {
defs.append(toP(F.at(pos).Provides(serviceName, implNames)));
} else {
log.error(DiagnosticFlag.SYNTAX, token.pos, Errors.ExpectedStr("'" + names.with + "'"));
skip(false, false, false, false, false);
skip(false, false, false, false);
}
} else if (token.name() == names.uses) {
nextToken();
@ -3588,7 +3475,7 @@ public class JavacParser implements Parser {
false));
if (token.pos <= endPosTable.errorEndPos) {
// error recovery
skip(false, true, true, false, false);
skip(false, true, true, false);
}
}
}
@ -3650,7 +3537,7 @@ public class JavacParser implements Parser {
accept(LBRACE);
if (token.pos <= endPosTable.errorEndPos) {
// error recovery
skip(false, true, false, false, false);
skip(false, true, false, false);
if (token.kind == LBRACE)
nextToken();
}
@ -3659,7 +3546,7 @@ public class JavacParser implements Parser {
defs.appendList(classOrInterfaceBodyDeclaration(className, isInterface));
if (token.pos <= endPosTable.errorEndPos) {
// error recovery
skip(false, true, true, false, false);
skip(false, true, true, false);
}
}
accept(RBRACE);
@ -3826,7 +3713,7 @@ public class JavacParser implements Parser {
accept(SEMI);
if (token.pos <= endPosTable.errorEndPos) {
// error recovery
skip(false, true, false, false, false);
skip(false, true, false, false);
if (token.kind == LBRACE) {
body = block();
}
@ -4060,7 +3947,7 @@ public class JavacParser implements Parser {
// need to distinguish between vararg annos and array annos
// look at typeAnnotationsPushedBack comment
this.permitTypeAnnotationsPushBack = true;
JCExpression type = parseType(lambdaParameter);
JCExpression type = parseType();
this.permitTypeAnnotationsPushBack = false;
if (token.kind == ELLIPSIS) {
@ -4077,10 +3964,6 @@ public class JavacParser implements Parser {
}
typeAnnotationsPushedBack = List.nil();
}
if (lambdaParameter && isRestrictedLocalVarTypeName(type)) {
//implicit lambda parameter type (with 'var')
type = null;
}
return variableDeclaratorId(mods, type, lambdaParameter);
}

View File

@ -1229,20 +1229,6 @@ compiler.err.var.not.allowed.array=\
compiler.err.var.not.allowed.compound=\
''var'' is not allowed in a compound declaration
# 0: fragment
compiler.err.invalid.lambda.parameter.declaration=\
invalid lambda parameter declaration\n\
({0})
compiler.misc.implicit.and.explicit.not.allowed=\
cannot mix implicitly-typed and explicitly-typed parameters
compiler.misc.var.and.explicit.not.allowed=\
cannot mix ''var'' and explicitly-typed parameters
compiler.misc.var.and.implicit.not.allowed=\
cannot mix ''var'' and implicitly-typed parameters
compiler.misc.local.cant.infer.null=\
variable initializer is ''null''

View File

@ -104,7 +104,7 @@ class ReplParser extends JavacParser {
while (token.kind != EOF) {
if (token.pos > 0 && token.pos <= endPosTable.errorEndPos) {
// error recovery
skip(true, false, false, false, false);
skip(true, false, false, false);
if (token.kind == EOF) {
break;
}

View File

@ -1,30 +0,0 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
// key: compiler.err.var.not.allowed.array
import java.util.function.*;
class BracketsNotAllowedImplicitLambda {
BiFunction<String[], String, String> f = (var s1[], var s2) -> s2;
}

View File

@ -1,31 +0,0 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
// key: compiler.err.invalid.lambda.parameter.declaration
// key: compiler.misc.implicit.and.explicit.not.allowed
import java.util.function.*;
class ExplicitImplicitLambda {
IntBinaryOperator f = (int x, y) -> x + y;
}

View File

@ -1,31 +0,0 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
// key: compiler.err.invalid.lambda.parameter.declaration
// key: compiler.misc.var.and.implicit.not.allowed
import java.util.function.*;
class VarAllOrNothing {
IntBinaryOperator f = (x, var y) -> x + y;
}

View File

@ -1,31 +0,0 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
// key: compiler.err.invalid.lambda.parameter.declaration
// key: compiler.misc.var.and.explicit.not.allowed
import java.util.function.*;
class VarExplicitLambda {
IntBinaryOperator f = (int x, var y) -> x + y;
}

View File

@ -1,31 +0,0 @@
/*
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
// key: compiler.err.invalid.lambda.parameter.declaration
// key: compiler.misc.var.and.explicit.not.allowed
class VarNotAllowedExplicitLambda {
F f = (String s, var v)->{};
}

View File

@ -1,4 +1,4 @@
T8131742.java:8:31: compiler.err.expected: ')'
T8131742.java:8:38: compiler.err.expected3: ',', ')', '['
T8131742.java:8:39: compiler.err.this.as.identifier
T8131742.java:8:43: compiler.err.expected: token.identifier
T8131742.java:8:43: compiler.err.expected: ';'
3 errors

View File

@ -40,7 +40,6 @@
*/
import java.io.IOException;
import java.util.Arrays;
import combo.ComboInstance;
import combo.ComboParameter;
@ -106,44 +105,26 @@ public class LambdaParserTest extends ComboInstance<LambdaParserTest> {
}
}
enum SourceKind {
SOURCE_9("9"),
SOURCE_10("10");
String sourceNumber;
SourceKind(String sourceNumber) {
this.sourceNumber = sourceNumber;
}
}
enum LambdaParameterKind implements ComboParameter {
IMPLICIT_1("", ExplicitKind.IMPLICIT),
IMPLICIT_2("var", ExplicitKind.IMPLICIT_VAR),
EXPLIICT_SIMPLE("A", ExplicitKind.EXPLICIT),
EXPLIICT_SIMPLE_ARR1("A[]", ExplicitKind.EXPLICIT),
EXPLIICT_SIMPLE_ARR2("A[][]", ExplicitKind.EXPLICIT),
EXPLICIT_VARARGS("A...", ExplicitKind.EXPLICIT),
EXPLICIT_GENERIC1("A<X>", ExplicitKind.EXPLICIT),
EXPLICIT_GENERIC2("A<? extends X, ? super Y>", ExplicitKind.EXPLICIT),
EXPLICIT_GENERIC2_VARARGS("A<? extends X, ? super Y>...", ExplicitKind.EXPLICIT),
EXPLICIT_GENERIC2_ARR1("A<? extends X, ? super Y>[]", ExplicitKind.EXPLICIT),
EXPLICIT_GENERIC2_ARR2("A<? extends X, ? super Y>[][]", ExplicitKind.EXPLICIT);
enum ExplicitKind {
IMPLICIT,
IMPLICIT_VAR,
EXPLICIT;
}
IMPLICIT(""),
EXPLIICT_SIMPLE("A"),
EXPLIICT_SIMPLE_ARR1("A[]"),
EXPLIICT_SIMPLE_ARR2("A[][]"),
EXPLICIT_VARARGS("A..."),
EXPLICIT_GENERIC1("A<X>"),
EXPLICIT_GENERIC2("A<? extends X, ? super Y>"),
EXPLICIT_GENERIC2_VARARGS("A<? extends X, ? super Y>..."),
EXPLICIT_GENERIC2_ARR1("A<? extends X, ? super Y>[]"),
EXPLICIT_GENERIC2_ARR2("A<? extends X, ? super Y>[][]");
String parameterType;
ExplicitKind explicitKind;
LambdaParameterKind(String parameterType, ExplicitKind ekind) {
LambdaParameterKind(String parameterType) {
this.parameterType = parameterType;
this.explicitKind = ekind;
}
boolean explicit() {
return this != IMPLICIT;
}
boolean isVarargs() {
@ -155,23 +136,12 @@ public class LambdaParserTest extends ComboInstance<LambdaParserTest> {
public String expand(String optParameter) {
return parameterType;
}
ExplicitKind explicitKind(SourceKind sk) {
switch (explicitKind) {
case IMPLICIT_VAR:
return (sk == SourceKind.SOURCE_9) ?
ExplicitKind.EXPLICIT : ExplicitKind.IMPLICIT_VAR;
default:
return explicitKind;
}
}
}
enum ModifierKind implements ComboParameter {
NONE(""),
FINAL("final"),
PUBLIC("public"),
ANNO("@A");
PUBLIC("public");
String modifier;
@ -182,8 +152,7 @@ public class LambdaParserTest extends ComboInstance<LambdaParserTest> {
boolean compatibleWith(LambdaParameterKind pk) {
switch (this) {
case PUBLIC: return false;
case ANNO:
case FINAL: return pk != LambdaParameterKind.IMPLICIT_1;
case FINAL: return pk != LambdaParameterKind.IMPLICIT;
case NONE: return true;
default: throw new AssertionError("Invalid modifier kind " + this);
}
@ -239,7 +208,6 @@ public class LambdaParserTest extends ComboInstance<LambdaParserTest> {
new ComboTestHelper<LambdaParserTest>()
.withFilter(LambdaParserTest::redundantTestFilter)
.withFilter(LambdaParserTest::badImplicitFilter)
.withDimension("SOURCE", (x, sk) -> x.sk = sk, SourceKind.values())
.withDimension("LAMBDA", (x, lk) -> x.lk = lk, LambdaKind.values())
.withDimension("NAME", (x, name) -> x.pn = name, LambdaParameterName.values())
.withArrayDimension("TYPE", (x, type, idx) -> x.pks[idx] = type, 2, LambdaParameterKind.values())
@ -253,7 +221,6 @@ public class LambdaParserTest extends ComboInstance<LambdaParserTest> {
ModifierKind[] mks = new ModifierKind[2];
LambdaKind lk;
LambdaParameterName pn;
SourceKind sk;
boolean badImplicitFilter() {
return !(mks[0] != ModifierKind.NONE && lk.isShort());
@ -273,15 +240,13 @@ public class LambdaParserTest extends ComboInstance<LambdaParserTest> {
return true;
}
String template = "@interface A { }\n" +
"class Test {\n" +
" SAM s = #{EXPR};\n" +
"}";
String template = "class Test {\n" +
" SAM s = #{EXPR};\n" +
"}";
@Override
public void doWork() throws IOException {
newCompilationTask()
.withOptions(Arrays.asList("-source", sk.sourceNumber))
.withSourceFromTemplate(template)
.parse(this::check);
}
@ -291,7 +256,7 @@ public class LambdaParserTest extends ComboInstance<LambdaParserTest> {
(lk.arity() > 1 && !mks[1].compatibleWith(pks[1]));
if (lk.arity() == 2 &&
(pks[0].explicitKind(sk) != pks[1].explicitKind(sk) ||
(pks[0].explicit() != pks[1].explicit() ||
pks[0].isVarargs())) {
errorExpected = true;
}

View File

@ -60,7 +60,7 @@ class ParserTest<var extends AutoCloseable> {
List<? extends var> l2; //error
List<? super var> l3; //error
try {
Function<var, String> f = (var x2) -> ""; //ok
Function<var, String> f = (var x2) -> ""; //error
} catch (var ex) { } //error
}

View File

@ -18,7 +18,8 @@ ParserTest.java:59:14: compiler.err.var.not.allowed.here
ParserTest.java:60:24: compiler.err.var.not.allowed.here
ParserTest.java:61:22: compiler.err.var.not.allowed.here
ParserTest.java:63:22: compiler.err.var.not.allowed.here
ParserTest.java:63:40: compiler.err.var.not.allowed.here
ParserTest.java:64:18: compiler.err.var.not.allowed.here
ParserTest.java:68:35: compiler.err.var.not.allowed.here
ParserTest.java:69:22: compiler.err.var.not.allowed.here
23 errors
24 errors

View File

@ -104,7 +104,7 @@ class TrialParser extends JavacParser {
while (token.kind != EOF) {
if (token.pos > 0 && token.pos <= endPosTable.errorEndPos) {
// error recovery
skip(true, false, false, false, false);
skip(true, false, false, false);
if (token.kind == EOF) {
break;
}

View File

@ -1,17 +0,0 @@
/*
* @test /nodynamiccopyright/
* @bug 8194892
* @summary add compiler support for local-variable syntax for lambda parameters
* @compile/fail/ref=VarInImplicitLambdaNegTest01.out -XDrawDiagnostics VarInImplicitLambdaNegTest01.java
*/
import java.util.function.*;
class VarInImplicitLambdaNegTest01 {
IntBinaryOperator f1 = (x, var y) -> x + y;
IntBinaryOperator f2 = (var x, y) -> x + y;
IntBinaryOperator f3 = (int x, var y) -> x + y;
IntBinaryOperator f4 = (int x, y) -> x + y;
BiFunction<String[], String, String> f5 = (var s1[], var s2) -> s2;
}

View File

@ -1,6 +0,0 @@
VarInImplicitLambdaNegTest01.java:11:28: compiler.err.invalid.lambda.parameter.declaration: (compiler.misc.var.and.implicit.not.allowed)
VarInImplicitLambdaNegTest01.java:12:28: compiler.err.invalid.lambda.parameter.declaration: (compiler.misc.var.and.implicit.not.allowed)
VarInImplicitLambdaNegTest01.java:13:28: compiler.err.invalid.lambda.parameter.declaration: (compiler.misc.var.and.explicit.not.allowed)
VarInImplicitLambdaNegTest01.java:14:28: compiler.err.invalid.lambda.parameter.declaration: (compiler.misc.implicit.and.explicit.not.allowed)
VarInImplicitLambdaNegTest01.java:16:54: compiler.err.var.not.allowed.array
5 errors