Skip to content

UnnecessaryNotNullCheck: fix false negative with smart casted arguments#5380

Merged
picklebento merged 3 commits intodetekt:mainfrom
t-kameyama:issue_5379
Oct 9, 2022
Merged

UnnecessaryNotNullCheck: fix false negative with smart casted arguments#5380
picklebento merged 3 commits intodetekt:mainfrom
t-kameyama:issue_5379

Conversation

@t-kameyama
Copy link
Copy Markdown
Contributor

Fixes #5379

Copy link
Copy Markdown
Member

@cortinico cortinico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff!

}

@Suppress("ReturnCount")
fun KtExpression.getDataFlowAwareTypes(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a comment on this function with a couple of example of what it does?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

private fun KtExpression.isNullable(): Boolean {
if (bindingContext == BindingContext.EMPTY) return false
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (bindingContext == BindingContext.EMPTY) return false

The rules annotated with @RequiresTypeResolution are not called by the core if the BindingContext is empty so we don't need this line any more.

@codecov
Copy link
Copy Markdown

codecov Bot commented Oct 6, 2022

Codecov Report

Merging #5380 (0ee3d04) into main (f87a72d) will increase coverage by 86.08%.
The diff coverage is 68.42%.

❗ Current head 0ee3d04 differs from pull request most recent head 3cdd9ac. Consider uploading reports for the commit 3cdd9ac to get more accurate results

@@             Coverage Diff             @@
##             main    #5380       +/-   ##
===========================================
+ Coverage        0   86.08%   +86.08%     
- Complexity      0     3642     +3642     
===========================================
  Files           0      515      +515     
  Lines           0    12101    +12101     
  Branches        0     2166     +2166     
===========================================
+ Hits            0    10417    +10417     
- Misses          0      611      +611     
- Partials        0     1073     +1073     
Impacted Files Coverage Δ
...lin/io/gitlab/arturbosch/detekt/rules/TypeUtils.kt 53.33% <50.00%> (ø)
...turbosch/detekt/rules/bugs/NullableToStringCall.kt 85.71% <71.42%> (ø)
...bosch/detekt/rules/bugs/UnnecessaryNotNullCheck.kt 88.46% <82.35%> (ø)
...otlin/io/github/detekt/metrics/ComplexityMetric.kt 100.00% <0.00%> (ø)
...turbosch/detekt/rules/documentation/CommentUtil.kt 100.00% <0.00%> (ø)
.../io/gitlab/arturbosch/detekt/cli/runners/Runner.kt 100.00% <0.00%> (ø)
...arturbosch/detekt/generator/collection/KDocTags.kt 100.00% <0.00%> (ø)
...gitlab/arturbosch/detekt/api/AnnotationExcluder.kt 91.89% <0.00%> (ø)
...hub/detekt/metrics/processors/AbstractProcessor.kt 100.00% <0.00%> (ø)
...rturbosch/detekt/rules/style/OptionalWhenBraces.kt 94.11% <0.00%> (ø)
... and 508 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@t-kameyama t-kameyama requested a review from BraisGabin October 6, 2022 13:19
@BraisGabin BraisGabin added this to the 1.22.0 milestone Oct 6, 2022
@picklebento picklebento merged commit 2e229ec into detekt:main Oct 9, 2022
@t-kameyama t-kameyama deleted the issue_5379 branch October 9, 2022 06:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UnnecessaryNotNullCheck: false negative with smart casted arguments

4 participants