From 4ee818addf32939ff7b3ca7e51e78178ee5b1abe Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Tue, 7 Feb 2017 14:50:43 +0300 Subject: [PATCH] Add callee name to diagnostic about illegal suspension call #KT-15938 Fixed --- .../src/org/jetbrains/kotlin/diagnostics/Errors.java | 2 +- .../kotlin/diagnostics/rendering/DefaultErrorMessages.java | 2 +- .../kotlin/resolve/calls/checkers/coroutineCallChecker.kt | 2 +- idea/testData/diagnosticMessage/illegalSuspendCall.kt | 7 +++++++ idea/testData/diagnosticMessage/illegalSuspendCall1.txt | 2 ++ idea/testData/quickfix/modifiers/suspend/init.kt | 2 +- idea/testData/quickfix/modifiers/suspend/topLevel.kt | 2 +- .../idea/highlighter/DiagnosticMessageTestGenerated.java | 6 ++++++ 8 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 idea/testData/diagnosticMessage/illegalSuspendCall.kt create mode 100644 idea/testData/diagnosticMessage/illegalSuspendCall1.txt diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index 551974b08ce..d89e9b346fd 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -911,7 +911,7 @@ public interface Errors { DiagnosticFactory0 NON_LOCAL_SUSPENSION_POINT = DiagnosticFactory0.create(ERROR); - DiagnosticFactory0 ILLEGAL_SUSPEND_FUNCTION_CALL = DiagnosticFactory0.create(ERROR); + DiagnosticFactory1 ILLEGAL_SUSPEND_FUNCTION_CALL = DiagnosticFactory1.create(ERROR); DiagnosticFactory0 ILLEGAL_RESTRICTED_SUSPENDING_FUNCTION_CALL = DiagnosticFactory0.create(ERROR); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java index 76dc680d056..7b1264c80ab 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -905,7 +905,7 @@ public class DefaultErrorMessages { MAP.put(INLINE_CALL_CYCLE, "The ''{0}'' invocation is a part of inline cycle", NAME); MAP.put(NON_LOCAL_RETURN_IN_DISABLED_INLINE, "Non-local returns are not allowed with inlining disabled"); MAP.put(NON_LOCAL_SUSPENSION_POINT, "Suspension functions can be called only within coroutine body"); - MAP.put(ILLEGAL_SUSPEND_FUNCTION_CALL, "Suspend functions are only allowed to be called from a coroutine or another suspend function"); + MAP.put(ILLEGAL_SUSPEND_FUNCTION_CALL, "Suspend function ''{0}'' should be called only from a coroutine or another suspend function", NAME); MAP.put(ILLEGAL_RESTRICTED_SUSPENDING_FUNCTION_CALL, "Restricted suspending functions can only invoke member or extension suspending functions on their restricted coroutine scope"); MAP.setImmutable(); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/coroutineCallChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/coroutineCallChecker.kt index 14e522fc572..bd199a42932 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/coroutineCallChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/coroutineCallChecker.kt @@ -66,7 +66,7 @@ object CoroutineSuspendCallChecker : CallChecker { checkRestrictsSuspension(enclosingSuspendFunction, resolvedCall, reportOn, context) } else -> { - context.trace.report(Errors.ILLEGAL_SUSPEND_FUNCTION_CALL.on(reportOn)) + context.trace.report(Errors.ILLEGAL_SUSPEND_FUNCTION_CALL.on(reportOn, resolvedCall.candidateDescriptor)) } } } diff --git a/idea/testData/diagnosticMessage/illegalSuspendCall.kt b/idea/testData/diagnosticMessage/illegalSuspendCall.kt new file mode 100644 index 00000000000..d9a956c421c --- /dev/null +++ b/idea/testData/diagnosticMessage/illegalSuspendCall.kt @@ -0,0 +1,7 @@ +// !DIAGNOSTICS_NUMBER: 1 +// !DIAGNOSTICS: ILLEGAL_SUSPEND_FUNCTION_CALL +suspend fun foo() {} + +fun noSuspend() { + foo() +} diff --git a/idea/testData/diagnosticMessage/illegalSuspendCall1.txt b/idea/testData/diagnosticMessage/illegalSuspendCall1.txt new file mode 100644 index 00000000000..936139909b7 --- /dev/null +++ b/idea/testData/diagnosticMessage/illegalSuspendCall1.txt @@ -0,0 +1,2 @@ + +Suspend function 'foo' should be called only from a coroutine or another suspend function diff --git a/idea/testData/quickfix/modifiers/suspend/init.kt b/idea/testData/quickfix/modifiers/suspend/init.kt index 2e7dd669505..0b7c25ec73e 100644 --- a/idea/testData/quickfix/modifiers/suspend/init.kt +++ b/idea/testData/quickfix/modifiers/suspend/init.kt @@ -1,5 +1,5 @@ // "Make bar suspend" "false" -// ERROR: Suspend functions are only allowed to be called from a coroutine or another suspend function +// ERROR: Suspend function 'foo' should be called only from a coroutine or another suspend function suspend fun foo() {} diff --git a/idea/testData/quickfix/modifiers/suspend/topLevel.kt b/idea/testData/quickfix/modifiers/suspend/topLevel.kt index bc8c1a94d9f..f76cc3fa183 100644 --- a/idea/testData/quickfix/modifiers/suspend/topLevel.kt +++ b/idea/testData/quickfix/modifiers/suspend/topLevel.kt @@ -1,6 +1,6 @@ // "Make bar suspend" "false" // ACTION: Convert property initializer to getter -// ERROR: Suspend functions are only allowed to be called from a coroutine or another suspend function +// ERROR: Suspend function 'foo' should be called only from a coroutine or another suspend function suspend fun foo() = 42 val x = foo() diff --git a/idea/tests/org/jetbrains/kotlin/idea/highlighter/DiagnosticMessageTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/highlighter/DiagnosticMessageTestGenerated.java index 29908ca262c..03a0ee75d01 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/highlighter/DiagnosticMessageTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/highlighter/DiagnosticMessageTestGenerated.java @@ -126,6 +126,12 @@ public class DiagnosticMessageTestGenerated extends AbstractDiagnosticMessageTes doTest(fileName); } + @TestMetadata("illegalSuspendCall.kt") + public void testIllegalSuspendCall() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/diagnosticMessage/illegalSuspendCall.kt"); + doTest(fileName); + } + @TestMetadata("invisibleMember.kt") public void testInvisibleMember() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/diagnosticMessage/invisibleMember.kt");