Can compiler plugins stop a vanilla Kotlin compile...
# compiler
c
Can compiler plugins stop a vanilla Kotlin compiler error/diagnostic from appearing? I'm working on a composite-annotations plugin (like Spring), and to do it I need to be able to apply any annotation to an annotation class, not just ones with
ANNOTATION_CLASS
as an allowed target.
EDIT: I just wanted to make my funky little compiler plugins, why am I now running into, of all things, the diamond problem ;_; Jeez it's almost like adding new language features is hard or something
😆 1
j
AFAIK, no, and I opened some time ago an issue on YouTrack about suppressing errors or diagnostics.
c
Oh no! So you really can't add any features that were previously errors?
b
Well, this is not exactly a recommendation because it could lead you to some problems in your plugin in future compiler versions or even in its behavior, but if you really want maybe for testing or internal usage you can make usage of some reflection for that, in your
FirAdditionalCheckersExtension
have something like this:
Copy code
private fun FirClass.suppressWrongAnnotationTarget(
    reporter: PendingDiagnosticsCollectorWithSuppress
  ) {
    val pendingDiagnosticsField = reporter::class.java.getDeclaredField("pendingDiagnosticsByFilePath")
    pendingDiagnosticsField.isAccessible = true
    val pendingDiagnostics = pendingDiagnosticsField.getSafe(reporter) as? MutableMap<String?, MutableList<KtDiagnostic>>
    pendingDiagnostics?.values?.forEach {
      it.removeAll { diagnostic -> diagnostic.factory.name == "WRONG_ANNOTATION_TARGET" }
    }
  }
👀 1
c
We do love jank in this house. It's less brittle than ASM at least, thank you!