Add call checker to report error more granulary if possible

This, however, works only for calls of 'synchronized' only. Thus, it
does not support inline functions of any kind.
This commit is contained in:
Ilmir Usmanov
2018-09-28 21:20:40 +03:00
parent 281f09f077
commit 9af7316845
21 changed files with 327 additions and 86 deletions
@@ -0,0 +1,3 @@
$TESTDATA_DIR$/suspensionPointInMonitor.kt
-d
$TEMP_DIR$
+68
View File
@@ -0,0 +1,68 @@
fun builder(c: suspend () -> Unit) {}
private val lock = Any()
suspend fun suspensionPoint() {}
private inline fun inlineMe(c: () -> Unit) {
synchronized(lock) {
c()
}
}
private inline fun monitorInFinally(a: () -> Unit, b: () -> Unit) {
try {
a()
} finally {
synchronized(lock) {
b()
}
}
}
fun test() {
builder {
synchronized(lock) {
suspensionPoint()
}
}
builder {
inlineMe {
suspensionPoint()
}
}
builder {
monitorInFinally(
{},
{ suspensionPoint() }
)
}
synchronized(lock) {
builder {
suspensionPoint()
}
}
synchronized(lock) {
object : SuspendRunnable {
override suspend fun run() {
suspensionPoint()
}
}
}
object : SuspendRunnable {
override suspend fun run() {
synchronized(lock) {
suspensionPoint()
}
}
}
}
interface SuspendRunnable {
suspend fun run()
}
@@ -0,0 +1,7 @@
compiler/testData/cli/jvm/suspensionPointInMonitor.kt:26:13: error: the 'suspensionPoint' suspension point is inside a synchronized block
suspensionPoint()
^
compiler/testData/cli/jvm/suspensionPointInMonitor.kt:60:17: error: the 'suspensionPoint' suspension point is inside a synchronized block
suspensionPoint()
^
COMPILATION_ERROR