You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Stabilise Quotes reflect methods used for creating new classes/objects (#23826)
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.
0 commit comments