Mark implicit receiver as captured if the function is expression

#KT-40260 Fixed
 #KT-42280 Fixed
This commit is contained in:
Ilmir Usmanov
2020-09-30 21:00:26 +02:00
parent 3078bd7b67
commit 5e02a4efd7
10 changed files with 141 additions and 1 deletions
@@ -6523,11 +6523,21 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/coroutines/builderInferenceAndGenericArrayAcessCall.kt");
}
@TestMetadata("captureInfixFun.kt")
public void testCaptureInfixFun() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/captureInfixFun.kt");
}
@TestMetadata("captureMutableLocalVariableInsideCoroutineBlock.kt")
public void testCaptureMutableLocalVariableInsideCoroutineBlock() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/captureMutableLocalVariableInsideCoroutineBlock.kt");
}
@TestMetadata("captureUnaryOperator.kt")
public void testCaptureUnaryOperator() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/captureUnaryOperator.kt");
}
@TestMetadata("capturedVarInSuspendLambda.kt")
public void testCapturedVarInSuspendLambda_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/capturedVarInSuspendLambda.kt", "kotlin.coroutines");
@@ -887,7 +887,9 @@ class ControlFlowInformationProvider private constructor(
}
instruction.next?.let { dfs(it) }
} else if (instruction.element is KtNameReferenceExpression) {
} else if (instruction.element is KtNameReferenceExpression || instruction.element is KtBinaryExpression ||
instruction.element is KtUnaryExpression
) {
val call = instruction.element.getResolvedCall(trace.bindingContext)
if (call is VariableAsFunctionResolvedCall) {
(call.variableCall.dispatchReceiver as? ExtensionReceiver)?.declarationDescriptor?.apply { markIfNeeded() }
@@ -0,0 +1,35 @@
// WITH_RUNTIME
// WITH_COROUTINES
import helpers.*
import kotlin.coroutines.*
fun builder(c: suspend Context.() -> Unit) {
c.startCoroutine(Context(), EmptyContinuation)
}
class Foo {
fun foo() {
val fionaClient = Any()
coVerify { fionaClient was Called }
}
}
object Called
var res = "FAIL"
class Context {
infix fun Any.was(called: Called) {
res = "OK"
}
}
fun coVerify(verifyBlock: suspend Context.() -> Unit) {
builder(verifyBlock)
}
fun box(): String {
Foo().foo()
return res
}
@@ -0,0 +1,33 @@
// WITH_RUNTIME
// WITH_COROUTINES
import helpers.*
import kotlin.coroutines.*
fun builder(c: suspend Context.() -> Unit) {
c.startCoroutine(Context(), EmptyContinuation)
}
class Foo {
fun foo() {
val fionaClient = Any()
coVerify { !fionaClient }
}
}
var res = "FAIL"
class Context {
operator fun Any.not() {
res = "OK"
}
}
fun coVerify(verifyBlock: suspend Context.() -> Unit) {
builder(verifyBlock)
}
fun box(): String {
Foo().foo()
return res
}
@@ -6593,11 +6593,21 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/coroutines/builderInferenceAndGenericArrayAcessCall.kt");
}
@TestMetadata("captureInfixFun.kt")
public void testCaptureInfixFun() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/captureInfixFun.kt");
}
@TestMetadata("captureMutableLocalVariableInsideCoroutineBlock.kt")
public void testCaptureMutableLocalVariableInsideCoroutineBlock() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/captureMutableLocalVariableInsideCoroutineBlock.kt");
}
@TestMetadata("captureUnaryOperator.kt")
public void testCaptureUnaryOperator() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/captureUnaryOperator.kt");
}
@TestMetadata("capturedVarInSuspendLambda.kt")
public void testCapturedVarInSuspendLambda_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/capturedVarInSuspendLambda.kt", "kotlin.coroutines.experimental");
@@ -6593,11 +6593,21 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/coroutines/builderInferenceAndGenericArrayAcessCall.kt");
}
@TestMetadata("captureInfixFun.kt")
public void testCaptureInfixFun() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/captureInfixFun.kt");
}
@TestMetadata("captureMutableLocalVariableInsideCoroutineBlock.kt")
public void testCaptureMutableLocalVariableInsideCoroutineBlock() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/captureMutableLocalVariableInsideCoroutineBlock.kt");
}
@TestMetadata("captureUnaryOperator.kt")
public void testCaptureUnaryOperator() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/captureUnaryOperator.kt");
}
@TestMetadata("capturedVarInSuspendLambda.kt")
public void testCapturedVarInSuspendLambda_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/capturedVarInSuspendLambda.kt", "kotlin.coroutines.experimental");
@@ -6523,11 +6523,21 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/coroutines/builderInferenceAndGenericArrayAcessCall.kt");
}
@TestMetadata("captureInfixFun.kt")
public void testCaptureInfixFun() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/captureInfixFun.kt");
}
@TestMetadata("captureMutableLocalVariableInsideCoroutineBlock.kt")
public void testCaptureMutableLocalVariableInsideCoroutineBlock() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/captureMutableLocalVariableInsideCoroutineBlock.kt");
}
@TestMetadata("captureUnaryOperator.kt")
public void testCaptureUnaryOperator() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/captureUnaryOperator.kt");
}
@TestMetadata("capturedVarInSuspendLambda.kt")
public void testCapturedVarInSuspendLambda_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/capturedVarInSuspendLambda.kt", "kotlin.coroutines");
@@ -5403,11 +5403,21 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
runTest("compiler/testData/codegen/box/coroutines/builderInferenceAndGenericArrayAcessCall.kt");
}
@TestMetadata("captureInfixFun.kt")
public void testCaptureInfixFun() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/captureInfixFun.kt");
}
@TestMetadata("captureMutableLocalVariableInsideCoroutineBlock.kt")
public void testCaptureMutableLocalVariableInsideCoroutineBlock() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/captureMutableLocalVariableInsideCoroutineBlock.kt");
}
@TestMetadata("captureUnaryOperator.kt")
public void testCaptureUnaryOperator() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/captureUnaryOperator.kt");
}
@TestMetadata("capturedVarInSuspendLambda.kt")
public void testCapturedVarInSuspendLambda_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/capturedVarInSuspendLambda.kt", "kotlin.coroutines");
@@ -5403,11 +5403,21 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/coroutines/builderInferenceAndGenericArrayAcessCall.kt");
}
@TestMetadata("captureInfixFun.kt")
public void testCaptureInfixFun() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/captureInfixFun.kt");
}
@TestMetadata("captureMutableLocalVariableInsideCoroutineBlock.kt")
public void testCaptureMutableLocalVariableInsideCoroutineBlock() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/captureMutableLocalVariableInsideCoroutineBlock.kt");
}
@TestMetadata("captureUnaryOperator.kt")
public void testCaptureUnaryOperator() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/captureUnaryOperator.kt");
}
@TestMetadata("capturedVarInSuspendLambda.kt")
public void testCapturedVarInSuspendLambda_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/capturedVarInSuspendLambda.kt", "kotlin.coroutines");
@@ -5403,11 +5403,21 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/coroutines/builderInferenceAndGenericArrayAcessCall.kt");
}
@TestMetadata("captureInfixFun.kt")
public void testCaptureInfixFun() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/captureInfixFun.kt");
}
@TestMetadata("captureMutableLocalVariableInsideCoroutineBlock.kt")
public void testCaptureMutableLocalVariableInsideCoroutineBlock() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/captureMutableLocalVariableInsideCoroutineBlock.kt");
}
@TestMetadata("captureUnaryOperator.kt")
public void testCaptureUnaryOperator() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/captureUnaryOperator.kt");
}
@TestMetadata("capturedVarInSuspendLambda.kt")
public void testCapturedVarInSuspendLambda_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/capturedVarInSuspendLambda.kt", "kotlin.coroutines");