Skip to content

Fix annotations being not expected in the middle of an array type by java parser#22391

Merged
hamzaremmal merged 1 commit into
scala:mainfrom
fan-tom:bugfix/19642-java-parse-annottations-in-array-types
Jan 21, 2025
Merged

Fix annotations being not expected in the middle of an array type by java parser#22391
hamzaremmal merged 1 commit into
scala:mainfrom
fan-tom:bugfix/19642-java-parse-annottations-in-array-types

Conversation

@fan-tom
Copy link
Copy Markdown
Contributor

@fan-tom fan-tom commented Jan 16, 2025

Closes #19642

Currently Java parser doesn't expect annotation between type name and square brackets in an array type, or between pairs of square brackets in nested array types.

I added a call to corresponding parser method annotations when parsing array types.

I also changed an unnecessary var to val, as IDEA suggested.

@fan-tom fan-tom marked this pull request as ready for review January 17, 2025 09:35
@fan-tom

This comment was marked as resolved.

Copy link
Copy Markdown
Member

@hamzaremmal hamzaremmal left a comment

Choose a reason for hiding this comment

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

Hi @fan-tom. thanks for contributing to Scala 3 🎉 . Your changes only covers half of the issue (type annotations on array). To fully close the linked issue, a fix for path selection has to be submitted. Would you like to try fixing it or should we take it from here ? Your changes for annotations on array types are correct and can be merged when all the requirements to close the issue are met.

Comment thread tests/pos/i19642/i19642.scala Outdated
@fan-tom
Copy link
Copy Markdown
Contributor Author

fan-tom commented Jan 20, 2025

Thanks @hamzaremmal

Would you like to try fixing it

Definitely, but I need inputs for that, like what's path selection. If possible, I'd like to get help writing a test case, from which I can unwind what and where exactly in code goes wrong. I tried to search for this term in https://dotty.epfl.ch/docs but got nothing

@fan-tom
Copy link
Copy Markdown
Contributor Author

fan-tom commented Jan 20, 2025

Oh, I just got that original issue speaks about such syntax Class.@TpeAnnot NestedClass

…ava parser

Java parser doesn't expect an annotation in the next types, while it should:
- `Object @my.Ann []`
- `Object @my.Ann [] @my.OtherAnn []`

closes scala#19642
@fan-tom
Copy link
Copy Markdown
Contributor Author

fan-tom commented Jan 20, 2025

@hamzaremmal hasn't path selection syntax been fixed in #21867? At least the MRE test from the original issue passes, without any additional fixes from my side. Seems issue and PR were not linked properly.

@fan-tom fan-tom force-pushed the bugfix/19642-java-parse-annottations-in-array-types branch from ed25fca to 9c971be Compare January 20, 2025 22:30
@fan-tom fan-tom requested a review from hamzaremmal January 20, 2025 22:31
@hamzaremmal
Copy link
Copy Markdown
Member

@hamzaremmal hasn't path selection syntax been fixed in #21867? At least the MRE test from the original issue passes, without any additional fixes from my side. Seems issue and PR were not linked properly.

Ah yes, it does

@mkurz
Copy link
Copy Markdown
Contributor

mkurz commented May 29, 2026

Backport / Same fix for Scala 2:

@mkurz
Copy link
Copy Markdown
Contributor

mkurz commented May 30, 2026

Added an additional test case here: #26188

mkurz added a commit to mkurz/scala that referenced this pull request May 30, 2026
Backport the Scala 3 Java parser fix for annotations that appear
before array brackets, such as String @nullable [] and nested annotated
arrays.

Scala 3 fixed the same parser gap in scala/scala3#22391. This applies
the corresponding optArrayBrackets change to the Scala 2 Java parser
and extends the existing Java type annotation positive test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot parse Java file with type annotations on array or path selection

5 participants