Add callee name to diagnostic about illegal suspension call

#KT-15938 Fixed
This commit is contained in:
Denis Zharkov
2017-02-07 14:50:43 +03:00
parent a74fffeac8
commit 4ee818addf
8 changed files with 20 additions and 5 deletions
@@ -911,7 +911,7 @@ public interface Errors {
DiagnosticFactory0<PsiElement> NON_LOCAL_SUSPENSION_POINT = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<PsiElement> ILLEGAL_SUSPEND_FUNCTION_CALL = DiagnosticFactory0.create(ERROR);
DiagnosticFactory1<PsiElement, CallableDescriptor> ILLEGAL_SUSPEND_FUNCTION_CALL = DiagnosticFactory1.create(ERROR);
DiagnosticFactory0<PsiElement> ILLEGAL_RESTRICTED_SUSPENDING_FUNCTION_CALL = DiagnosticFactory0.create(ERROR);
@@ -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();
@@ -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))
}
}
}
+7
View File
@@ -0,0 +1,7 @@
// !DIAGNOSTICS_NUMBER: 1
// !DIAGNOSTICS: ILLEGAL_SUSPEND_FUNCTION_CALL
suspend fun foo() {}
fun noSuspend() {
foo()
}
@@ -0,0 +1,2 @@
<!-- illegalSuspendCall1 -->
Suspend function 'foo' should be called only from a coroutine or another suspend function
+1 -1
View File
@@ -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() {}
+1 -1
View File
@@ -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 = <caret>foo()
@@ -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");