changeset 48435:e3b7341fd0d4 datum

improve error messages
author vromero
date Fri, 08 Dec 2017 16:32:38 -0500
parents 7807f935382e
children f942ae050606
files src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties test/langtools/tools/javac/datum/Neg03.java test/langtools/tools/javac/datum/Neg03.out test/langtools/tools/javac/datum/NoAddFieldsCanBeDeclaredInDatumTest.out
diffstat 5 files changed, 23 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java	Fri Dec 08 13:43:00 2017 -0500
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java	Fri Dec 08 16:32:38 2017 -0500
@@ -3793,6 +3793,7 @@
                     storeEnd(defs.last(), S.prevToken().endPos);
                     return defs;
                 } else {
+                    error(pos, "record.fields.must.be.in.header");
                     int tmpPos = token.pos;
                     nextToken();
                     return List.of(syntaxError(tmpPos, null, "expected", LPAREN));
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties	Fri Dec 08 13:43:00 2017 -0500
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties	Fri Dec 08 16:32:38 2017 -0500
@@ -319,7 +319,7 @@
 
 # 0: name
 compiler.err.duplicate.argument.to.super=\
-    duplicate argument {0}, arguments passed to super of a data class must be unique
+    duplicate argument {0}, arguments passed to the super of a record must be unique
 
 compiler.err.record.must.declare.at.least.one.field=\
     records must declare at least one field
@@ -345,7 +345,10 @@
     found: {2} {3}
 
 compiler.misc.bad.super.fields=\
-    A data class cannot have both an explicit constructor, and an implicit superclass header.
+    A record cannot have both an explicit constructor, and an implicit superclass header.
+
+compiler.err.record.fields.must.be.in.header=\
+    record fields must be declared in the header
 
 # 0: symbol
 compiler.err.cant.inherit.from.final=\
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/datum/Neg03.java	Fri Dec 08 16:32:38 2017 -0500
@@ -0,0 +1,11 @@
+/*
+ * @test /nodynamiccopyright/
+ * @summary smoke negative test for datum classes
+ * @compile/fail/ref=Neg03.out -XDrawDiagnostics Neg03.java
+ */
+
+public class Neg03 {
+    record R(int i) {
+        int j;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/datum/Neg03.out	Fri Dec 08 16:32:38 2017 -0500
@@ -0,0 +1,3 @@
+Neg03.java:9:13: compiler.err.record.fields.must.be.in.header
+Neg03.java:9:14: compiler.err.expected: '('
+2 errors
--- a/test/langtools/tools/javac/datum/NoAddFieldsCanBeDeclaredInDatumTest.out	Fri Dec 08 13:43:00 2017 -0500
+++ b/test/langtools/tools/javac/datum/NoAddFieldsCanBeDeclaredInDatumTest.out	Fri Dec 08 16:32:38 2017 -0500
@@ -1,7 +1,8 @@
+NoAddFieldsCanBeDeclaredInDatumTest.java:9:13: compiler.err.record.fields.must.be.in.header
 NoAddFieldsCanBeDeclaredInDatumTest.java:9:14: compiler.err.expected: '('
 NoAddFieldsCanBeDeclaredInDatumTest.java:13:9: compiler.err.illegal.start.of.type
 NoAddFieldsCanBeDeclaredInDatumTest.java:13:20: compiler.err.expected: token.identifier
-NoAddFieldsCanBeDeclaredInDatumTest.java:13:21: compiler.err.expected: '('
+NoAddFieldsCanBeDeclaredInDatumTest.java:13:21: compiler.err.record.fields.must.be.in.header
 NoAddFieldsCanBeDeclaredInDatumTest.java:17:16: compiler.err.illegal.start.of.type
 NoAddFieldsCanBeDeclaredInDatumTest.java:18:5: compiler.err.expected4: class, interface, enum, record
-6 errors
+7 errors