Accept an annotated C-style array dimension on a parameter - #65
Merged
Merged
Conversation
A method parameter declared as "int a @anno []" crashed the formatter with a VerifyException from visitAnnotatedArrayType: the parameter's type was printed as a whole, dimensions included, before the name, and the annotated dimension that belongs after the name had nowhere to go. Fields and locals were fine, because their path already splits the dimensions off the type; parameters, resources and catch parameters go through visitToDeclare, which did not. This ports the fix for google/google-java-format#374, upstream commit ed40e472 by cushon, together with the null check that google/google-java-format#463 (upstream commit e19b7637) added next to it: a "var" declaration or an untyped lambda parameter has no type tree to split. The golden I374 comes from upstream, with the expected output in this project's style. The 15,747 files of the JDK 21 sources format exactly as before.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Brings over the fix for google/google-java-format#374, commit google/google-java-format@ed40e472 from google-java-format 1.8.
The bug
A method parameter declared as
int a @Anno []crashed the formatter with aVerifyExceptionfromvisitAnnotatedArrayType. The parameter's type was printed as a whole, dimensions included, before the name, and the annotated dimension that belongs after the name had nowhere to go. Fields and locals were fine, because their path already splits the dimensions off the type; parameters, try-with-resources and catch parameters go throughvisitToDeclare, which did not.From upstream, with the author kept
visitToDeclarenow extracts the dimensions the same way the other declaration paths do and hands them todeclareOne, which already knew what to do with them.vardeclaration or an untyped lambda parameter has no type tree to split. Without it, the port failed theVargolden and 83 JDK files.I374comes with it, with the expected output in this project's style.Checked
int @A [] a @B [],var,for (var x : xs)and untyped lambda parameters still format as before../gradlew :open-java-format:teston JDK 21: 1501 tests, all green.