-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Incorrect fix of null-safety rule (#857)
* Incorrect fix of null-safety rule ### What's done: Fixed bug, changed logic Created tests
- Loading branch information
Showing
7 changed files
with
296 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
diktat-rules/src/test/resources/test/paragraph4/null_checks/IfConditionBreakCheckExpected.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package test.paragraph4.null_checks | ||
|
||
|
||
fun foo() { | ||
var result: Int? = 19 | ||
while(result != 0 ) { | ||
if (result == null) { | ||
foo() | ||
} else { | ||
break | ||
} | ||
} | ||
} | ||
|
||
fun foo() { | ||
var result: Int? = 19 | ||
while(result != 0 ) { | ||
result?.let { | ||
foo() | ||
} ?: break | ||
} | ||
} | ||
|
||
fun foo() { | ||
var result: Int? = 19 | ||
while(result != 0 ) { | ||
if (result != null) { | ||
break | ||
} else { | ||
foo() | ||
} | ||
} | ||
} | ||
|
||
fun foo() { | ||
var result: Int? = 19 | ||
while(result != 0 ) { | ||
result?.let { | ||
foo() | ||
} ?: break | ||
} | ||
} | ||
|
||
fun foo() { | ||
var result: Int? = 19 | ||
while(result != 0 ) { | ||
result ?: break | ||
} | ||
} | ||
|
||
fun foo() { | ||
var result: Int? = 19 | ||
while(result != 0 ) { | ||
if (result != null) { | ||
break | ||
} | ||
} | ||
} | ||
|
||
fun foo() { | ||
var result: Int? = 19 | ||
while(result != 0 ) { | ||
if (result != null) { | ||
foo() | ||
break | ||
} else { | ||
break | ||
} | ||
} | ||
} | ||
|
||
fun foo() { | ||
var result: Int? = 19 | ||
while(result != 0 ) { | ||
if (result != null) { | ||
result?.let { | ||
goo() | ||
} ?: break | ||
} else { | ||
break | ||
} | ||
} | ||
} | ||
|
92 changes: 92 additions & 0 deletions
92
diktat-rules/src/test/resources/test/paragraph4/null_checks/IfConditionBreakCheckTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package test.paragraph4.null_checks | ||
|
||
|
||
fun foo() { | ||
var result: Int? = 19 | ||
while(result != 0 ) { | ||
if (result == null) { | ||
foo() | ||
} else { | ||
break | ||
} | ||
} | ||
} | ||
|
||
fun foo() { | ||
var result: Int? = 19 | ||
while(result != 0 ) { | ||
if (result == null) { | ||
break | ||
} else { | ||
foo() | ||
} | ||
} | ||
} | ||
|
||
fun foo() { | ||
var result: Int? = 19 | ||
while(result != 0 ) { | ||
if (result != null) { | ||
break | ||
} else { | ||
foo() | ||
} | ||
} | ||
} | ||
|
||
fun foo() { | ||
var result: Int? = 19 | ||
while(result != 0 ) { | ||
if (result != null) { | ||
foo() | ||
} else { | ||
break | ||
} | ||
} | ||
} | ||
|
||
fun foo() { | ||
var result: Int? = 19 | ||
while(result != 0 ) { | ||
if (result == null) { | ||
break | ||
} | ||
} | ||
} | ||
|
||
fun foo() { | ||
var result: Int? = 19 | ||
while(result != 0 ) { | ||
if (result != null) { | ||
break | ||
} | ||
} | ||
} | ||
|
||
fun foo() { | ||
var result: Int? = 19 | ||
while(result != 0 ) { | ||
if (result != null) { | ||
foo() | ||
break | ||
} else { | ||
break | ||
} | ||
} | ||
} | ||
|
||
fun foo() { | ||
var result: Int? = 19 | ||
while(result != 0 ) { | ||
if (result != null) { | ||
if (result != null) { | ||
goo() | ||
} else { | ||
break | ||
} | ||
} else { | ||
break | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
076ec56
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.
I wasn't able to retrieve PDD puzzles from the code base and submit them to GitHub. If you think that it's a bug on our side, please submit it to yegor256/0pdd:
Please, copy and paste this stack trace to GitHub: