8235446: confusing error message for records with no parens
Reviewed-by: mcimadamore
This commit is contained in:
parent
06cb195865
commit
bf2f855cd7
src/jdk.compiler/share/classes/com/sun/tools/javac
test/langtools/tools/javac
@ -3664,23 +3664,29 @@ public class JavacParser implements Parser {
|
||||
} else {
|
||||
int pos = token.pos;
|
||||
List<JCTree> errs;
|
||||
if (LAX_IDENTIFIER.accepts(token.kind)) {
|
||||
errs = List.of(mods, toP(F.at(pos).Ident(ident())));
|
||||
setErrorEndPos(token.pos);
|
||||
if (token.kind == IDENTIFIER && token.name() == names.record && preview.isEnabled()) {
|
||||
checkSourceLevel(Feature.RECORDS);
|
||||
JCErroneous erroneousTree = syntaxError(token.pos, List.of(mods), Errors.RecordHeaderExpected);
|
||||
return toP(F.Exec(erroneousTree));
|
||||
} else {
|
||||
errs = List.of(mods);
|
||||
}
|
||||
final JCErroneous erroneousTree;
|
||||
if (parseModuleInfo) {
|
||||
erroneousTree = syntaxError(pos, errs, Errors.ExpectedModuleOrOpen);
|
||||
} else {
|
||||
if (allowRecords) {
|
||||
erroneousTree = syntaxError(pos, errs, Errors.Expected4(CLASS, INTERFACE, ENUM, "record"));
|
||||
if (LAX_IDENTIFIER.accepts(token.kind)) {
|
||||
errs = List.of(mods, toP(F.at(pos).Ident(ident())));
|
||||
setErrorEndPos(token.pos);
|
||||
} else {
|
||||
erroneousTree = syntaxError(pos, errs, Errors.Expected3(CLASS, INTERFACE, ENUM));
|
||||
errs = List.of(mods);
|
||||
}
|
||||
final JCErroneous erroneousTree;
|
||||
if (parseModuleInfo) {
|
||||
erroneousTree = syntaxError(pos, errs, Errors.ExpectedModuleOrOpen);
|
||||
} else {
|
||||
if (allowRecords) {
|
||||
erroneousTree = syntaxError(pos, errs, Errors.Expected4(CLASS, INTERFACE, ENUM, "record"));
|
||||
} else {
|
||||
erroneousTree = syntaxError(pos, errs, Errors.Expected3(CLASS, INTERFACE, ENUM));
|
||||
}
|
||||
}
|
||||
return toP(F.Exec(erroneousTree));
|
||||
}
|
||||
return toP(F.Exec(erroneousTree));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3522,6 +3522,9 @@ compiler.err.instance.initializer.not.allowed.in.records=\
|
||||
compiler.err.record.declaration.not.allowed.in.inner.classes=\
|
||||
record declarations not allowed in inner classes
|
||||
|
||||
compiler.err.record.header.expected=\
|
||||
record header expected
|
||||
|
||||
############################################
|
||||
# messages previouly at javac.properties
|
||||
|
||||
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (c) 2019, 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.record.header.expected
|
||||
// key: compiler.note.preview.filename
|
||||
// key: compiler.note.preview.recompile
|
||||
// options: --enable-preview -source ${jdk.version}
|
||||
|
||||
record R {}
|
@ -67,7 +67,7 @@ public class RecordCompilationTests extends CompilationTestCase {
|
||||
assertFail("compiler.err.premature.eof", "record R();");
|
||||
assertFail("compiler.err.illegal.start.of.type", "record R(,) { }");
|
||||
assertFail("compiler.err.illegal.start.of.type", "record R((int x)) { }");
|
||||
assertFail("compiler.err.expected4", "record R { }");
|
||||
assertFail("compiler.err.record.header.expected", "record R { }");
|
||||
assertFail("compiler.err.expected", "record R(foo) { }");
|
||||
assertFail("compiler.err.expected", "record R(int int) { }");
|
||||
assertFail("compiler.err.mod.not.allowed.here", "abstract record R(String foo) { }");
|
||||
|
Loading…
x
Reference in New Issue
Block a user