[NI] Fix checking for the same instance inside for suspend functions
This commit is contained in:
+13
-2
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.psi.KtThisExpression
|
|||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.tower.NewResolvedCallImpl
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||||
import org.jetbrains.kotlin.resolve.inline.InlineUtil
|
import org.jetbrains.kotlin.resolve.inline.InlineUtil
|
||||||
import org.jetbrains.kotlin.resolve.scopes.HierarchicalScope
|
import org.jetbrains.kotlin.resolve.scopes.HierarchicalScope
|
||||||
@@ -156,9 +157,19 @@ private fun checkRestrictsSuspension(
|
|||||||
if (!enclosingSuspendReceiverValue.isRestrictsSuspensionReceiver()) return
|
if (!enclosingSuspendReceiverValue.isRestrictsSuspensionReceiver()) return
|
||||||
|
|
||||||
// member of suspend receiver
|
// member of suspend receiver
|
||||||
if (enclosingSuspendReceiverValue sameInstance resolvedCall.dispatchReceiver) return
|
val (dispatchReceiver, extensionReceiver) = if (context.languageVersionSettings.supportsFeature(LanguageFeature.NewInference)) {
|
||||||
|
require(resolvedCall is NewResolvedCallImpl<*>) {
|
||||||
|
"Resolved call with enabled new inference should be instance of NewResolvedCallImpl"
|
||||||
|
}
|
||||||
|
|
||||||
if (enclosingSuspendReceiverValue sameInstance resolvedCall.extensionReceiver &&
|
resolvedCall.originalDispatchReceiver() to resolvedCall.originalExtensionReceiver()
|
||||||
|
} else {
|
||||||
|
resolvedCall.dispatchReceiver to resolvedCall.extensionReceiver
|
||||||
|
}
|
||||||
|
|
||||||
|
if (enclosingSuspendReceiverValue sameInstance dispatchReceiver) return
|
||||||
|
|
||||||
|
if (enclosingSuspendReceiverValue sameInstance extensionReceiver &&
|
||||||
resolvedCall.candidateDescriptor.extensionReceiverParameter!!.value.isRestrictsSuspensionReceiver()) return
|
resolvedCall.candidateDescriptor.extensionReceiverParameter!!.value.isRestrictsSuspensionReceiver()) return
|
||||||
|
|
||||||
context.trace.report(Errors.ILLEGAL_RESTRICTED_SUSPENDING_FUNCTION_CALL.on(reportOn))
|
context.trace.report(Errors.ILLEGAL_RESTRICTED_SUSPENDING_FUNCTION_CALL.on(reportOn))
|
||||||
|
|||||||
+3
-3
@@ -153,9 +153,6 @@ class CoroutineInferenceSession(
|
|||||||
|
|
||||||
val nonFixedTypesToResultSubstitutor = ComposedSubstitutor(commonSystemSubstitutor, nonFixedToVariablesSubstitutor)
|
val nonFixedTypesToResultSubstitutor = ComposedSubstitutor(commonSystemSubstitutor, nonFixedToVariablesSubstitutor)
|
||||||
|
|
||||||
val lambdaAtomCompleter = createResolvedAtomCompleter(nonFixedTypesToResultSubstitutor, topLevelCallContext)
|
|
||||||
lambdaAtomCompleter.completeAll(lambda)
|
|
||||||
|
|
||||||
for (completedCall in suspendCompletedCalls + normalCompletedCalls) {
|
for (completedCall in suspendCompletedCalls + normalCompletedCalls) {
|
||||||
val resultCallAtom = completedCall.callResolutionResult.resultCallAtom
|
val resultCallAtom = completedCall.callResolutionResult.resultCallAtom
|
||||||
val call = resultCallAtom.atom.getResolvedPsiKotlinCall<CallableDescriptor>(trace) ?: continue
|
val call = resultCallAtom.atom.getResolvedPsiKotlinCall<CallableDescriptor>(trace) ?: continue
|
||||||
@@ -167,6 +164,9 @@ class CoroutineInferenceSession(
|
|||||||
completedCall.context, trace, resultCallAtom, resultingDescriptor, commonSystem.diagnostics
|
completedCall.context, trace, resultCallAtom, resultingDescriptor, commonSystem.diagnostics
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val lambdaAtomCompleter = createResolvedAtomCompleter(nonFixedTypesToResultSubstitutor, topLevelCallContext)
|
||||||
|
lambdaAtomCompleter.completeAll(lambda)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateCall(
|
private fun updateCall(
|
||||||
|
|||||||
+3
@@ -534,6 +534,9 @@ class NewResolvedCallImpl<D : CallableDescriptor>(
|
|||||||
|
|
||||||
override fun getSmartCastDispatchReceiverType(): KotlinType? = smartCastDispatchReceiverType
|
override fun getSmartCastDispatchReceiverType(): KotlinType? = smartCastDispatchReceiverType
|
||||||
|
|
||||||
|
internal fun originalExtensionReceiver(): ReceiverValue? = resolvedCallAtom.extensionReceiverArgument?.receiver?.receiverValue
|
||||||
|
internal fun originalDispatchReceiver(): ReceiverValue? = resolvedCallAtom.dispatchReceiverArgument?.receiver?.receiverValue
|
||||||
|
|
||||||
fun updateExtensionReceiverWithSmartCastIfNeeded(smartCastExtensionReceiverType: KotlinType) {
|
fun updateExtensionReceiverWithSmartCastIfNeeded(smartCastExtensionReceiverType: KotlinType) {
|
||||||
if (extensionReceiver is ImplicitClassReceiver) {
|
if (extensionReceiver is ImplicitClassReceiver) {
|
||||||
extensionReceiver = CastImplicitClassReceiver(
|
extensionReceiver = CastImplicitClassReceiver(
|
||||||
|
|||||||
Vendored
+18
@@ -0,0 +1,18 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
// WITH_COROUTINES
|
||||||
|
// COMMON_COROUTINES_TEST
|
||||||
|
import helpers.*
|
||||||
|
import COROUTINES_PACKAGE.*
|
||||||
|
import COROUTINES_PACKAGE.intrinsics.*
|
||||||
|
|
||||||
|
val f = run {
|
||||||
|
buildSequence {
|
||||||
|
if (true) {
|
||||||
|
yield("OK")
|
||||||
|
}
|
||||||
|
}.toList()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
return f[0]
|
||||||
|
}
|
||||||
Generated
+12
@@ -7091,6 +7091,18 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines");
|
doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("ifExpressionInsideCoroutine.kt")
|
||||||
|
public void testIfExpressionInsideCoroutine_1_2() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/ifExpressionInsideCoroutine.kt");
|
||||||
|
doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines.experimental");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("ifExpressionInsideCoroutine.kt")
|
||||||
|
public void testIfExpressionInsideCoroutine_1_3() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/ifExpressionInsideCoroutine.kt");
|
||||||
|
doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("inlineTwoReceivers.kt")
|
@TestMetadata("inlineTwoReceivers.kt")
|
||||||
public void testInlineTwoReceivers_1_2() throws Exception {
|
public void testInlineTwoReceivers_1_2() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/inlineTwoReceivers.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/inlineTwoReceivers.kt");
|
||||||
|
|||||||
+12
@@ -7091,6 +7091,18 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines");
|
doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("ifExpressionInsideCoroutine.kt")
|
||||||
|
public void testIfExpressionInsideCoroutine_1_2() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/ifExpressionInsideCoroutine.kt");
|
||||||
|
doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines.experimental");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("ifExpressionInsideCoroutine.kt")
|
||||||
|
public void testIfExpressionInsideCoroutine_1_3() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/ifExpressionInsideCoroutine.kt");
|
||||||
|
doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("inlineTwoReceivers.kt")
|
@TestMetadata("inlineTwoReceivers.kt")
|
||||||
public void testInlineTwoReceivers_1_2() throws Exception {
|
public void testInlineTwoReceivers_1_2() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/inlineTwoReceivers.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/inlineTwoReceivers.kt");
|
||||||
|
|||||||
+12
@@ -7091,6 +7091,18 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines");
|
doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("ifExpressionInsideCoroutine.kt")
|
||||||
|
public void testIfExpressionInsideCoroutine_1_2() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/ifExpressionInsideCoroutine.kt");
|
||||||
|
doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines.experimental");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("ifExpressionInsideCoroutine.kt")
|
||||||
|
public void testIfExpressionInsideCoroutine_1_3() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/ifExpressionInsideCoroutine.kt");
|
||||||
|
doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("inlineTwoReceivers.kt")
|
@TestMetadata("inlineTwoReceivers.kt")
|
||||||
public void testInlineTwoReceivers_1_2() throws Exception {
|
public void testInlineTwoReceivers_1_2() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/inlineTwoReceivers.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/inlineTwoReceivers.kt");
|
||||||
|
|||||||
@@ -12,8 +12,6 @@ import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
|||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import org.jetbrains.kotlin.types.TypeUtils
|
import org.jetbrains.kotlin.types.TypeUtils
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||||
import java.lang.reflect.ParameterizedType
|
|
||||||
import kotlin.reflect.KFunction1
|
|
||||||
|
|
||||||
fun ClassDescriptor.underlyingRepresentation(): ValueParameterDescriptor? {
|
fun ClassDescriptor.underlyingRepresentation(): ValueParameterDescriptor? {
|
||||||
if (!isInline) return null
|
if (!isInline) return null
|
||||||
|
|||||||
+6
@@ -5907,6 +5907,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
|||||||
doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines.experimental");
|
doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines.experimental");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("ifExpressionInsideCoroutine.kt")
|
||||||
|
public void testIfExpressionInsideCoroutine_1_2() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/ifExpressionInsideCoroutine.kt");
|
||||||
|
doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines.experimental");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("inlineTwoReceivers.kt")
|
@TestMetadata("inlineTwoReceivers.kt")
|
||||||
public void testInlineTwoReceivers_1_2() throws Exception {
|
public void testInlineTwoReceivers_1_2() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/inlineTwoReceivers.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/inlineTwoReceivers.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user