changeset 45750:15404afd36ab

8058408: Compiler should emit a clearer message for invalid parenthesized expression Reviewed-by: sadayapalam Contributed-by: priya.lakshmi.muthuswamy@oracle.com
author sadayapalam
date Tue, 27 Jun 2017 15:30:21 +0530
parents 11797433fbc0
children 61f96770ee3a
files langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties langtools/test/tools/javac/Parens1.out langtools/test/tools/javac/Parens4.out langtools/test/tools/javac/diags/examples/IllegalParanthesisExpression.java langtools/test/tools/javac/expression/IllegalParenthesis.java langtools/test/tools/javac/expression/IllegalParenthesis.out
diffstat 7 files changed, 53 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Mon Jun 26 18:43:00 2017 -0700
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Tue Jun 27 15:30:21 2017 +0530
@@ -3184,7 +3184,7 @@
         result = check(tree, owntype, pkind(), resultInfo);
         Symbol sym = TreeInfo.symbol(tree);
         if (sym != null && sym.kind.matches(KindSelector.TYP_PCK))
-            log.error(tree.pos(), Errors.IllegalStartOfType);
+            log.error(tree.pos(), Errors.IllegalParenthesizedExpression);
     }
 
     public void visitAssign(JCAssign tree) {
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties	Mon Jun 26 18:43:00 2017 -0700
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties	Tue Jun 27 15:30:21 2017 +0530
@@ -591,6 +591,9 @@
 compiler.err.illegal.start.of.type=\
     illegal start of type
 
+compiler.err.illegal.parenthesized.expression=\
+    illegal parenthesized expression
+
 compiler.err.illegal.unicode.esc=\
     illegal unicode escape
 
--- a/langtools/test/tools/javac/Parens1.out	Mon Jun 26 18:43:00 2017 -0700
+++ b/langtools/test/tools/javac/Parens1.out	Tue Jun 27 15:30:21 2017 +0530
@@ -1,2 +1,2 @@
-Parens1.java:12:20: compiler.err.illegal.start.of.type
+Parens1.java:12:20: compiler.err.illegal.parenthesized.expression
 1 error
--- a/langtools/test/tools/javac/Parens4.out	Mon Jun 26 18:43:00 2017 -0700
+++ b/langtools/test/tools/javac/Parens4.out	Tue Jun 27 15:30:21 2017 +0530
@@ -1,2 +1,2 @@
-Parens4.java:12:16: compiler.err.illegal.start.of.type
+Parens4.java:12:16: compiler.err.illegal.parenthesized.expression
 1 error
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/diags/examples/IllegalParanthesisExpression.java	Tue Jun 27 15:30:21 2017 +0530
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2017, 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.illegal.parenthesized.expression
+
+class IllegalParenthesisExpression {
+    String s = (Integer).toString(123);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/expression/IllegalParenthesis.java	Tue Jun 27 15:30:21 2017 +0530
@@ -0,0 +1,16 @@
+/*
+ * @test  /nodynamiccopyright/
+ * @bug 8058408
+ * @summary Test that illegal.parenthesized.expression error key is used for parenthesized expression used in cast
+ *
+ * @compile/fail/ref=IllegalParenthesis.out -XDrawDiagnostics IllegalParenthesis.java
+ */
+
+import java.time.LocalDate;
+
+class IllegalParenthesis {
+    String s = (Integer).toString(123);
+    void f(){
+        LocalDate date = (LocalDate).now();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/expression/IllegalParenthesis.out	Tue Jun 27 15:30:21 2017 +0530
@@ -0,0 +1,3 @@
+IllegalParenthesis.java:12:16: compiler.err.illegal.parenthesized.expression
+IllegalParenthesis.java:14:26: compiler.err.illegal.parenthesized.expression
+2 errors