Description
Currently StandardPlugin
defined an init method
def init(options: List[String]): List[PluginPhase]
When parsing options, users might want to report warnings (e.g. deprecate compiler plugin options), however report.warning
requires implicit Context
. One available Context instance that can be suggested to users is NoContext
, however it's usage would result in runtime exceptions.
Solution 1: redefine StandardPlugin
since Scala 3.5.0 to define implicit Context parameter
def init(options: List[String])(using Context): List[PluginPhase]
The 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
def initialize(options: List[String])(using Context): List[PluginPhase] = init(options)
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.
def validate(options: List[String])(using Context): Unit = ()
Alternative solutions:
Allow to use report
using NoContext
Issue is related to Scala Native compiler plugin, which has used NoContext for reporting. It was workaround by using ContextBase().initialCtx
instead of NoContext
but it seems to not support logging correctly - warning message has no level modifier, seems to be standard println instead.