Generate last expression in coroutine block even for Unit expected type
This commit is contained in:
@@ -1745,7 +1745,8 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
assert resolvedCall.getValueArgumentsByIndex() != null : "Arguments were not resolved for call element: " + callOwner.getText();
|
||||
KtExpression argumentExpression =
|
||||
resolvedCall.getValueArgumentsByIndex().get(0).getArguments().get(0).getArgumentExpression();
|
||||
if (KotlinBuiltIns.isUnit(resolvedCall.getResultingDescriptor().getValueParameters().get(0).getType())) {
|
||||
if (valueToReturn == null
|
||||
&& KotlinBuiltIns.isUnit(resolvedCall.getResultingDescriptor().getValueParameters().get(0).getType())) {
|
||||
tempVariables.put(argumentExpression, StackValue.unit());
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
class Controller {
|
||||
var ok = false
|
||||
var v = "fail"
|
||||
suspend fun suspendHere(v: String, x: Continuation<Unit>) {
|
||||
this.v = v
|
||||
x.resume(Unit)
|
||||
}
|
||||
|
||||
operator fun handleResult(u: Unit, v: Continuation<Nothing>) {
|
||||
ok = true
|
||||
}
|
||||
}
|
||||
|
||||
fun builder(coroutine c: Controller.() -> Continuation<Unit>): String {
|
||||
val controller = Controller()
|
||||
c(controller).resume(Unit)
|
||||
if (!controller.ok) throw java.lang.RuntimeException("Fail 1")
|
||||
return controller.v
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
|
||||
return builder {
|
||||
suspendHere("OK")
|
||||
}
|
||||
}
|
||||
@@ -4183,6 +4183,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("lastUnitExpression.kt")
|
||||
public void testLastUnitExpression() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/lastUnitExpression.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("manualContinuationImpl.kt")
|
||||
public void testManualContinuationImpl() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/manualContinuationImpl.kt");
|
||||
|
||||
Reference in New Issue
Block a user