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

Incorrect fix of null-safety rule #818

Closed
kgevorkyan opened this issue Apr 2, 2021 · 1 comment · Fixed by #857
Closed

Incorrect fix of null-safety rule #818

kgevorkyan opened this issue Apr 2, 2021 · 1 comment · Fixed by #857
Assignees
Labels
bug Something isn't working

Comments

@kgevorkyan
Copy link
Member

kgevorkyan commented Apr 2, 2021

Describe the bug

Consider the following code:

while (someCondition) {
    result = someFunction()
    if (result != null) {
        doSomething()
    } else {
        break
    }
}

Expected behavior

TBD

After the mvn diktat:fix@diktat this block changes to the following, which couldn't be compiled:

Observed behavior

while (someCondition) {
    result = someFunction()
    result ?.let {
        doSomething()
    }
        ?: run {
            break
        }
}

Error: break or continue jumps across a function or a class boundary

@kgevorkyan kgevorkyan added the bug Something isn't working label Apr 2, 2021
@petertrr
Copy link
Member

Another note: we should not wrap single statements in run when fixing such issues. The provided example will then be fine: ?: break compiles. If there is any logic before break, though, it'll still not work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants