Loops without bodies are reported as having redundant semicolons


#1

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.


#2

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


#3

Use “do while” for clarity

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

otherwise

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

#4

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