From 7787b53b4aea54c53b0cba9f3ef73b3474c77b78 Mon Sep 17 00:00:00 2001 From: "Anastasia.Nekrasova" Date: Thu, 23 Nov 2023 14:56:42 +0200 Subject: [PATCH] [K2] Disappeared UNSUPPORTED Forbid callable reference to coroutineContext ^KT-59881 --- .../expression/FirSuspendCallChecker.kt | 18 +++++++++++++++++- .../callableReference/property.fir.kt | 12 ------------ .../coroutines/callableReference/property.kt | 1 + 3 files changed, 18 insertions(+), 13 deletions(-) delete mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference/property.fir.kt diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirSuspendCallChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirSuspendCallChecker.kt index 9dbda509be8..206cb5c678f 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirSuspendCallChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirSuspendCallChecker.kt @@ -44,7 +44,12 @@ object FirSuspendCallChecker : FirQualifiedAccessExpressionChecker() { ) { checkSuspendModifierForm(expression, reference, symbol, context, reporter) } - if (reference is FirResolvedCallableReference) return + + if (reference is FirResolvedCallableReference) { + checkCallableReference(expression, symbol, reporter, context) + return + } + when (symbol) { is FirNamedFunctionSymbol -> if (!symbol.isSuspend) return is FirPropertySymbol -> if (symbol.callableId != StandardClassIds.Callables.coroutineContext) return @@ -260,6 +265,17 @@ object FirSuspendCallChecker : FirQualifiedAccessExpressionChecker() { calledDeclarationSymbol.resolvedReceiverTypeRef?.coneType, ) } + + private fun checkCallableReference( + expression: FirQualifiedAccessExpression, + symbol: FirCallableSymbol<*>, + reporter: DiagnosticReporter, + context: CheckerContext, + ) { + if (symbol.callableId == StandardClassIds.Callables.coroutineContext) { + reporter.reportOn(expression.calleeReference.source, FirErrors.UNSUPPORTED, "Callable reference to suspend property", context) + } + } } private enum class SuspendCallArgumentKind { diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference/property.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference/property.fir.kt deleted file mode 100644 index 11c5a7520c2..00000000000 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference/property.fir.kt +++ /dev/null @@ -1,12 +0,0 @@ -// SKIP_TXT -import kotlin.coroutines.coroutineContext - -val c = ::coroutineContext - -fun test() { - c() -} - -suspend fun test2() { - c() -} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference/property.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference/property.kt index 1d68edc5504..0cdd8d16254 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference/property.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference/property.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // SKIP_TXT import kotlin.coroutines.coroutineContext