Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8294020: improve errors for record declarations #10963

Conversation

vicente-romero-oracle
Copy link
Contributor

@vicente-romero-oracle vicente-romero-oracle commented Nov 3, 2022

Although the reporter originally referred to 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


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk pull/10963/head:pull/10963
$ git checkout pull/10963

Update a local copy of the PR:
$ git checkout pull/10963
$ git pull https://git.openjdk.org/jdk pull/10963/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 10963

View PR using the GUI difftool:
$ git pr show -t 10963

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/10963.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 3, 2022

👋 Welcome back vromero! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label Nov 3, 2022
@openjdk
Copy link

openjdk bot commented Nov 3, 2022

@vicente-romero-oracle The following label will be automatically applied to this pull request:

  • compiler

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the compiler compiler-dev@openjdk.org label Nov 3, 2022
@mlbridge
Copy link

mlbridge bot commented Nov 3, 2022

Webrevs

@jaikiran
Copy link
Member

jaikiran commented Nov 3, 2022

Hello Vicente, I built this PR locally and compiled the same previous code that was reporting that odd error message:

public record Record {

}

With the change in this PR, the error message is much more understandable:

javac /tmp/Record.java 
/tmp/Record.java:1: error: '(' expected
public record Record {
                    ^
/tmp/Record.java:1: error: illegal start of type
public record Record {
                     ^
2 errors

Thank you.

@forax
Copy link
Member

forax commented Nov 3, 2022

There is also the dual problem, students are writing classes with parenthesis after the name and the error message is not obvious too

FooNotARecord.java:1: error: '{' expected
public class FooNotARecord(String s) {
                          ^
1 error

@forax
Copy link
Member

forax commented Nov 3, 2022

I believe in both cases, the error message should mention that a record requires parenthesis (the word record should be in the error message).

By example here is the error message reported by IntelliJ when a class is declared with parenthesis
"record header declared for non record".

@vicente-romero-oracle
Copy link
Contributor Author

vicente-romero-oracle commented Nov 3, 2022

Hello Vicente, I built this PR locally and compiled the same previous code that was reporting that odd error message:

public record Record {

}

With the change in this PR, the error message is much more understandable:

javac /tmp/Record.java 
/tmp/Record.java:1: error: '(' expected
public record Record {
                    ^
/tmp/Record.java:1: error: illegal start of type
public record Record {
                     ^
2 errors

Thank you.

nice, thanks for your feedback

@jaikiran
Copy link
Member

jaikiran commented Nov 3, 2022

I wasn't complaining :) I am just happily stating that your change in this PR makes the error message more understandable than what was before.

@vicente-romero-oracle
Copy link
Contributor Author

I wasn't complaining :) I am just happily stating that your change in this PR makes the error message more understandable than what was before.

hehe, right I think I was pre-coffee sorry, thanks for your feedback

Copy link
Contributor

@lahodaj lahodaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks OK.

@openjdk
Copy link

openjdk bot commented Nov 7, 2022

@vicente-romero-oracle This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8294020: improve errors for record declarations

Reviewed-by: jlahoda

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 66 new commits pushed to the master branch:

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Nov 7, 2022
@vicente-romero-oracle
Copy link
Contributor Author

@lahodaj thanks for the review

@vicente-romero-oracle
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Nov 7, 2022

Going to push as commit 60db5f2.
Since your change was applied there have been 72 commits pushed to the master branch:

  • 520db1e: 8296485: BuildEEBasicConstraints.java test fails with SunCertPathBuilderException
  • b29817a: 8296479: Remove stray comment about POST_STRIP_CMD
  • b6ea69c: 8296480: java/security/cert/pkix/policyChanges/TestPolicy.java is failing
  • 3baad06: 8295953: Use enhanced-for cycle instead of Enumeration in sun.security
  • ba303c0: 8295893: Improve printing of Constant Pool Cache Entries
  • f8b2574: 8296137: diags-examples.xml is broken
  • 00d22f6: 8279164: Disable TLS_ECDH_* cipher suites
  • d634dde: 8295354: Remove G1 incremental non-copy time calculation
  • 8836b92: 8296226: Add constructors (String,Throwable) and (Throwable) to InvalidParameterException
  • 51f8e9b: 8296443: NMT: Remove cmdline_tracking_level handling code
  • ... and 62 more: https://git.openjdk.org/jdk/compare/50d91a31d495adf8e189d0188918f4ff22f93876...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Nov 7, 2022
@openjdk openjdk bot closed this Nov 7, 2022
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Nov 7, 2022
@openjdk
Copy link

openjdk bot commented Nov 7, 2022

@vicente-romero-oracle Pushed as commit 60db5f2.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@vicente-romero-oracle vicente-romero-oracle deleted the JDK-8294020 branch November 7, 2022 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler compiler-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

4 participants