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

UnnecessaryParentheses false positive with in and ?: #5136

Closed
Gama11 opened this issue Jul 26, 2022 · 3 comments
Closed

UnnecessaryParentheses false positive with in and ?: #5136

Gama11 opened this issue Jul 26, 2022 · 3 comments

Comments

@Gama11
Copy link

Gama11 commented Jul 26, 2022

The following snippet triggers the UnnecessaryParentheses rule:

try {
} catch (e: Exception) {
    if ("foo" in (e.message ?: "")) {}
}

However, they're not in fact unnecessary:

image

Your Environment

  • Version of detekt used: 1.21.0
  • Version of Gradle used (if applicable): 7.5
  • Operating System and version: Windows 10 (19044.1766)
@BraisGabin
Copy link
Member

BraisGabin commented Aug 7, 2022

I can reproduce it with this unit test:

    @ParameterizedTest
    @MethodSource("cases")
    fun `with unnecessary parentheses on aval assignment`(testCase: RuleTestCase) {
        val code = """val a = if ("foo" in (null ?: "")) 1 else 2"""

        assertThat(testCase.rule.lint(code)).hasSize(0)
    }

But the issue seems to be in KtPsiUtil.areParenthesesUseless. I imagine that this will be solved in the compiler and we will be able to use the fix. But I'm not sure where to report this to be sure that this is fixed.

#4881 would be used as a workaround to this issue if you enable allowForUnclearPrecedence. But that's not released yet and as I said, it's just a workaround.

@github-actions
Copy link

github-actions bot commented Nov 6, 2022

This issue is stale because it has been open 90 days with no activity. Please comment or this will be closed in 7 days.

@github-actions github-actions bot added the stale label Nov 6, 2022
@BraisGabin
Copy link
Member

This is still an issue right now. But I feel that there is no way to do something about it. Any idea is more than welcome.

But, because this is not actionable, I'm closing it.

@BraisGabin BraisGabin closed this as not planned Won't fix, can't repro, duplicate, stale Nov 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants