Skip to content

Ignore @throws annotation on non-methods - #26802

Merged
tanishiking merged 1 commit into
scala:mainfrom
dotty-staging:fix-throws-annot
Aug 14, 2026
Merged

Ignore @throws annotation on non-methods#26802
tanishiking merged 1 commit into
scala:mainfrom
dotty-staging:fix-throws-annot

Conversation

@tanishiking

Copy link
Copy Markdown
Member

According to JVMS 4.7.9.1
https://docs.oracle.com/javase/specs/jvms/se24/html/jvms-4.html#jvms-4.7.9.1

ThrowsSignature is only valid in MethodSignatures. Previously, we add ^... ThrowsSignature no matter the symbol is method or not. We should just ignore @throws annotation on invalid locations.

Fixes comment by @WojciechMazur #26787 (comment) (in usql)

Have you relied on LLM-based tools in this contribution?

No

How was the solution tested?

New automated tests (including the issue's reproducer, if applicable)

According to JVMS 4.7.9.1
https://docs.oracle.com/javase/specs/jvms/se24/html/jvms-4.html#jvms-4.7.9.1

`ThrowsSignature` is only valid in `MethodSignature`s.
Previously, we add `^...` ThrowsSignature no matter the symbol is method
or not. We just ignore @throws annotation on invalid locations.

@SolalPirelli SolalPirelli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good fix to have for 3.9, but should we error about this earlier in the pipeline? Presumably a developer would do this because they intended to put it somewhere else.

@SolalPirelli SolalPirelli added the backport:nominated If we agree to backport this PR, replace this tag with "backport:accepted", otherwise delete it. label Aug 14, 2026
@SolalPirelli SolalPirelli added this to the 3.9.0 milestone Aug 14, 2026
@tanishiking

Copy link
Copy Markdown
Member Author

should we error about this earlier in the pipeline?

Yeah, and in fact, Scala 2 already emits error earlier in the pipeline. I'll open an issue 👍

@tanishiking
tanishiking merged commit 05bf135 into scala:main Aug 14, 2026
60 checks passed
@tanishiking
tanishiking deleted the fix-throws-annot branch August 14, 2026 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:nominated If we agree to backport this PR, replace this tag with "backport:accepted", otherwise delete it.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants