Add contract for 'synchronized'
^KT-25962 Fixed
This commit is contained in:
+11
@@ -0,0 +1,11 @@
|
|||||||
|
// !LANGUAGE: +ReadDeserializedContracts +UseCallsInPlaceEffect
|
||||||
|
|
||||||
|
fun test(lock: Any) {
|
||||||
|
val x: Int
|
||||||
|
|
||||||
|
synchronized(lock) {
|
||||||
|
x = 42
|
||||||
|
}
|
||||||
|
|
||||||
|
x.inc()
|
||||||
|
}
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public fun test(/*0*/ lock: kotlin.Any): kotlin.Unit
|
||||||
+5
@@ -1192,6 +1192,11 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW
|
|||||||
public void testRequire() throws Exception {
|
public void testRequire() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/require.kt");
|
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")
|
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts")
|
||||||
|
|||||||
compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java
Generated
+5
@@ -1192,6 +1192,11 @@ public class DiagnosticsTestWithStdLibUsingJavacGenerated extends AbstractDiagno
|
|||||||
public void testRequire() throws Exception {
|
public void testRequire() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/require.kt");
|
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")
|
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts")
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
package kotlin
|
package kotlin
|
||||||
|
|
||||||
|
import kotlin.internal.contracts.*
|
||||||
|
|
||||||
|
|
||||||
@Deprecated("Use Synchronized annotation from kotlin.jvm package", ReplaceWith("kotlin.jvm.Synchronized"), level = DeprecationLevel.WARNING)
|
@Deprecated("Use Synchronized annotation from kotlin.jvm package", ReplaceWith("kotlin.jvm.Synchronized"), level = DeprecationLevel.WARNING)
|
||||||
public typealias Synchronized = kotlin.jvm.Synchronized
|
public typealias Synchronized = kotlin.jvm.Synchronized
|
||||||
@@ -13,4 +15,9 @@ public typealias Synchronized = kotlin.jvm.Synchronized
|
|||||||
public typealias Volatile = kotlin.jvm.Volatile
|
public typealias Volatile = kotlin.jvm.Volatile
|
||||||
|
|
||||||
@kotlin.internal.InlineOnly
|
@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")
|
@file:kotlin.jvm.JvmName("StandardKt")
|
||||||
package kotlin
|
package kotlin
|
||||||
|
|
||||||
|
import kotlin.internal.contracts.*
|
||||||
import kotlin.jvm.internal.unsafe.*
|
import kotlin.jvm.internal.unsafe.*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -14,6 +15,10 @@ import kotlin.jvm.internal.unsafe.*
|
|||||||
*/
|
*/
|
||||||
@kotlin.internal.InlineOnly
|
@kotlin.internal.InlineOnly
|
||||||
public actual inline fun <R> synchronized(lock: Any, block: () -> R): R {
|
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")
|
@Suppress("NON_PUBLIC_CALL_FROM_PUBLIC_INLINE", "INVISIBLE_MEMBER")
|
||||||
monitorEnter(lock)
|
monitorEnter(lock)
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user