RFR: 8294020: improve errors for record declarations
Vicente Romero
vromero at openjdk.org
Thu Nov 3 02:47:00 UTC 2022
Although the reporter originally complained about the error message for records with no header, I think the issue is deeper. We intentionally didn't follow the same path for parsing record declarations as we do for, for example, classes. This is mainly because `class` is a keyword but `record` is a contextual keyword. So when we find `record` we are not sure if it is an identifier or a record declaration. Although I think that given a context where the compiler expects a type declaration, we can be more aggressive than before and if we find `record` + `identifier` consider it a record declaration. The current implementation of `JavacParser::isRecordStart` is trying to be too clever but it is actually leaving several cases uncovered. So the proposed simpler version should be more stable and make record related errors more similar to those for other class declarations. Test `RecordDeclarationSyntaxTest.java` has been added just to have a golden file that stores the error position.
TIA
-------------
Commit messages:
- 8294020: improve errors for record declarations
Changes: https://git.openjdk.org/jdk/pull/10963/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=10963&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8294020
Stats: 45 lines in 6 files changed: 15 ins; 13 del; 17 mod
Patch: https://git.openjdk.org/jdk/pull/10963.diff
Fetch: git fetch https://git.openjdk.org/jdk pull/10963/head:pull/10963
PR: https://git.openjdk.org/jdk/pull/10963
More information about the compiler-dev
mailing list