Compiler plugins API: init
method should have access to Context
#20185
Labels
area:initialization
itype:enhancement
needs-minor-release
This PR cannot be merged until the next minor release
Milestone
Currently
StandardPlugin
defined an init methodWhen parsing options, users might want to report warnings (e.g. deprecate compiler plugin options), however
report.warning
requires implicitContext
. One available Context instance that can be suggested to users isNoContext
, however it's usage would result in runtime exceptions.Solution 1: redefine
StandardPlugin
since Scala 3.5.0 to define implicit Context parameterThe issue with this solution is source compatibility with already existing compiler plugins sources, there are now 106 found standar d plugins implementations on GitHub . All of this would be required to modify the builds to support for version specific implementation of init method
Solution 2: create additional method taking Context that delated to old init method by default
New method needs to have a different name, otherwise we would not be able to delegate contextual init call to old non-contextual method. Another issue is handling of old
init
method variant - it typically would needed to be overrided with dummy implementation.Solution 3: create additional method run before / after init with access to context allowing to validate options and report warnings. Provide it with default no-op implimentation to make it backward source-compatible.
Alternative solutions:
Allow to use
report
usingNoContext
Issue is related to Scala Native compiler plugin, which has used NoContext for reporting. It was workaround by using
ContextBase().initialCtx
instead ofNoContext
but it seems to not support logging correctly - warning message has no level modifier, seems to be standard println instead.The text was updated successfully, but these errors were encountered: