Skip to content

Conversation

@ecrabor8
Copy link

@ecrabor8 ecrabor8 commented Jan 4, 2026

This PR fixes issue #22991 by retaining parameter annotations in mixin phase
generation of forwarder methods.
Therefore, a trait method parameter annotated with Java RetentionPolicy.RUNTIME
annotation is retained in the subclasses .class file in same named method/parameter
for Java reflection use.
This restores the behavior of Scala 2 for such RUNTIME annotated paramters.

Closes ticket #22991

Note -- This is one of two PR choices that fix the issue. Consider this one as second cut with alternate set of changes.

Fixes #22991

…ding methods

    This PR fixes issue scala#22991 by retaining parameter annotations in mixin phase
    generation of forwarder methods.
    Therefore, a trait method parameter annotated with Java RetentionPolicy.RUNTIME
    annotation is retained in the subclasses .class file in same named method/parameter
    for Java reflection use.
    This restores the behavior of Scala 2 for such RUNTIME annotated paramters.

    Closes ticket scala#22991
@odersky
Copy link
Contributor

odersky commented Jan 7, 2026

Where to add or not annotations is a bit outside my area of expertise. Someone should evaluate the two alternative PRs and compare with what Scala 2 does. Then do the closest to the Scala 2 behavior.

@odersky odersky removed their assignment Jan 7, 2026
vpms.addAnnotations(annots)
forwarderSym.setParamss(vparams :: Nil)
end if
transformFollowing(DefDef(forwarderSym, forwarderRhsFn(meth)))
Copy link
Contributor

Choose a reason for hiding this comment

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

This was over my head, but it felt like a lot of work.

I pushed a slightly different PR. If that flies, I'll add you as co-author.

Copy link
Author

Choose a reason for hiding this comment

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

I looked at the PR you mention and I like it. I was not able to clone this repo to try out the test but I assume the test still passes. No problem and appreciate the co-author. I figured my PR here was just a starting point and I have some learning to do if I were to become a further contributor. Thanks.

Copy link
Contributor

@som-snytt som-snytt left a comment

Choose a reason for hiding this comment

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

Let's see if the 3rd time was a charm. Feedback welcome!

@@ -0,0 +1,9 @@
class Blah extends scala.annotation.StaticAnnotation

trait Barly {
Copy link
Contributor

Choose a reason for hiding this comment

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

I will definitely use Barly in future!

@som-snytt
Copy link
Contributor

I forgot that the assignment was to compare Scala 2. Can I get an extension? I saw the Scala 3 comment that params are kept up-to-date until erasure, but I did not understand it. (I expected "fidelity"; but I'll look again tomorrow, or your today.)

@@ -0,0 +1,17 @@

Copy link
Contributor

Choose a reason for hiding this comment

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

It needs to skip scalajs because of java reflection. My version will also fail!

// scalajs: --skip

Copy link
Author

Choose a reason for hiding this comment

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

sounds good. I didnt understand the issue with scala-js testing.

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.

Trait method parameter annotated with RetentionPolicy.RUNTIME annotation is not indicated in .class file for the method parameter

3 participants