Skip to content

Commit 4ee818a

Browse files
committed
Add callee name to diagnostic about illegal suspension call
#KT-15938 Fixed
1 parent a74fffe commit 4ee818a

File tree

8 files changed

+20
-5
lines changed

8 files changed

+20
-5
lines changed

compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ enum BadNamedArgumentsTarget {
911911

912912

913913
DiagnosticFactory0<PsiElement> NON_LOCAL_SUSPENSION_POINT = DiagnosticFactory0.create(ERROR);
914-
DiagnosticFactory0<PsiElement> ILLEGAL_SUSPEND_FUNCTION_CALL = DiagnosticFactory0.create(ERROR);
914+
DiagnosticFactory1<PsiElement, CallableDescriptor> ILLEGAL_SUSPEND_FUNCTION_CALL = DiagnosticFactory1.create(ERROR);
915915
DiagnosticFactory0<PsiElement> ILLEGAL_RESTRICTED_SUSPENDING_FUNCTION_CALL = DiagnosticFactory0.create(ERROR);
916916

917917

compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ public String render(@NotNull Boolean hasValueParameters, @NotNull RenderingCont
905905
MAP.put(INLINE_CALL_CYCLE, "The ''{0}'' invocation is a part of inline cycle", NAME);
906906
MAP.put(NON_LOCAL_RETURN_IN_DISABLED_INLINE, "Non-local returns are not allowed with inlining disabled");
907907
MAP.put(NON_LOCAL_SUSPENSION_POINT, "Suspension functions can be called only within coroutine body");
908-
MAP.put(ILLEGAL_SUSPEND_FUNCTION_CALL, "Suspend functions are only allowed to be called from a coroutine or another suspend function");
908+
MAP.put(ILLEGAL_SUSPEND_FUNCTION_CALL, "Suspend function ''{0}'' should be called only from a coroutine or another suspend function", NAME);
909909
MAP.put(ILLEGAL_RESTRICTED_SUSPENDING_FUNCTION_CALL, "Restricted suspending functions can only invoke member or extension suspending functions on their restricted coroutine scope");
910910

911911
MAP.setImmutable();

compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/coroutineCallChecker.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ object CoroutineSuspendCallChecker : CallChecker {
6666
checkRestrictsSuspension(enclosingSuspendFunction, resolvedCall, reportOn, context)
6767
}
6868
else -> {
69-
context.trace.report(Errors.ILLEGAL_SUSPEND_FUNCTION_CALL.on(reportOn))
69+
context.trace.report(Errors.ILLEGAL_SUSPEND_FUNCTION_CALL.on(reportOn, resolvedCall.candidateDescriptor))
7070
}
7171
}
7272
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// !DIAGNOSTICS_NUMBER: 1
2+
// !DIAGNOSTICS: ILLEGAL_SUSPEND_FUNCTION_CALL
3+
suspend fun foo() {}
4+
5+
fun noSuspend() {
6+
foo()
7+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<!-- illegalSuspendCall1 -->
2+
Suspend function 'foo' should be called only from a coroutine or another suspend function

idea/testData/quickfix/modifiers/suspend/init.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// "Make bar suspend" "false"
2-
// ERROR: Suspend functions are only allowed to be called from a coroutine or another suspend function
2+
// ERROR: Suspend function 'foo' should be called only from a coroutine or another suspend function
33

44
suspend fun foo() {}
55

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// "Make bar suspend" "false"
22
// ACTION: Convert property initializer to getter
3-
// ERROR: Suspend functions are only allowed to be called from a coroutine or another suspend function
3+
// ERROR: Suspend function 'foo' should be called only from a coroutine or another suspend function
44

55
suspend fun foo() = 42
66
val x = <caret>foo()

idea/tests/org/jetbrains/kotlin/idea/highlighter/DiagnosticMessageTestGenerated.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ public void testFunctionPlaceholder() throws Exception {
126126
doTest(fileName);
127127
}
128128

129+
@TestMetadata("illegalSuspendCall.kt")
130+
public void testIllegalSuspendCall() throws Exception {
131+
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/diagnosticMessage/illegalSuspendCall.kt");
132+
doTest(fileName);
133+
}
134+
129135
@TestMetadata("invisibleMember.kt")
130136
public void testInvisibleMember() throws Exception {
131137
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/diagnosticMessage/invisibleMember.kt");

0 commit comments

Comments
 (0)