Hi folks! I got a question regarding @Suppress ann...
# compiler
o
Hi folks! I got a question regarding @Suppress annotations. I am in the middle of migration of many project from Kotlin 1.9.x to Kotlin 2.x right now, with my IntelliJ already swtiched to K2 mode. Now, here are some interesting ones: I often got
@Suppress("UNUSED_PARAMETER")
in my code and now it seems that with K2 enabled, this should now be changed to
@Suppress("unused")
, even as an annotation at the argument itself, not the function. Well, I was curious to read more about this suppression in general and what defines which names for the Suppress annotation are possible. Is it the compiler used, the IntelliJ plugin used, why is is that UNUSED_PARAMTER should now be just unused. My current state came to be because of using quick fixes in IntelliJ in the past, so it was not invented by me to but UNUSED_PARAMETER there... and now, because of the project using Kotlin 1.9.25 I feel like I am stuck in the middle of two chairs...
j
You can put both until one of them survive, not sure if it is a bug or an intentional behavior. About how the new one is reported, I guess it is a FIR checker.
o
Is there any documentation whatsoever for the suppress names? I searched but was not able to find them. I also find it rather strange that they are now existing in two different writing styles: lowercase and screaming snake case. Does not feel good.
🤷 1
(I know I can put both ... But it does not feel right at all)
d
About how the new one is reported, I guess it is a FIR checker.
It's vice-versa. Compiler warnings/errors named in
SNAKE_CASE
Lowercase for IDE inspections
Is there any documentation whatsoever for the suppress names?
If you are looking for specific names, then for compiler diagnostics you can add the
-Xrender-internal-diagnostic-names
compiler arg or enable the intellij internal mode to make these diagnostic names to be reported in the build output/IDE
As for `UNUSED_PARAMETER`: this diagnostic from the compiler was converted to the IDE inspection with K2
o
@dmitriy.novozhilov this is really good to know, thanks! I like that you have a convention that one can understand. But, technically, this transition phase seems awkward. Is there a reason for changing from compiler warning to IDE suppression? Technically, the main reason for me having these suppressions is implementing Java interfaces, where sadly I cannot use
_
as an argument name for a function. Why is that not possible btw?
d
It was decided to move to the IDE the whole family of
UNUSED_
diagnostics to the IDE due to two reasons: • not all unused entities could be detected by the compiler (e.g. unused function) • compiler diagnostics should be reliable and as most precise as possible, but IDE inspections with false-positives are perceived better. And there are corner cases when it really hard to distinguish if something is unusable or not (e.g. some plain property access could have or not have side effects)
Wrong mention BTW
😂 2
👍 1
o
@dmitriy.novozhilov sorry to bother you again about the different suppression IDs... you have explained about uppercase and lowercase, but where do PascalCase suppression codes fit in? E.g. I have an "UNUSED_VARIABLE" which I tried to change to "unused", but this did not work. IntelliJ suggests "UnusedVariable", which also has no effect... Why are there so many differences? What is the correct way to do this?
d
All I can say for sure is about the compiler diagnostics (
SNAKE_CASE
). Don't know actual conventions and possible scenarios in the IDE. I won't be surprised that there could be 3 different naming schemes for inspections (due to the size of intellij project)
u
@dmitriy.novozhilov Hello, found this thread when searching for
UNUSED_PARAMETER
. So - with K2 the compiler doesn't give a warning anymore, if I've understood correctlyy? which means we can't have a CI build fail (with
-Werror)
if we have something like this, right? Is there some way to make it fail again? it was quite useful...
d
Yes, this checker is not implemented in K2 compiler by design. Now it's a ide inspection
u
Is there any known linter we can run that would give an error? ide inspection is really useful and helpful, but sometimes a developer might miss it (looking at myself, earlier today)