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

UselessCallOnNotNull: fix false positive for unresolved types #4880

Merged
merged 1 commit into from
Jun 1, 2022
Merged

UselessCallOnNotNull: fix false positive for unresolved types #4880

merged 1 commit into from
Jun 1, 2022

Conversation

dzirbel
Copy link
Contributor

@dzirbel dzirbel commented May 31, 2022

Fix an issue where UselessCallOnNotNull would report issues when some of the argument types resolved as ErrorType. While it correctly handles cases where the BindingContext cannot resolve a type (the first test case), in cases where a call is made on an unknown type (the second test case, e.g. via takeIf{}) the BindingContext will report it as an ErrorType. Since ErrorType.isNullable() apparently returns false we need to make an exception to ensure the rule behaves as expected.

@github-actions github-actions bot added the rules label May 31, 2022
@codecov
Copy link

codecov bot commented May 31, 2022

Codecov Report

Merging #4880 (7626f69) into main (b2ef7a6) will increase coverage by 0.00%.
The diff coverage is 80.00%.

@@            Coverage Diff            @@
##               main    #4880   +/-   ##
=========================================
  Coverage     84.81%   84.82%           
- Complexity     3463     3467    +4     
=========================================
  Files           493      493           
  Lines         11355    11359    +4     
  Branches       2090     2092    +2     
=========================================
+ Hits           9631     9635    +4     
- Misses          674      675    +1     
+ Partials       1050     1049    -1     
Impacted Files Coverage Δ
...urbosch/detekt/rules/style/UselessCallOnNotNull.kt 91.66% <80.00%> (+2.53%) ⬆️
...etekt/generator/printer/defaultconfig/Exclusion.kt 93.93% <0.00%> (-2.84%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b2ef7a6...7626f69. Read the comment docs.

Fix an issue where UselessCallOnNotNull would report issues when some of the argument types resolved as ErrorType. While it correctly handles cases where the BindingContext cannot resolve a type (the first test case), in cases where a call is made on an unknown type (the second test case, e.g. via takeIf{}) the BindingContext will report it as an ErrorType. Since ErrorType.isNullable() apparently returns false we need to make an exception to ensure the rule behaves as expected.
@cortinico cortinico added this to the 1.21.0 milestone Jun 1, 2022
@schalkms schalkms merged commit db0b4b5 into detekt:main Jun 1, 2022
@dzirbel dzirbel deleted the listOfNotNullUnknownType branch June 1, 2022 18:09
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.

4 participants