Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Compilation error due to function-expression-body #2269

Closed
paul-dingemans opened this issue Sep 20, 2023 · 0 comments · Fixed by #2273
Closed

Compilation error due to function-expression-body #2269

paul-dingemans opened this issue Sep 20, 2023 · 0 comments · Fixed by #2273

Comments

@paul-dingemans
Copy link
Collaborator

Given code below:

fun foo(): Any {
    return if (true) {
        Foo()
    } else {
        return Bar()
    }
}

this is formatted by Ktlint 1.0.0 (with experimental enabled) to:

fun foo(): Any =
    if (true) {
        Foo()
    } else {
        return Bar()
    }

and results in a compilation error as a body expression may not contain a return statement

@paul-dingemans paul-dingemans added this to the 1.0.1 milestone Sep 20, 2023
paul-dingemans added a commit that referenced this issue Sep 23, 2023
…he return statement contains an intermediate exit point

Closes #2269
paul-dingemans added a commit that referenced this issue Sep 23, 2023
* Do not replace function body having a return statement only in case the return statement contains an intermediate exit point

Closes #2269
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant