[K2] Disappeared UNSUPPORTED
Mark as UNSUPPORTED suspension points in default parameters ^KT-59881
This commit is contained in:
committed by
Space Team
parent
c1f6fe1e76
commit
6471080c48
+22
-4
@@ -12,10 +12,8 @@ import org.jetbrains.kotlin.fir.FirSession
|
|||||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||||
import org.jetbrains.kotlin.fir.analysis.getChild
|
import org.jetbrains.kotlin.fir.analysis.getChild
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirAnonymousFunction
|
import org.jetbrains.kotlin.fir.declarations.*
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirFunction
|
import org.jetbrains.kotlin.fir.declarations.utils.isInline
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction
|
|
||||||
import org.jetbrains.kotlin.fir.declarations.getAnnotationByClassId
|
|
||||||
import org.jetbrains.kotlin.fir.declarations.utils.isSuspend
|
import org.jetbrains.kotlin.fir.declarations.utils.isSuspend
|
||||||
import org.jetbrains.kotlin.fir.expressions.*
|
import org.jetbrains.kotlin.fir.expressions.*
|
||||||
import org.jetbrains.kotlin.fir.references.FirResolvedCallableReference
|
import org.jetbrains.kotlin.fir.references.FirResolvedCallableReference
|
||||||
@@ -64,6 +62,14 @@ object FirSuspendCallChecker : FirQualifiedAccessExpressionChecker() {
|
|||||||
if (!checkNonLocalReturnUsage(enclosingSuspendFunction, context)) {
|
if (!checkNonLocalReturnUsage(enclosingSuspendFunction, context)) {
|
||||||
reporter.reportOn(expression.source, FirErrors.NON_LOCAL_SUSPENSION_POINT, context)
|
reporter.reportOn(expression.source, FirErrors.NON_LOCAL_SUSPENSION_POINT, context)
|
||||||
}
|
}
|
||||||
|
if (isInScopeForDefaultParameterValues(enclosingSuspendFunction, context)) {
|
||||||
|
reporter.reportOn(
|
||||||
|
expression.source,
|
||||||
|
FirErrors.UNSUPPORTED,
|
||||||
|
"suspend function calls in a context of default parameter value",
|
||||||
|
context
|
||||||
|
)
|
||||||
|
}
|
||||||
if (!checkRestrictsSuspension(expression, enclosingSuspendFunction, symbol, context)) {
|
if (!checkRestrictsSuspension(expression, enclosingSuspendFunction, symbol, context)) {
|
||||||
reporter.reportOn(expression.source, FirErrors.ILLEGAL_RESTRICTED_SUSPENDING_FUNCTION_CALL, context)
|
reporter.reportOn(expression.source, FirErrors.ILLEGAL_RESTRICTED_SUSPENDING_FUNCTION_CALL, context)
|
||||||
}
|
}
|
||||||
@@ -139,6 +145,18 @@ object FirSuspendCallChecker : FirQualifiedAccessExpressionChecker() {
|
|||||||
} as? FirFunction
|
} as? FirFunction
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun isInScopeForDefaultParameterValues(enclosingSuspendFunction: FirFunction, context: CheckerContext): Boolean {
|
||||||
|
val valueParameters = enclosingSuspendFunction.valueParameters
|
||||||
|
for (declaration in context.containingDeclarations.asReversed()) {
|
||||||
|
when {
|
||||||
|
declaration is FirValueParameter && declaration in valueParameters && declaration.defaultValue != null -> return true
|
||||||
|
declaration is FirAnonymousFunction && declaration.inlineStatus == InlineStatus.Inline -> continue
|
||||||
|
declaration is FirFunction && !declaration.isInline -> return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
private fun checkNonLocalReturnUsage(enclosingSuspendFunction: FirFunction, context: CheckerContext): Boolean {
|
private fun checkNonLocalReturnUsage(enclosingSuspendFunction: FirFunction, context: CheckerContext): Boolean {
|
||||||
val containingFunction = context.containingDeclarations.lastIsInstanceOrNull<FirFunction>() ?: return false
|
val containingFunction = context.containingDeclarations.lastIsInstanceOrNull<FirFunction>() ?: return false
|
||||||
return if (containingFunction is FirAnonymousFunction && enclosingSuspendFunction !== containingFunction) {
|
return if (containingFunction is FirAnonymousFunction && enclosingSuspendFunction !== containingFunction) {
|
||||||
|
|||||||
+4
-2
@@ -4,10 +4,11 @@
|
|||||||
suspend fun foo() = 1
|
suspend fun foo() = 1
|
||||||
|
|
||||||
suspend fun bar(
|
suspend fun bar(
|
||||||
x: Int = 2 + foo(),
|
x: Int = 2 + <!UNSUPPORTED!>foo()<!>,
|
||||||
y: suspend () -> Int = { foo() },
|
y: suspend () -> Int = { foo() },
|
||||||
z: () -> Int = { <!NON_LOCAL_SUSPENSION_POINT!>foo<!>() },
|
z: () -> Int = { <!NON_LOCAL_SUSPENSION_POINT!>foo<!>() },
|
||||||
w: Int = myInline { foo() },
|
w: Int = myInline { <!UNSUPPORTED!>foo()<!> },
|
||||||
|
q: Int = myInline2 { <!NON_LOCAL_SUSPENSION_POINT!>foo<!>() },
|
||||||
v: Any? = object {
|
v: Any? = object {
|
||||||
fun x() = <!NON_LOCAL_SUSPENSION_POINT!>foo<!>()
|
fun x() = <!NON_LOCAL_SUSPENSION_POINT!>foo<!>()
|
||||||
suspend fun y() = foo()
|
suspend fun y() = foo()
|
||||||
@@ -15,3 +16,4 @@ suspend fun bar(
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
inline fun myInline(x: () -> Unit) = 1
|
inline fun myInline(x: () -> Unit) = 1
|
||||||
|
inline fun myInline2(crossinline x: () -> Unit) = 1
|
||||||
|
|||||||
+2
@@ -8,6 +8,7 @@ suspend fun bar(
|
|||||||
y: suspend () -> Int = { foo() },
|
y: suspend () -> Int = { foo() },
|
||||||
z: () -> Int = { <!NON_LOCAL_SUSPENSION_POINT!>foo<!>() },
|
z: () -> Int = { <!NON_LOCAL_SUSPENSION_POINT!>foo<!>() },
|
||||||
w: Int = myInline { <!UNSUPPORTED!>foo<!>() },
|
w: Int = myInline { <!UNSUPPORTED!>foo<!>() },
|
||||||
|
q: Int = myInline2 { <!NON_LOCAL_SUSPENSION_POINT!>foo<!>() },
|
||||||
v: Any? = object {
|
v: Any? = object {
|
||||||
fun x() = <!NON_LOCAL_SUSPENSION_POINT!>foo<!>()
|
fun x() = <!NON_LOCAL_SUSPENSION_POINT!>foo<!>()
|
||||||
suspend fun y() = foo()
|
suspend fun y() = foo()
|
||||||
@@ -15,3 +16,4 @@ suspend fun bar(
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
inline fun myInline(x: () -> Unit) = 1
|
inline fun myInline(x: () -> Unit) = 1
|
||||||
|
inline fun myInline2(crossinline x: () -> Unit) = 1
|
||||||
|
|||||||
Reference in New Issue
Block a user