How to add `@Suppress` for `IrTypeOperatorCall` by...
# compiler
t
How to add
@Suppress
for
IrTypeOperatorCall
by compiler plugin?
Copy code
external interface INode

// before
val isNode = i is INode

// after
val isNode = @Suppress(
    "UNCHECKED_CAST_TO_EXTERNAL_INTERFACE",
    "USELESS_IS_CHECK"
) i is INode
✔️ 1
d
Why do you need it? If you want automaticlly suppress some diagnostics in existing code then such IR transformation doesn't help because of almost all diagnostics are reported before IR phase
t
I have custom strict implementation of
is
and
as
operators for some external interfaces. By default: •
is
operator for external interface = ERROR •
as
operator for external interface = WARNING I need suppress both for specific interfaces
d
I suggest you to look at
DiagnosticSuppressor
extension
👍 1
t
Could it be registered via SPI?
d
It's regular extension point, like
IrGenerationExtension
t
I register
IrGenerationExtension
via
IrGenerationExtension.registerExtension
But
DiagnosticSuppressor
has no register method
d
Oh, I got it. Yes, suppressor should be registered using java services mechanism
t
Will it work in IR mode?
d
Should be. It's a frontend extension point
t
I declare suppressor in Kotlin Compiler plugin, but it has no effect
For test I suppress all warnings/errors with special type
And remove suppresses here
SPI registration doesn’t work
Copy code
// This registration works
Extensions.getRootArea()
    .getExtensionPoint(DiagnosticSuppressor.EP_NAME)
    .registerExtension(YDiagnosticSuppressor())
@dmitriy.novozhilov Do I need to use plugin extension area instead?
d
Sorry, I didn't write any plugins for two years so I forgot some details. For your plugin you need to declare
ComponentRegistrar
service and then register all your extensions in it See how it done in e.g.
allopen
plugin: https://github.com/JetBrains/kotlin/tree/master/plugins/allopen/allopen-cli/resources/META-INF/services https://github.com/JetBrains/kotlin/blob/master/plugins/allopen/allopen-cli/src/AllOpenPlugin.kt#L68
t
Registration in project root doesn’t work as expected 😞 How I can calculate 
KtClass
associated with KtTypeReference?
d
Try to implement
fun isSuppressed(diagnostic: Diagnostic, bindingContext: BindingContext?): Boolean
instead of
fun isSuppressed(diagnostic: Diagnostic): Boolean
Binding context should contain
KotlinType
you want in
TYPE
slice https://github.com/JetBrains/kotlin/blob/master/compiler/frontend/src/org/jetbrains/kotlin/resolve/BindingContext.java#L97
t
What about
ExtensionArea
for suppressor? Could I use
Extensions.getRootArea()
(other extensions use
MockProject.extensionArea
)?
d
I think you should use
MockProject
as other extensions. But it's a assumption since I don't exactly know how this machinery works
t
Looks like
suppress
configuration is global by default (in implementation). Is there anybody who can know exactly?