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

UnnecessaryNotNullCheck: fix false negative with smart casted arguments #5380

Merged
merged 3 commits into from Oct 9, 2022

Conversation

t-kameyama
Copy link
Contributor

Fixes #5379

Copy link
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!


fun KotlinType.fqNameOrNull(): FqName? {
return TypeUtils.getClassDescriptor(this)?.fqNameOrNull()
}

@Suppress("ReturnCount")
fun KtExpression.getDataFlowAwareTypes(
Copy link
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
Contributor Author

Choose a reason for hiding this comment

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

@@ -86,21 +87,22 @@ class NullableToStringCall(config: Config = Config.empty) : Rule(config) {
}

private fun KtExpression.isNullable(): Boolean {
if (bindingContext == BindingContext.EMPTY) return false
Copy link
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

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.

@BraisGabin BraisGabin added this to the 1.22.0 milestone Oct 6, 2022
@chao2zhang chao2zhang 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