Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnnecessaryEventHandlerParameter raises an exception #14

Closed
BraisGabin opened this issue Jul 25, 2022 · 1 comment
Closed

UnnecessaryEventHandlerParameter raises an exception #14

BraisGabin opened this issue Jul 25, 2022 · 1 comment

Comments

@BraisGabin
Copy link
Contributor

BraisGabin commented Jul 25, 2022

I wanted to Suppress an issue raised by UnnecessaryEventHandlerParameter because it is a false positive (more about this in #13)

But when I add the @Suppress to the parameter like this:

@Composable
internal fun MyButton(
    state: State,
    @Suppress("UnnecessaryEventHandlerParameter") onClick: (String) -> Unit,
) {
    when (state) {
        State.Loading -> Text("Loading")
        is State.Data -> Button(onClick = { onClick(state.id) }) { Text("Click here") }
    }
}

I'm getting this exception:

> Analyzing /Users/brais.gabin/Workspace/lidl/features/selfscanning/src/main/java/es/lidlplus/features/selfscanning/checkout/AA.kt led to an exception.
  Location: ru.kode.detekt.rule.compose.UnnecessaryEventHandlerParameter$UnnecessaryHandlerArgumentsVisitor.reportError(UnnecessaryEventHandlerParameter.kt:114)
  The original exception message was: class org.jetbrains.kotlin.psi.KtDeclarationModifierList cannot be cast to class org.jetbrains.kotlin.psi.KtTypeReference (org.jetbrains.kotlin.psi.KtDeclarationModifierList and org.jetbrains.kotlin.psi.KtTypeReference are in unnamed module of loader java.net.URLClassLoader @54724ee9)
  Running detekt '1.21.0-RC2' on Java '11.0.11+9' on OS 'Mac OS X'

The interesting part of the stack trace is this:

Caused by: java.lang.ClassCastException: class org.jetbrains.kotlin.psi.KtDeclarationModifierList cannot be cast to class org.jetbrains.kotlin.psi.KtTypeReference (org.jetbrains.kotlin.psi.KtDeclarationModifierList and org.jetbrains.kotlin.psi.KtTypeReference are in unnamed module of loader java.net.URLClassLoader @54724ee9)
        at ru.kode.detekt.rule.compose.UnnecessaryEventHandlerParameter$UnnecessaryHandlerArgumentsVisitor.reportError(UnnecessaryEventHandlerParameter.kt:114)
        at ru.kode.detekt.rule.compose.UnnecessaryEventHandlerParameter$UnnecessaryHandlerArgumentsVisitor.visitCallExpression(UnnecessaryEventHandlerParameter.kt:107)

If I set the suppress at the function level all works as expected.

@dimsuz
Copy link
Collaborator

dimsuz commented Jul 25, 2022

Looks like I was overly specific/optimistic about psi structure somewhere. I will take a look!

@dimsuz dimsuz closed this as completed in 2f549d9 Aug 4, 2022
dimsuz added a commit that referenced this issue Aug 4, 2022
Was playing with test reproduction and accidentally commited the wrong
sample as part of the fix for #14

Correcting :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants