From 16fc65741d7d0c987095817217b6afd3aeff28c8 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Mon, 29 Jun 2026 20:41:39 +0200 Subject: [PATCH] [kotlin] SuspiciousImplicitCoroutineScopeReceiverAccess: avoid endless loop - when functional literal doesn't belong to any call ^KTIJ-39388 fixed (cherry picked from commit 0a4f356027659d7ad1370b2224daedc023c2cddb) IJ-CR-218907 GitOrigin-RevId: 440778a288dde343f88a6868cf0628586283bfc0 --- ...tCoroutineScopeReceiverAccessInspection.kt | 2 +- .../tests/K2LocalInspectionTestGenerated.java | 5 +++++ .../selectBuilderProperty.kt | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 plugins/kotlin/code-insight/inspections-k2/tests/testData/inspectionsLocal/coroutines/ambiguousCoroutineScope/selectBuilderProperty.kt diff --git a/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/codeInsight/inspections/coroutines/SuspiciousImplicitCoroutineScopeReceiverAccessInspection.kt b/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/codeInsight/inspections/coroutines/SuspiciousImplicitCoroutineScopeReceiverAccessInspection.kt index 30dad4aea743..1d847e2df0c1 100644 --- a/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/codeInsight/inspections/coroutines/SuspiciousImplicitCoroutineScopeReceiverAccessInspection.kt +++ b/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/codeInsight/inspections/coroutines/SuspiciousImplicitCoroutineScopeReceiverAccessInspection.kt @@ -152,7 +152,7 @@ internal class SuspiciousImplicitCoroutineScopeReceiverAccessInspection : } // Check if the matching parameter's return type is a suspend type - val (functionSymbol, argumentSymbol) = getCallExpressionSymbol(current) ?: continue + val (functionSymbol, argumentSymbol) = getCallExpressionSymbol(current) ?: return false // Resolve the outer call of the lambda val parameterType = argumentSymbol.returnType diff --git a/plugins/kotlin/code-insight/inspections-k2/tests/test/org/jetbrains/kotlin/idea/inspections/tests/K2LocalInspectionTestGenerated.java b/plugins/kotlin/code-insight/inspections-k2/tests/test/org/jetbrains/kotlin/idea/inspections/tests/K2LocalInspectionTestGenerated.java index c5f3f73cd1f9..e0d5b3ba3e55 100644 --- a/plugins/kotlin/code-insight/inspections-k2/tests/test/org/jetbrains/kotlin/idea/inspections/tests/K2LocalInspectionTestGenerated.java +++ b/plugins/kotlin/code-insight/inspections-k2/tests/test/org/jetbrains/kotlin/idea/inspections/tests/K2LocalInspectionTestGenerated.java @@ -16347,6 +16347,11 @@ public abstract class K2LocalInspectionTestGenerated extends AbstractK2LocalInsp runTest("testData/inspectionsLocal/coroutines/ambiguousCoroutineScope/lambdaExtensionReceiver_withLabel_suspendWrapper.kt"); } + @TestMetadata("selectBuilderProperty.kt") + public void testSelectBuilderProperty() throws Exception { + runTest("testData/inspectionsLocal/coroutines/ambiguousCoroutineScope/selectBuilderProperty.kt"); + } + @TestMetadata("selectExpression.kt") public void testSelectExpression() throws Exception { runTest("testData/inspectionsLocal/coroutines/ambiguousCoroutineScope/selectExpression.kt"); diff --git a/plugins/kotlin/code-insight/inspections-k2/tests/testData/inspectionsLocal/coroutines/ambiguousCoroutineScope/selectBuilderProperty.kt b/plugins/kotlin/code-insight/inspections-k2/tests/testData/inspectionsLocal/coroutines/ambiguousCoroutineScope/selectBuilderProperty.kt new file mode 100644 index 000000000000..c3c7793ea977 --- /dev/null +++ b/plugins/kotlin/code-insight/inspections-k2/tests/testData/inspectionsLocal/coroutines/ambiguousCoroutineScope/selectBuilderProperty.kt @@ -0,0 +1,19 @@ +// WITH_COROUTINES +// PROBLEM: none +package test + +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.async +import kotlinx.coroutines.selects.SelectBuilder + +fun CoroutineScope.doStuff() {} + +suspend fun CoroutineScope.test() { + val deferred = async { 42 } + + val p: SelectBuilder.() -> Unit = { + deferred.onAwait { + doStuff() + } + } +}