Debugger: Prohibit 'suspend fun' calls in evaluated expressions
Currently, it's impossible to call suspend functions in evaluated code fragments (see KT-31701). This commit officially prohibits such calls, so users will see a semi-friendly error message.
This commit is contained in:
+12
@@ -184,6 +184,18 @@ class CodeFragmentParameterAnalyzer(
|
|||||||
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun visitCallExpression(expression: KtCallExpression, data: Unit?): Void? {
|
||||||
|
val resolvedCall = expression.getResolvedCall(bindingContext)
|
||||||
|
if (resolvedCall != null) {
|
||||||
|
val descriptor = resolvedCall.resultingDescriptor
|
||||||
|
if (descriptor is FunctionDescriptor && descriptor.isSuspend) {
|
||||||
|
throw EvaluateExceptionUtil.createEvaluateException("Evaluation of 'suspend' calls is not supported")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.visitCallExpression(expression, data)
|
||||||
|
}
|
||||||
}, Unit)
|
}, Unit)
|
||||||
|
|
||||||
return CodeFragmentParameterInfo(parameters.values.toList(), crossingBounds)
|
return CodeFragmentParameterInfo(parameters.values.toList(), crossingBounds)
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package suspendCalls
|
||||||
|
|
||||||
|
suspend fun main() {
|
||||||
|
//Breakpoint!
|
||||||
|
foo()
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun foo(): Int = 42
|
||||||
|
|
||||||
|
// EXPRESSION: foo()
|
||||||
|
// RESULT: Evaluation of 'suspend' calls is not supported
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
LineBreakpoint created at suspendCalls.kt:5
|
||||||
|
Run Java
|
||||||
|
Connected to the target VM
|
||||||
|
suspendCalls.kt:5
|
||||||
|
Disconnected from the target VM
|
||||||
|
|
||||||
|
Process finished with exit code 0
|
||||||
Generated
+5
@@ -421,6 +421,11 @@ public class KotlinEvaluateExpressionTestGenerated extends AbstractKotlinEvaluat
|
|||||||
runTest("idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/superCallsSimple.kt");
|
runTest("idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/superCallsSimple.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("suspendCalls.kt")
|
||||||
|
public void testSuspendCalls() throws Exception {
|
||||||
|
runTest("idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/suspendCalls.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("synchronizedBlock.kt")
|
@TestMetadata("synchronizedBlock.kt")
|
||||||
public void testSynchronizedBlock() throws Exception {
|
public void testSynchronizedBlock() throws Exception {
|
||||||
runTest("idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/synchronizedBlock.kt");
|
runTest("idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/synchronizedBlock.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user