-
Notifications
You must be signed in to change notification settings - Fork 39
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
Removing complex cases from the warning related to null checks #532
Conversation
### What's done: Null check will not trigger on the following code: 1) if (myVar == null || otherValue == 5 && isValid) {} 2) if (myVar != null) { println("not null") } else if (true) { println("Other condition") }
Codecov Report
@@ Coverage Diff @@
## master #532 +/- ##
============================================
- Coverage 81.93% 81.88% -0.05%
- Complexity 1637 1641 +4
============================================
Files 78 78
Lines 4123 4129 +6
Branches 1302 1306 +4
============================================
+ Hits 3378 3381 +3
Misses 219 219
- Partials 526 529 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
val parentIfPsi = parentIf.psi | ||
require(parentIfPsi is KtIfExpression) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
val parentIfPsi = parentIf.psi | |
require(parentIfPsi is KtIfExpression) | |
val parentIfPsi = parentIf.psi as KtIfExpression |
Is require
here only for smart cast? You already have element type check above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, I also wanted to prohibit other KtElements in this method
* checks if condition is a complex expression. For example: | ||
* (a == 5) - is not a complex condition, but (a == 5 && b != 6) is a complex condition | ||
*/ | ||
private fun KtBinaryExpression.isComplexCondition(): Boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this function is called for every BINARY_EXPRESSION
in a CONDITION
, then you could encounter situation like if (foo.bar(x == null))
which is a complex statement but won't be detected by your code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as we discussed - we don't like to raise warnings on such complex cases. I even should remove part of it
I discovered that this rule currently reports simple comparisons as errors too: val isDefault = configuration == null yields
Create #550 for this |
Co-authored-by: Peter Trifanov <peter.trifanov@mail.ru>
What's done:
Null check will not trigger on the following code:
println("not null")
} else if (true) {
println("Other condition")
}