8199327: nuke var type name after a lambda has been accepted
authorvromero
Thu, 08 Mar 2018 10:28:46 -0500
changeset 49152 e38b6a7f65ee
parent 49151 a7d2f0dd9c1f
child 49153 5447851ff0f6
8199327: nuke var type name after a lambda has been accepted Reviewed-by: mcimadamore
src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java
test/langtools/tools/javac/var_implicit_lambda/VarInImplicitLambdaNegTest01.java
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java	Thu Mar 08 13:39:42 2018 +0800
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java	Thu Mar 08 10:28:46 2018 -0500
@@ -1696,6 +1696,11 @@
             if (lambdaClassifier.diagFragment != null) {
                 log.error(DiagnosticFlag.SYNTAX, pos, Errors.InvalidLambdaParameterDeclaration(lambdaClassifier.diagFragment));
             }
+            for (JCVariableDecl param: params) {
+                if (param.vartype != null && isRestrictedLocalVarTypeName(param.vartype)) {
+                    param.vartype = null;
+                }
+            }
         }
         return lambdaExpressionOrStatementRest(params, pos);
     }
--- a/test/langtools/tools/javac/var_implicit_lambda/VarInImplicitLambdaNegTest01.java	Thu Mar 08 13:39:42 2018 +0800
+++ b/test/langtools/tools/javac/var_implicit_lambda/VarInImplicitLambdaNegTest01.java	Thu Mar 08 10:28:46 2018 -0500
@@ -1,6 +1,6 @@
 /*
  * @test /nodynamiccopyright/
- * @bug 8198512
+ * @bug 8198512 8199327
  * @summary compiler support for local-variable syntax for lambda parameters
  * @compile/fail/ref=VarInImplicitLambdaNegTest01.out -XDrawDiagnostics VarInImplicitLambdaNegTest01.java
  */
@@ -14,5 +14,8 @@
     IntBinaryOperator f4 = (int x, y) -> x + y;                              // error explicit and implicit
 
     BiFunction<String[], String, String> f5 = (var s1[], var s2) -> s2;      // error var and array
+
+    // correct use
+    IntBinaryOperator f6 = (var x, var y) -> x + y;                          // ok
     BiFunction<Function<String, String>, String, String> f = (Function<String, String> s1, String s2) -> s2; // ok
 }