Add contract for 'synchronized'

^KT-25962 Fixed
This commit is contained in:
Dmitry Savvinov
2018-07-26 14:58:50 +03:00
parent a81fc9e9bc
commit a8e1a6a2a1
6 changed files with 37 additions and 1 deletions
@@ -0,0 +1,11 @@
// !LANGUAGE: +ReadDeserializedContracts +UseCallsInPlaceEffect
fun test(lock: Any) {
val x: Int
synchronized(lock) {
x = 42
}
x.inc()
}
@@ -0,0 +1,3 @@
package
public fun test(/*0*/ lock: kotlin.Any): kotlin.Unit
@@ -1192,6 +1192,11 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW
public void testRequire() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/require.kt");
}
@TestMetadata("synchronize.kt")
public void testSynchronize() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/synchronize.kt");
}
}
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts")
@@ -1192,6 +1192,11 @@ public class DiagnosticsTestWithStdLibUsingJavacGenerated extends AbstractDiagno
public void testRequire() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/require.kt");
}
@TestMetadata("synchronize.kt")
public void testSynchronize() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/synchronize.kt");
}
}
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts")
+8 -1
View File
@@ -5,6 +5,8 @@
package kotlin
import kotlin.internal.contracts.*
@Deprecated("Use Synchronized annotation from kotlin.jvm package", ReplaceWith("kotlin.jvm.Synchronized"), level = DeprecationLevel.WARNING)
public typealias Synchronized = kotlin.jvm.Synchronized
@@ -13,4 +15,9 @@ public typealias Synchronized = kotlin.jvm.Synchronized
public typealias Volatile = kotlin.jvm.Volatile
@kotlin.internal.InlineOnly
public actual inline fun <R> synchronized(lock: Any, block: () -> R): R = block()
public actual inline fun <R> synchronized(lock: Any, block: () -> R): R {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
return block()
}
@@ -7,6 +7,7 @@
@file:kotlin.jvm.JvmName("StandardKt")
package kotlin
import kotlin.internal.contracts.*
import kotlin.jvm.internal.unsafe.*
/**
@@ -14,6 +15,10 @@ import kotlin.jvm.internal.unsafe.*
*/
@kotlin.internal.InlineOnly
public actual inline fun <R> synchronized(lock: Any, block: () -> R): R {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
@Suppress("NON_PUBLIC_CALL_FROM_PUBLIC_INLINE", "INVISIBLE_MEMBER")
monitorEnter(lock)
try {