Skip to content

Conversation

jchyb
Copy link
Contributor

@jchyb jchyb commented Aug 27, 2025

This PR stabilizes Quotes reflect methods:

  • 3 overloaded versions of Symbol.newClass - the first one added in 3.3.0, updated in 3.7.0. Basically necessary for mock tests, and already used in ScalaMock via workarounds - so somewhat battle tested.
  • ClassDef.apply - added in 3.3.0, used in conjunction with Symbol.newClass.
  • The Symbol.newModule - added in 3.3.0, updated in 3.7.0. Not as widely used, but generally similar to the above. If we ever need more features there, we can add those via overloading.
  • ClassDef.module - added in 3.3.0, used in conjunction with Symbol.newModule.
  • Symbol.freshName - added in 3.3.0. Not strictly necessary, but useful even without Macro Annotations. The design is simple enough (and API identical to scala-2 counterpart), where I don't see anything that could go wrong here. Already used in some project via a workaround (Chimney).

The main idea here is to be finally able to use mocking libraries without any ugly workarounds or --experimental options. With that said, there are more methods in Quotes reflect that have been experimental for some time now:

  • Symbol.newTypeBounds, Symbol.newTypeAlias - added in 3.6.0. I believe they could be stabilized, and I planned to add them in this PR, but found some leftover todos (connected to the implementation, not the API) so I'll fix those and submit separately.
  • Symbol.info - added in 3.3.0. To be honest, I'd prefer if this was removed. Naturally info can return a ClassInfo which we currently do not support in the reflection API (so this can cause crashes currently). We would also need an asSeenFrom method added for this to be useful. We already have a method to return types of Symbols, with Symbol.typeMember, which already can return complete type information, making info + asSeenFrom redundant. Currently, in tests, it is used to more easily copy type information of one Symbol, when creating another (like when overwriting a hashCode method). There must be a better way to do that than accessing the raw info of any Symbol (perhaps we could add a methodInfo instead, which would, by design, not work for Classes)
  • GivenSelectorModule.apply, OmitSelectorModule.apply, RenameSelectorModule.apply, SimpleSelectorModule.apply- Added in 3.7.0. I'd prefer if we waited with these a bit. Added by an outside contributor, I tried to look for solid arguments not to add them, couldn't really find any, merged them and I got some pushback after doing so from other contributors. Ideally, when unused-imports become more stable/complete, we'll be able to better see the impact of those methods.
  • other ones like erasedParams and erasedArgs are still connected to other experimental features, so they should be left as-is.

@jchyb jchyb force-pushed the stabilise-Quotes-reflect-methods branch from 7f787be to 1cc636d Compare August 27, 2025 23:30
@jchyb jchyb marked this pull request as ready for review August 28, 2025 09:38
@jchyb jchyb requested a review from a team as a code owner August 28, 2025 09:38
@jchyb jchyb requested a review from hamzaremmal August 28, 2025 09:39
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.

2 participants