Skip to content

fix(scanner): Don't insert semicolon before constructor annotations#248

Merged
VladimirMakaev merged 3 commits intofwcd:mainfrom
punchagan:modifier-constructor
Mar 12, 2026
Merged

fix(scanner): Don't insert semicolon before constructor annotations#248
VladimirMakaev merged 3 commits intofwcd:mainfrom
punchagan:modifier-constructor

Conversation

@punchagan
Copy link
Copy Markdown
Contributor

No description provided.

@github-actions github-actions bot added the scanner Related to the external scanner label Mar 12, 2026
@punchagan punchagan force-pushed the modifier-constructor branch from 5a1cc91 to dec16de Compare March 12, 2026 13:48
…otation args

Fixes two edge cases in check_annotation_then_constructor:

1. Fully-qualified annotation names (e.g. @com.example.Inject) are now
   handled by skipping dot-separated segments in the annotation name.

2. String literals inside annotation arguments (e.g. @bar(name = "x)y"))
   are now skipped over when counting parenthesis depth, preventing
   premature exit from the argument list.
@VladimirMakaev
Copy link
Copy Markdown
Collaborator

Thanks for the fix! I found two edge cases that the lookahead in check_annotation_then_constructor didn't handle and pushed a follow-up commit to your branch:

1. Fully-qualified annotations

class Foo
@com.example.Inject
constructor (x: Int) {}

The scanner read com as the annotation name and then saw ., which it didn't recognize as part of the annotation. It exited the annotation loop early, failed to find constructor, and incorrectly inserted ASI.

Fix: After reading word characters for the annotation name, also skip .-separated qualifier segments.

2. String literals containing parentheses in annotation arguments

class Foo
@Bar(name = "some ) text")
constructor (x: Int) {}

The ) inside the string literal decremented the parenthesis depth counter to 0, causing the scanner to exit the argument list prematurely. The same issue occurred with ( inside strings incrementing the counter.

Fix: When scanning inside (...), skip over "..." string literals (including \-escaped characters) without counting their contents as parentheses.

Both edge cases now have test coverage. All 289 tests pass.

@VladimirMakaev VladimirMakaev merged commit a1760ba into fwcd:main Mar 12, 2026
2 checks passed
@punchagan
Copy link
Copy Markdown
Contributor Author

Thank you for the review, the improvements/fixes and the merge! 🎉 🙇

@punchagan punchagan deleted the modifier-constructor branch March 12, 2026 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scanner Related to the external scanner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants