kotlin compiler (from 1.6.0-M1 back to at least 1.4.32)
Description
While loop is decompiled incorrectly with kotlin elvis operator. Value returned from operator is not assigned to variable, as per attached example.
Example
Test.kt
import java.util.Queue
class Test {
fun processAll(q: Queue<String>) {
while (true) {
val item = q.poll() ?: break
process(item)
}
}
private fun process(item: String) {
}
}
Decompiled
/*
* Decompiled with CFR 0.151.
*/
import java.util.Queue;
import kotlin.Metadata;
import kotlin.jvm.internal.Intrinsics;
import org.jetbrains.annotations.NotNull;
@Metadata(/* omitted for brevity */)
public final class Test {
public final void processAll(@NotNull Queue<String> q) {
Intrinsics.checkNotNullParameter(q, "q");
while (q.poll() != null) {
String item;
this.process(item);
}
}
private final void process(String item) {
}
}
CFR version
0.151
Compiler
kotlin compiler (from 1.6.0-M1 back to at least 1.4.32)
Description
While loop is decompiled incorrectly with kotlin elvis operator. Value returned from operator is not assigned to variable, as per attached example.
Example
Test.kt
Decompiled
javap -c
outputCuriously, it only happens when elvis operator is used. Changing the loop to equivalent:
decompiles correctly.