Stabilise Quotes reflect methods used for creating new classes/objects #23826
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR stabilizes Quotes reflect methods:
Symbol.newClass
- the first one added in 3.3.0, updated in 3.7.0. Basically necessary for mock tests, and already used inScalaMock
via workarounds - so somewhat battle tested.ClassDef.apply
- added in 3.3.0, used in conjunction withSymbol.newClass
.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 withSymbol.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. Naturallyinfo
can return aClassInfo
which we currently do not support in the reflection API (so this can cause crashes currently). We would also need anasSeenFrom
method added for this to be useful. We already have a method to return types of Symbols, withSymbol.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 ahashCode
method). There must be a better way to do that than accessing the rawinfo
of any Symbol (perhaps we could add amethodInfo
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.erasedParams
anderasedArgs
are still connected to other experimental features, so they should be left as-is.