Loops without bodies are reported as having redundant semicolons

Not that great of an issue, but I tend to judge the “cleanness” of my projects based on the presence of any warnings.

Found this while messing with Xuggler.

If I write

fun foo() {
    ...
    while(reader.readPacket() == null);
}

IntelliJ tells me that the semicolon is redundant and suggests that I remove it.

If I remove it, however, this is obviously invalid as the loop has no body.

This isn’t really great code, but in any case the suggestion is invalid. You should probably file a bug on youtrack.

Use “do while” for clarity

fun foo() {
    ...
    do while(reader.readPacket() == null)
}

otherwise

fun foo() {
    ...
    while(reader.readPacket() == null) Unit
}
1 Like

https://youtrack.jetbrains.com/issue/KT-12805