8058408: Compiler should emit a clearer message for invalid parenthesized expression

Reviewed-by: sadayapalam
This commit is contained in:
Priya Lakshmi Muthuswamy 2017-06-27 15:30:21 +05:30 committed by Srikanth Adayapalam
parent feee226151
commit 965530668b
7 changed files with 53 additions and 3 deletions

View File

@ -3184,7 +3184,7 @@ public class Attr extends JCTree.Visitor {
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) {

View File

@ -591,6 +591,9 @@ compiler.err.illegal.start.of.stmt=\
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

View File

@ -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

View File

@ -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

View File

@ -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);
}

View File

@ -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();
}
}

View File

@ -0,0 +1,3 @@
IllegalParenthesis.java:12:16: compiler.err.illegal.parenthesized.expression
IllegalParenthesis.java:14:26: compiler.err.illegal.parenthesized.expression
2 errors