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

Fix false-negative for CanBeNonNullable #4993

Merged
merged 3 commits into from Jun 24, 2022

Conversation

VitalyVPinchuk
Copy link
Contributor

For #4492
Report code smell when null-check expression returns 'Unit'

The rule will report code smell when null-check expression returns 'Unit'
# Conflicts:
#	detekt-rules-style/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/style/CanBeNonNullable.kt
@marschwar
Copy link
Contributor

How about this example? If there is any side effect before the guard statement it should not report an issue, right?

fun foo(a: Int?) {
    println("side effect")
    if (a == null) return
    println(a)
}

@VitalyVPinchuk
Copy link
Contributor Author

Hmm... I didn't think of it.
We'll lose part of the side effect if we make parameter non-nullable. Probably, it's better not to report such a case...
Give your thoughts, please

@marschwar
Copy link
Contributor

That was exactly my thought. I would not report if there is any side effect before the guard statement. Since detecting if it really is a side effect would be hard, I would not allow anything before the guard.

@VitalyVPinchuk
Copy link
Contributor Author

You're right. I'll fix it.

@BraisGabin BraisGabin merged commit 4742842 into detekt:main Jun 24, 2022
@cortinico cortinico added this to the 1.21.0 milestone Jun 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants