Make 'controller' field package-private
To make it accessible from nested lambdas #KT-12974 Fixed
This commit is contained in:
@@ -58,7 +58,7 @@ class CoroutineCodegen(
|
|||||||
|
|
||||||
override fun generateClosureBody() {
|
override fun generateClosureBody() {
|
||||||
v.newField(
|
v.newField(
|
||||||
JvmDeclarationOrigin.NO_ORIGIN, Opcodes.ACC_PRIVATE or Opcodes.ACC_VOLATILE,
|
JvmDeclarationOrigin.NO_ORIGIN, AsmUtil.NO_FLAG_PACKAGE_PRIVATE or Opcodes.ACC_VOLATILE,
|
||||||
COROUTINE_CONTROLLER_FIELD_NAME,
|
COROUTINE_CONTROLLER_FIELD_NAME,
|
||||||
typeMapper.mapType(controllerType).descriptor, null, null)
|
typeMapper.mapType(controllerType).descriptor, null, null)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
class Controller {
|
||||||
|
var result = false
|
||||||
|
suspend fun suspendHere(x: Continuation<String>) {
|
||||||
|
x.resume("OK")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
result = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun builder(coroutine c: Controller.() -> Continuation<Unit>) {
|
||||||
|
val controller = Controller()
|
||||||
|
c(controller).resume(Unit)
|
||||||
|
if (!controller.result) throw java.lang.RuntimeException("fail")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun noinlineRun(block: () -> Unit) {
|
||||||
|
block()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
builder {
|
||||||
|
if (suspendHere() != "OK") {
|
||||||
|
throw java.lang.RuntimeException("fail 1")
|
||||||
|
}
|
||||||
|
noinlineRun {
|
||||||
|
foo()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (suspendHere() != "OK") {
|
||||||
|
throw java.lang.RuntimeException("fail 2")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -4153,6 +4153,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/coroutines"), Pattern.compile("^(.+)\\.kt$"), true);
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/coroutines"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("controllerAccessFromInnerLambda.kt")
|
||||||
|
public void testControllerAccessFromInnerLambda() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/controllerAccessFromInnerLambda.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("defaultParametersInSuspend.kt")
|
@TestMetadata("defaultParametersInSuspend.kt")
|
||||||
public void testDefaultParametersInSuspend() throws Exception {
|
public void testDefaultParametersInSuspend() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/defaultParametersInSuspend.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/defaultParametersInSuspend.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user