[NI] Fix recording info about captured local variables
This commit is contained in:
+5
-4
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.resolve.calls.inference
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor
|
||||
import org.jetbrains.kotlin.resolve.BindingTrace
|
||||
import org.jetbrains.kotlin.resolve.MissingSupertypesResolver
|
||||
import org.jetbrains.kotlin.resolve.TemporaryBindingTrace
|
||||
@@ -90,10 +91,10 @@ class CoroutineInferenceSession(
|
||||
}
|
||||
|
||||
private fun skipCall(callInfo: SingleCallResolutionResult): Boolean {
|
||||
// FakeCallableDescriptorForObject can't introduce new information for inference, so it's safe to complete it fully
|
||||
if (callInfo.resultCallAtom.candidateDescriptor is FakeCallableDescriptorForObject) return true
|
||||
|
||||
return false
|
||||
// FakeCallableDescriptorForObject and LocalVariableDescriptor can't introduce new information for inference,
|
||||
// so it's safe to complete it fully
|
||||
val descriptor = callInfo.resultCallAtom.candidateDescriptor
|
||||
return descriptor is FakeCallableDescriptorForObject || descriptor is LocalVariableDescriptor
|
||||
}
|
||||
|
||||
override fun currentConstraintSystem(): ConstraintStorage {
|
||||
|
||||
Vendored
+44
@@ -0,0 +1,44 @@
|
||||
// WITH_RUNTIME
|
||||
// WITH_COROUTINES
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
|
||||
import helpers.*
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
import kotlin.test.*
|
||||
|
||||
fun testLaziness() {
|
||||
var sharedVar = -2
|
||||
val result = sequence {
|
||||
while (true) {
|
||||
when (sharedVar) {
|
||||
-1 -> return@sequence
|
||||
-2 -> error("Invalid state: -2")
|
||||
else -> yield(sharedVar)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val iterator = result.iterator()
|
||||
|
||||
sharedVar = 1
|
||||
assertTrue(iterator.hasNext())
|
||||
assertEquals(1, iterator.next())
|
||||
|
||||
sharedVar = 2
|
||||
assertTrue(iterator.hasNext())
|
||||
assertEquals(2, iterator.next())
|
||||
|
||||
sharedVar = 3
|
||||
assertTrue(iterator.hasNext())
|
||||
assertEquals(3, iterator.next())
|
||||
|
||||
sharedVar = -1
|
||||
assertFalse(iterator.hasNext())
|
||||
assertFailsWith<NoSuchElementException> { iterator.next() }
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
testLaziness()
|
||||
return "OK"
|
||||
}
|
||||
+10
@@ -6052,6 +6052,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/coroutines/builderInferenceAndGenericArrayAcessCall.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("captureMutableLocalVariableInsideCoroutineBlock.kt")
|
||||
public void testCaptureMutableLocalVariableInsideCoroutineBlock() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/coroutines/captureMutableLocalVariableInsideCoroutineBlock.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("capturedVarInSuspendLambda.kt")
|
||||
public void testCapturedVarInSuspendLambda_1_2() throws Exception {
|
||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/capturedVarInSuspendLambda.kt", "kotlin.coroutines.experimental");
|
||||
@@ -12697,6 +12702,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/inference/capturedStarProjection.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("coercionToUnitWithNestedLambda.kt")
|
||||
public void testCoercionToUnitWithNestedLambda() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inference/coercionToUnitWithNestedLambda.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("integerLiteralTypeInLamdaReturnType.kt")
|
||||
public void testIntegerLiteralTypeInLamdaReturnType() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inference/integerLiteralTypeInLamdaReturnType.kt");
|
||||
|
||||
+10
@@ -6052,6 +6052,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/coroutines/builderInferenceAndGenericArrayAcessCall.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("captureMutableLocalVariableInsideCoroutineBlock.kt")
|
||||
public void testCaptureMutableLocalVariableInsideCoroutineBlock() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/coroutines/captureMutableLocalVariableInsideCoroutineBlock.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("capturedVarInSuspendLambda.kt")
|
||||
public void testCapturedVarInSuspendLambda_1_2() throws Exception {
|
||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/capturedVarInSuspendLambda.kt", "kotlin.coroutines.experimental");
|
||||
@@ -12697,6 +12702,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/inference/capturedStarProjection.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("coercionToUnitWithNestedLambda.kt")
|
||||
public void testCoercionToUnitWithNestedLambda() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inference/coercionToUnitWithNestedLambda.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("integerLiteralTypeInLamdaReturnType.kt")
|
||||
public void testIntegerLiteralTypeInLamdaReturnType() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inference/integerLiteralTypeInLamdaReturnType.kt");
|
||||
|
||||
+10
@@ -5987,6 +5987,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/coroutines/builderInferenceAndGenericArrayAcessCall.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("captureMutableLocalVariableInsideCoroutineBlock.kt")
|
||||
public void testCaptureMutableLocalVariableInsideCoroutineBlock() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/coroutines/captureMutableLocalVariableInsideCoroutineBlock.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("capturedVarInSuspendLambda.kt")
|
||||
public void testCapturedVarInSuspendLambda_1_3() throws Exception {
|
||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/capturedVarInSuspendLambda.kt", "kotlin.coroutines");
|
||||
@@ -11572,6 +11577,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/inference/capturedStarProjection.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("coercionToUnitWithNestedLambda.kt")
|
||||
public void testCoercionToUnitWithNestedLambda() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inference/coercionToUnitWithNestedLambda.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("integerLiteralTypeInLamdaReturnType.kt")
|
||||
public void testIntegerLiteralTypeInLamdaReturnType() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inference/integerLiteralTypeInLamdaReturnType.kt");
|
||||
|
||||
+10
@@ -5987,6 +5987,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/coroutines/builderInferenceAndGenericArrayAcessCall.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("captureMutableLocalVariableInsideCoroutineBlock.kt")
|
||||
public void testCaptureMutableLocalVariableInsideCoroutineBlock() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/coroutines/captureMutableLocalVariableInsideCoroutineBlock.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("capturedVarInSuspendLambda.kt")
|
||||
public void testCapturedVarInSuspendLambda_1_3() throws Exception {
|
||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/capturedVarInSuspendLambda.kt", "kotlin.coroutines");
|
||||
@@ -11572,6 +11577,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/inference/capturedStarProjection.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("coercionToUnitWithNestedLambda.kt")
|
||||
public void testCoercionToUnitWithNestedLambda() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inference/coercionToUnitWithNestedLambda.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("integerLiteralTypeInLamdaReturnType.kt")
|
||||
public void testIntegerLiteralTypeInLamdaReturnType() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inference/integerLiteralTypeInLamdaReturnType.kt");
|
||||
|
||||
Generated
+5
@@ -5047,6 +5047,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/coroutines/builderInferenceAndGenericArrayAcessCall.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("captureMutableLocalVariableInsideCoroutineBlock.kt")
|
||||
public void testCaptureMutableLocalVariableInsideCoroutineBlock() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/coroutines/captureMutableLocalVariableInsideCoroutineBlock.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("capturedVarInSuspendLambda.kt")
|
||||
public void testCapturedVarInSuspendLambda_1_3() throws Exception {
|
||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/capturedVarInSuspendLambda.kt", "kotlin.coroutines");
|
||||
|
||||
+5
@@ -5047,6 +5047,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/coroutines/builderInferenceAndGenericArrayAcessCall.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("captureMutableLocalVariableInsideCoroutineBlock.kt")
|
||||
public void testCaptureMutableLocalVariableInsideCoroutineBlock() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/coroutines/captureMutableLocalVariableInsideCoroutineBlock.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("capturedVarInSuspendLambda.kt")
|
||||
public void testCapturedVarInSuspendLambda_1_3() throws Exception {
|
||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/capturedVarInSuspendLambda.kt", "kotlin.coroutines");
|
||||
|
||||
Reference in New Issue
Block a user