Allow contracts on final non-override members since 1.4
This commit is contained in:
+29
-9
@@ -1188,9 +1188,14 @@ public class FirOldFrontendDiagnosticsTestWithStdlibGenerated extends AbstractFi
|
|||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/callInContractDescription.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/callInContractDescription.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("contractCallSites.kt")
|
@TestMetadata("contractCallSites.1.3.kt")
|
||||||
public void testContractCallSites() throws Exception {
|
public void testContractCallSites_1_3() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/contractCallSites.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/contractCallSites.1.3.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("contractCallSites.1.4.kt")
|
||||||
|
public void testContractCallSites_1_4() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/contractCallSites.1.4.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("emptyContract.kt")
|
@TestMetadata("emptyContract.kt")
|
||||||
@@ -1233,14 +1238,24 @@ public class FirOldFrontendDiagnosticsTestWithStdlibGenerated extends AbstractFi
|
|||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/recursiveContractCustomContractFunction.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/recursiveContractCustomContractFunction.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("referenceToProperty.kt")
|
@TestMetadata("referenceToProperty.1.3.kt")
|
||||||
public void testReferenceToProperty() throws Exception {
|
public void testReferenceToProperty_1_3() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/referenceToProperty.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/referenceToProperty.1.3.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("typeReferences.kt")
|
@TestMetadata("referenceToProperty.1.4.kt")
|
||||||
public void testTypeReferences() throws Exception {
|
public void testReferenceToProperty_1_4() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/typeReferences.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/referenceToProperty.1.4.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("typeReferences.1.3.kt")
|
||||||
|
public void testTypeReferences_1_3() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/typeReferences.1.3.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("typeReferences.1.4.kt")
|
||||||
|
public void testTypeReferences_1_4() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/typeReferences.1.4.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("unlabeledReceiver.kt")
|
@TestMetadata("unlabeledReceiver.kt")
|
||||||
@@ -1320,6 +1335,11 @@ public class FirOldFrontendDiagnosticsTestWithStdlibGenerated extends AbstractFi
|
|||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/compositions.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/compositions.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("contractsOnMembers.kt")
|
||||||
|
public void testContractsOnMembers() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/contractsOnMembers.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("deeplyNested.kt")
|
@TestMetadata("deeplyNested.kt")
|
||||||
public void testDeeplyNested() throws Exception {
|
public void testDeeplyNested() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/deeplyNested.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/deeplyNested.kt");
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
|||||||
import org.jetbrains.kotlin.builtins.getReceiverTypeFromFunctionType
|
import org.jetbrains.kotlin.builtins.getReceiverTypeFromFunctionType
|
||||||
import org.jetbrains.kotlin.builtins.getValueParameterTypesFromFunctionType
|
import org.jetbrains.kotlin.builtins.getValueParameterTypesFromFunctionType
|
||||||
import org.jetbrains.kotlin.builtins.isBuiltinFunctionalType
|
import org.jetbrains.kotlin.builtins.isBuiltinFunctionalType
|
||||||
import org.jetbrains.kotlin.config.AnalysisFlags
|
|
||||||
import org.jetbrains.kotlin.config.LanguageFeature
|
import org.jetbrains.kotlin.config.LanguageFeature
|
||||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||||
import org.jetbrains.kotlin.contracts.description.ContractProviderKey
|
import org.jetbrains.kotlin.contracts.description.ContractProviderKey
|
||||||
@@ -259,8 +258,9 @@ class FunctionDescriptorResolver(
|
|||||||
if (function !is KtNamedFunction) return null
|
if (function !is KtNamedFunction) return null
|
||||||
|
|
||||||
val isContractsEnabled = languageVersionSettings.supportsFeature(LanguageFeature.AllowContractsForCustomFunctions)
|
val isContractsEnabled = languageVersionSettings.supportsFeature(LanguageFeature.AllowContractsForCustomFunctions)
|
||||||
|
val isAllowedOnMembers = languageVersionSettings.supportsFeature(LanguageFeature.AllowContractsForNonOverridableMembers)
|
||||||
|
|
||||||
if (!isContractsEnabled || !function.mayHaveContract()) return null
|
if (!isContractsEnabled || !function.mayHaveContract(isAllowedOnMembers)) return null
|
||||||
|
|
||||||
return LazyContractProvider(storageManager) {
|
return LazyContractProvider(storageManager) {
|
||||||
AstLoadingFilter.forceAllowTreeLoading(function.containingFile, ThrowableComputable {
|
AstLoadingFilter.forceAllowTreeLoading(function.containingFile, ThrowableComputable {
|
||||||
|
|||||||
+34
-7
@@ -6,11 +6,9 @@
|
|||||||
package org.jetbrains.kotlin.resolve.calls.checkers
|
package org.jetbrains.kotlin.resolve.calls.checkers
|
||||||
|
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
|
import org.jetbrains.kotlin.config.LanguageFeature
|
||||||
import org.jetbrains.kotlin.contracts.parsing.isContractCallDescriptor
|
import org.jetbrains.kotlin.contracts.parsing.isContractCallDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
|
||||||
import org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor
|
|
||||||
import org.jetbrains.kotlin.descriptors.isOverridable
|
|
||||||
import org.jetbrains.kotlin.diagnostics.Errors
|
import org.jetbrains.kotlin.diagnostics.Errors
|
||||||
import org.jetbrains.kotlin.psi.KtElement
|
import org.jetbrains.kotlin.psi.KtElement
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.isFirstStatement
|
import org.jetbrains.kotlin.psi.psiUtil.isFirstStatement
|
||||||
@@ -25,6 +23,8 @@ object ContractNotAllowedCallChecker : CallChecker {
|
|||||||
val descriptor = resolvedCall.resultingDescriptor as? FunctionDescriptor ?: return
|
val descriptor = resolvedCall.resultingDescriptor as? FunctionDescriptor ?: return
|
||||||
if (!descriptor.isContractCallDescriptor()) return
|
if (!descriptor.isContractCallDescriptor()) return
|
||||||
|
|
||||||
|
val allowedOnMembers = context.languageVersionSettings.supportsFeature(LanguageFeature.AllowContractsForNonOverridableMembers)
|
||||||
|
|
||||||
val callElement = resolvedCall.call.callElement
|
val callElement = resolvedCall.call.callElement
|
||||||
var hasErrors = false
|
var hasErrors = false
|
||||||
|
|
||||||
@@ -40,7 +40,24 @@ object ContractNotAllowedCallChecker : CallChecker {
|
|||||||
contractNotAllowed("Contracts are allowed only for functions")
|
contractNotAllowed("Contracts are allowed only for functions")
|
||||||
|
|
||||||
var inFunctionBodyBlock = true
|
var inFunctionBodyBlock = true
|
||||||
if (scope.ownerDescriptor.containingDeclaration !is PackageFragmentDescriptor
|
|
||||||
|
val declarationOwner = scope.ownerDescriptor.containingDeclaration
|
||||||
|
val acceptableParent = if (allowedOnMembers) {
|
||||||
|
var owner = declarationOwner
|
||||||
|
var result = true
|
||||||
|
while (owner !is PackageFragmentDescriptor) {
|
||||||
|
if (owner !is ClassDescriptor) {
|
||||||
|
result = false
|
||||||
|
break
|
||||||
|
}
|
||||||
|
owner = owner.containingDeclaration
|
||||||
|
}
|
||||||
|
result
|
||||||
|
} else {
|
||||||
|
declarationOwner is PackageFragmentDescriptor
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!acceptableParent
|
||||||
|| scope.kind != LexicalScopeKind.CODE_BLOCK
|
|| scope.kind != LexicalScopeKind.CODE_BLOCK
|
||||||
|| (scope.parent as? LexicalScope)?.kind != LexicalScopeKind.FUNCTION_INNER_SCOPE
|
|| (scope.parent as? LexicalScope)?.kind != LexicalScopeKind.FUNCTION_INNER_SCOPE
|
||||||
) {
|
) {
|
||||||
@@ -48,13 +65,23 @@ object ContractNotAllowedCallChecker : CallChecker {
|
|||||||
contractNotAllowed("Contracts are allowed only in function body block")
|
contractNotAllowed("Contracts are allowed only in function body block")
|
||||||
inFunctionBodyBlock = false
|
inFunctionBodyBlock = false
|
||||||
} else {
|
} else {
|
||||||
contractNotAllowed("Contracts are allowed only for top-level functions")
|
val message = if (allowedOnMembers)
|
||||||
|
"Contracts are allowed only for functions"
|
||||||
|
else
|
||||||
|
"Contracts are allowed only for top-level functions"
|
||||||
|
contractNotAllowed(message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (functionDescriptor?.isOperator == true) contractNotAllowed("Contracts are not allowed for operator functions")
|
if (functionDescriptor?.isOperator == true) contractNotAllowed("Contracts are not allowed for operator functions")
|
||||||
|
|
||||||
if (functionDescriptor?.isOverridable == true) contractNotAllowed("Contracts are not allowed for open functions")
|
|
||||||
|
if (!allowedOnMembers && functionDescriptor?.isOverridable == true) {
|
||||||
|
contractNotAllowed("Contracts are not allowed for open functions")
|
||||||
|
}
|
||||||
|
if (allowedOnMembers && functionDescriptor?.isOverridableOrOverrides == true) {
|
||||||
|
contractNotAllowed("Contracts are not allowed for open or override functions")
|
||||||
|
}
|
||||||
|
|
||||||
if (!callElement.isFirstStatement() && inFunctionBodyBlock) {
|
if (!callElement.isFirstStatement() && inFunctionBodyBlock) {
|
||||||
contractNotAllowed("Contract should be the first statement")
|
contractNotAllowed("Contract should be the first statement")
|
||||||
|
|||||||
@@ -246,11 +246,15 @@ public class KtNamedFunction extends KtTypeParameterListOwnerStub<KotlinFunction
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean mayHaveContract() {
|
public boolean mayHaveContract() {
|
||||||
|
return mayHaveContract(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean mayHaveContract(boolean isAllowedOnMembers) {
|
||||||
KotlinFunctionStub stub = getStub();
|
KotlinFunctionStub stub = getStub();
|
||||||
if (stub != null) {
|
if (stub != null) {
|
||||||
return stub.mayHaveContract();
|
return stub.mayHaveContract();
|
||||||
}
|
}
|
||||||
|
|
||||||
return KtPsiUtilKt.isContractPresentPsiCheck(this);
|
return KtPsiUtilKt.isContractPresentPsiCheck(this, isAllowedOnMembers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -296,9 +296,9 @@ inline fun <reified T : KtElement, R> flatMapDescendantsOfTypeVisitor(
|
|||||||
|
|
||||||
// ----------- Contracts -------------------------------------------------------------------------------------------------------------------
|
// ----------- Contracts -------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
fun KtNamedFunction.isContractPresentPsiCheck(): Boolean {
|
fun KtNamedFunction.isContractPresentPsiCheck(isAllowedOnMembers: Boolean): Boolean {
|
||||||
val contractAllowedHere =
|
val contractAllowedHere =
|
||||||
isTopLevel &&
|
(isAllowedOnMembers || isTopLevel) &&
|
||||||
hasBlockBody() &&
|
hasBlockBody() &&
|
||||||
!hasModifier(KtTokens.OPERATOR_KEYWORD)
|
!hasModifier(KtTokens.OPERATOR_KEYWORD)
|
||||||
if (!contractAllowedHere) return false
|
if (!contractAllowedHere) return false
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect
|
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect -AllowContractsForNonOverridableMembers
|
||||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||||
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER -NOTHING_TO_INLINE -ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS -ABSTRACT_FUNCTION_WITH_BODY -UNUSED_PARAMETER -UNUSED_VARIABLE -EXPERIMENTAL_FEATURE_WARNING
|
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER -NOTHING_TO_INLINE -ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS -ABSTRACT_FUNCTION_WITH_BODY -UNUSED_PARAMETER -UNUSED_VARIABLE -EXPERIMENTAL_FEATURE_WARNING
|
||||||
|
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect
|
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect -AllowContractsForNonOverridableMembers
|
||||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||||
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER -NOTHING_TO_INLINE -ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS -ABSTRACT_FUNCTION_WITH_BODY -UNUSED_PARAMETER -UNUSED_VARIABLE -EXPERIMENTAL_FEATURE_WARNING
|
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER -NOTHING_TO_INLINE -ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS -ABSTRACT_FUNCTION_WITH_BODY -UNUSED_PARAMETER -UNUSED_VARIABLE -EXPERIMENTAL_FEATURE_WARNING
|
||||||
|
|
||||||
Vendored
+101
@@ -0,0 +1,101 @@
|
|||||||
|
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +AllowContractsForNonOverridableMembers
|
||||||
|
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||||
|
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER -NOTHING_TO_INLINE -ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS -ABSTRACT_FUNCTION_WITH_BODY -UNUSED_PARAMETER -UNUSED_VARIABLE -EXPERIMENTAL_FEATURE_WARNING
|
||||||
|
|
||||||
|
import kotlin.contracts.*
|
||||||
|
|
||||||
|
|
||||||
|
// ============= Class =====================
|
||||||
|
open class Class {
|
||||||
|
fun member(x: Boolean) {
|
||||||
|
contract { returns() implies (x) }
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun inlineMember(x: Boolean) {
|
||||||
|
contract { returns() implies (x) }
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract fun abstractMember(x: Boolean) {
|
||||||
|
contract { returns() implies (x) }
|
||||||
|
}
|
||||||
|
|
||||||
|
open fun openMemeber(x: Boolean) {
|
||||||
|
contract { returns() implies (x) }
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun suspendMember(x: Boolean) {
|
||||||
|
contract { returns() implies (x) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
open class Inheritor : Class() {
|
||||||
|
override fun openMemeber(x: Boolean) {
|
||||||
|
contract { returns() implies (x) }
|
||||||
|
}
|
||||||
|
|
||||||
|
final override fun abstractMember(x: Boolean) {
|
||||||
|
contract { returns() implies (x) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Interface {
|
||||||
|
fun implicitlyOpenMember(x: Boolean) {
|
||||||
|
contract { returns() implies (x) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============= Top-level =====================
|
||||||
|
fun topLevel(x: Boolean) {
|
||||||
|
contract { returns() implies (x) }
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun inlineTopLevel(x: Boolean) {
|
||||||
|
contract { returns() implies (x) }
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun suspendTopLevel(x: Boolean) {
|
||||||
|
contract { returns() implies (x) }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Top-level operator
|
||||||
|
operator fun Boolean.plus(x: Boolean): Boolean {
|
||||||
|
contract { returns() implies (x) }
|
||||||
|
return x
|
||||||
|
}
|
||||||
|
|
||||||
|
val topLevelLambda: (Boolean) -> Unit = { x: Boolean ->
|
||||||
|
contract { returns() implies (x) }
|
||||||
|
}
|
||||||
|
|
||||||
|
val topLevelAnonymousFunction = fun (x: Boolean) {
|
||||||
|
contract { returns() implies (x) }
|
||||||
|
}
|
||||||
|
|
||||||
|
var topLevelPropertyAccessors: Int? = 42
|
||||||
|
get() {
|
||||||
|
contract { returns() implies (field != null) }
|
||||||
|
return 42
|
||||||
|
}
|
||||||
|
set(value) {
|
||||||
|
contract { returns() implies (field != null) }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ============= Local =====================
|
||||||
|
fun test() {
|
||||||
|
fun localDeclaration(x: Boolean) {
|
||||||
|
contract { returns() implies (x) }
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun suspendlocalDeclaration(x: Boolean) {
|
||||||
|
contract { returns() implies (x) }
|
||||||
|
}
|
||||||
|
|
||||||
|
val localAnonymousFunction = fun (x: Boolean) {
|
||||||
|
contract { returns() implies (x) }
|
||||||
|
}
|
||||||
|
|
||||||
|
val localLambda: (Boolean) -> Unit = { x: Boolean ->
|
||||||
|
contract { returns() implies (x) }
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+101
@@ -0,0 +1,101 @@
|
|||||||
|
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +AllowContractsForNonOverridableMembers
|
||||||
|
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||||
|
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER -NOTHING_TO_INLINE -ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS -ABSTRACT_FUNCTION_WITH_BODY -UNUSED_PARAMETER -UNUSED_VARIABLE -EXPERIMENTAL_FEATURE_WARNING
|
||||||
|
|
||||||
|
import kotlin.contracts.*
|
||||||
|
|
||||||
|
|
||||||
|
// ============= Class =====================
|
||||||
|
open class Class {
|
||||||
|
fun member(x: Boolean) {
|
||||||
|
contract { returns() implies (x) }
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun inlineMember(x: Boolean) {
|
||||||
|
contract { returns() implies (x) }
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract fun abstractMember(x: Boolean) {
|
||||||
|
<!CONTRACT_NOT_ALLOWED!>contract<!> { returns() implies (x) }
|
||||||
|
}
|
||||||
|
|
||||||
|
open fun openMemeber(x: Boolean) {
|
||||||
|
<!CONTRACT_NOT_ALLOWED!>contract<!> { returns() implies (x) }
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun suspendMember(x: Boolean) {
|
||||||
|
contract { returns() implies (x) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
open class Inheritor : Class() {
|
||||||
|
override fun openMemeber(x: Boolean) {
|
||||||
|
<!CONTRACT_NOT_ALLOWED!>contract<!> { returns() implies (x) }
|
||||||
|
}
|
||||||
|
|
||||||
|
final override fun abstractMember(x: Boolean) {
|
||||||
|
<!CONTRACT_NOT_ALLOWED!>contract<!> { returns() implies (x) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Interface {
|
||||||
|
fun implicitlyOpenMember(x: Boolean) {
|
||||||
|
<!CONTRACT_NOT_ALLOWED!>contract<!> { returns() implies (x) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============= Top-level =====================
|
||||||
|
fun topLevel(x: Boolean) {
|
||||||
|
contract { returns() implies (x) }
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun inlineTopLevel(x: Boolean) {
|
||||||
|
contract { returns() implies (x) }
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun suspendTopLevel(x: Boolean) {
|
||||||
|
contract { returns() implies (x) }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Top-level operator
|
||||||
|
operator fun Boolean.plus(x: Boolean): Boolean {
|
||||||
|
<!CONTRACT_NOT_ALLOWED!>contract<!> { returns() implies (x) }
|
||||||
|
return x
|
||||||
|
}
|
||||||
|
|
||||||
|
val topLevelLambda: (Boolean) -> Unit = { x: Boolean ->
|
||||||
|
<!CONTRACT_NOT_ALLOWED!>contract<!> { returns() implies (x) }
|
||||||
|
}
|
||||||
|
|
||||||
|
val topLevelAnonymousFunction = fun (x: Boolean) {
|
||||||
|
<!CONTRACT_NOT_ALLOWED!>contract<!> { returns() implies (x) }
|
||||||
|
}
|
||||||
|
|
||||||
|
var topLevelPropertyAccessors: Int? = 42
|
||||||
|
get() {
|
||||||
|
<!CONTRACT_NOT_ALLOWED, CONTRACT_NOT_ALLOWED!>contract<!> { returns() implies (field != null) }
|
||||||
|
return 42
|
||||||
|
}
|
||||||
|
set(value) {
|
||||||
|
<!CONTRACT_NOT_ALLOWED, CONTRACT_NOT_ALLOWED!>contract<!> { returns() implies (field != null) }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ============= Local =====================
|
||||||
|
fun test() {
|
||||||
|
fun localDeclaration(x: Boolean) {
|
||||||
|
<!CONTRACT_NOT_ALLOWED!>contract<!> { returns() implies (x) }
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun suspendlocalDeclaration(x: Boolean) {
|
||||||
|
<!CONTRACT_NOT_ALLOWED!>contract<!> { returns() implies (x) }
|
||||||
|
}
|
||||||
|
|
||||||
|
val localAnonymousFunction = fun (x: Boolean) {
|
||||||
|
<!CONTRACT_NOT_ALLOWED!>contract<!> { returns() implies (x) }
|
||||||
|
}
|
||||||
|
|
||||||
|
val localLambda: (Boolean) -> Unit = { x: Boolean ->
|
||||||
|
<!CONTRACT_NOT_ALLOWED!>contract<!> { returns() implies (x) }
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+53
@@ -0,0 +1,53 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public val topLevelAnonymousFunction: (kotlin.Boolean) -> kotlin.Unit
|
||||||
|
public val topLevelLambda: (kotlin.Boolean) -> kotlin.Unit
|
||||||
|
public var topLevelPropertyAccessors: kotlin.Int?
|
||||||
|
public inline fun inlineTopLevel(/*0*/ x: kotlin.Boolean): kotlin.Unit
|
||||||
|
Returns(WILDCARD) -> x
|
||||||
|
|
||||||
|
public suspend fun suspendTopLevel(/*0*/ x: kotlin.Boolean): kotlin.Unit
|
||||||
|
Returns(WILDCARD) -> x
|
||||||
|
|
||||||
|
public fun test(): kotlin.Unit
|
||||||
|
public fun topLevel(/*0*/ x: kotlin.Boolean): kotlin.Unit
|
||||||
|
Returns(WILDCARD) -> x
|
||||||
|
|
||||||
|
public operator fun kotlin.Boolean.plus(/*0*/ x: kotlin.Boolean): kotlin.Boolean
|
||||||
|
|
||||||
|
public open class Class {
|
||||||
|
public constructor Class()
|
||||||
|
public abstract fun abstractMember(/*0*/ x: kotlin.Boolean): kotlin.Unit
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public final inline fun inlineMember(/*0*/ x: kotlin.Boolean): kotlin.Unit
|
||||||
|
public final fun member(/*0*/ x: kotlin.Boolean): kotlin.Unit
|
||||||
|
public open fun openMemeber(/*0*/ x: kotlin.Boolean): kotlin.Unit
|
||||||
|
public final suspend fun suspendMember(/*0*/ x: kotlin.Boolean): kotlin.Unit
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
|
||||||
|
public open class Inheritor : Class {
|
||||||
|
public constructor Inheritor()
|
||||||
|
public final override /*1*/ fun abstractMember(/*0*/ x: kotlin.Boolean): kotlin.Unit
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public final override /*1*/ inline /*fake_override*/ fun inlineMember(/*0*/ x: kotlin.Boolean): kotlin.Unit
|
||||||
|
Returns(WILDCARD) -> x
|
||||||
|
|
||||||
|
public final override /*1*/ /*fake_override*/ fun member(/*0*/ x: kotlin.Boolean): kotlin.Unit
|
||||||
|
Returns(WILDCARD) -> x
|
||||||
|
|
||||||
|
public open override /*1*/ fun openMemeber(/*0*/ x: kotlin.Boolean): kotlin.Unit
|
||||||
|
public final override /*1*/ suspend /*fake_override*/ fun suspendMember(/*0*/ x: kotlin.Boolean): kotlin.Unit
|
||||||
|
Returns(WILDCARD) -> x
|
||||||
|
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface Interface {
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open fun implicitlyOpenMember(/*0*/ x: kotlin.Boolean): kotlin.Unit
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect
|
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect -AllowContractsForNonOverridableMembers
|
||||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||||
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
||||||
|
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect
|
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect -AllowContractsForNonOverridableMembers
|
||||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||||
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
||||||
|
|
||||||
Vendored
+14
@@ -0,0 +1,14 @@
|
|||||||
|
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +AllowContractsForNonOverridableMembers
|
||||||
|
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||||
|
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
||||||
|
|
||||||
|
import kotlin.contracts.*
|
||||||
|
|
||||||
|
class Foo(val x: Int?) {
|
||||||
|
fun isXNull(): Boolean {
|
||||||
|
contract {
|
||||||
|
returns(false) implies (x != null)
|
||||||
|
}
|
||||||
|
return x != null
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+14
@@ -0,0 +1,14 @@
|
|||||||
|
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +AllowContractsForNonOverridableMembers
|
||||||
|
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||||
|
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
||||||
|
|
||||||
|
import kotlin.contracts.*
|
||||||
|
|
||||||
|
class Foo(val x: Int?) {
|
||||||
|
fun isXNull(): Boolean {
|
||||||
|
contract {
|
||||||
|
returns(false) implies (<!ERROR_IN_CONTRACT_DESCRIPTION!>x<!> != null)
|
||||||
|
}
|
||||||
|
return x != null
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+10
@@ -0,0 +1,10 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public final class Foo {
|
||||||
|
public constructor Foo(/*0*/ x: kotlin.Int?)
|
||||||
|
public final val x: kotlin.Int?
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public final fun isXNull(): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect
|
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect -AllowContractsForNonOverridableMembers
|
||||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||||
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
||||||
|
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect
|
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect -AllowContractsForNonOverridableMembers
|
||||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||||
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
||||||
|
|
||||||
Vendored
+53
@@ -0,0 +1,53 @@
|
|||||||
|
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +AllowContractsForNonOverridableMembers
|
||||||
|
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||||
|
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
||||||
|
|
||||||
|
import kotlin.contracts.*
|
||||||
|
|
||||||
|
inline fun <reified T> referToReifiedGeneric(x: Any?) {
|
||||||
|
contract {
|
||||||
|
returns() implies (x is T)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Generic<T> {
|
||||||
|
fun referToCaptured(x: Any?) {
|
||||||
|
contract {
|
||||||
|
returns() implies (x is T)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun referToSubstituted(x: Any?) {
|
||||||
|
contract {
|
||||||
|
returns() implies (x is Generic<String>)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun referToSubstitutedWithStar(x: Any?) {
|
||||||
|
contract {
|
||||||
|
returns() implies (x is Generic<*>)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
typealias GenericString = Generic<String>
|
||||||
|
typealias FunctionalType = () -> Unit
|
||||||
|
typealias SimpleType = Int
|
||||||
|
|
||||||
|
fun referToAliasedGeneric(x: Any?) {
|
||||||
|
contract {
|
||||||
|
returns() implies (x is GenericString)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun referToAliasedFunctionType(x: Any?) {
|
||||||
|
contract {
|
||||||
|
returns() implies (x is FunctionalType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun referToAliasedSimpleType(x: Any?) {
|
||||||
|
contract {
|
||||||
|
returns() implies (x is SimpleType)
|
||||||
|
}
|
||||||
|
}
|
||||||
+53
@@ -0,0 +1,53 @@
|
|||||||
|
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +AllowContractsForNonOverridableMembers
|
||||||
|
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||||
|
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
||||||
|
|
||||||
|
import kotlin.contracts.*
|
||||||
|
|
||||||
|
inline fun <reified T> referToReifiedGeneric(x: Any?) {
|
||||||
|
contract {
|
||||||
|
returns() implies (x is <!ERROR_IN_CONTRACT_DESCRIPTION("references to type parameters are forbidden in contracts")!>T<!>)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Generic<T> {
|
||||||
|
fun referToCaptured(x: Any?) {
|
||||||
|
contract {
|
||||||
|
returns() implies (x is <!CANNOT_CHECK_FOR_ERASED, ERROR_IN_CONTRACT_DESCRIPTION!>T<!>)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun referToSubstituted(x: Any?) {
|
||||||
|
<!ERROR_IN_CONTRACT_DESCRIPTION("Error in contract description")!>contract<!> {
|
||||||
|
returns() implies (x is <!CANNOT_CHECK_FOR_ERASED!>Generic<String><!>)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun referToSubstitutedWithStar(x: Any?) {
|
||||||
|
contract {
|
||||||
|
returns() implies (x is Generic<*>)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
typealias GenericString = Generic<String>
|
||||||
|
typealias FunctionalType = () -> Unit
|
||||||
|
typealias SimpleType = Int
|
||||||
|
|
||||||
|
fun referToAliasedGeneric(x: Any?) {
|
||||||
|
<!ERROR_IN_CONTRACT_DESCRIPTION("Error in contract description")!>contract<!> {
|
||||||
|
returns() implies (x is <!CANNOT_CHECK_FOR_ERASED!>GenericString<!>)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun referToAliasedFunctionType(x: Any?) {
|
||||||
|
<!ERROR_IN_CONTRACT_DESCRIPTION("Error in contract description")!>contract<!> {
|
||||||
|
returns() implies (x is <!CANNOT_CHECK_FOR_ERASED!>FunctionalType<!>)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun referToAliasedSimpleType(x: Any?) {
|
||||||
|
contract {
|
||||||
|
returns() implies (x is SimpleType)
|
||||||
|
}
|
||||||
|
}
|
||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public fun referToAliasedFunctionType(/*0*/ x: kotlin.Any?): kotlin.Unit
|
||||||
|
public fun referToAliasedGeneric(/*0*/ x: kotlin.Any?): kotlin.Unit
|
||||||
|
public fun referToAliasedSimpleType(/*0*/ x: kotlin.Any?): kotlin.Unit
|
||||||
|
Returns(WILDCARD) -> x is Int
|
||||||
|
|
||||||
|
public inline fun </*0*/ reified T> referToReifiedGeneric(/*0*/ x: kotlin.Any?): kotlin.Unit
|
||||||
|
public fun referToSubstituted(/*0*/ x: kotlin.Any?): kotlin.Unit
|
||||||
|
public fun referToSubstitutedWithStar(/*0*/ x: kotlin.Any?): kotlin.Unit
|
||||||
|
Returns(WILDCARD) -> x is Generic<*>
|
||||||
|
|
||||||
|
public final class Generic</*0*/ T> {
|
||||||
|
public constructor Generic</*0*/ T>()
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public final fun referToCaptured(/*0*/ x: kotlin.Any?): kotlin.Unit
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
public typealias FunctionalType = () -> kotlin.Unit
|
||||||
|
public typealias GenericString = Generic<kotlin.String>
|
||||||
|
public typealias SimpleType = kotlin.Int
|
||||||
Vendored
+31
@@ -0,0 +1,31 @@
|
|||||||
|
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +AllowContractsForNonOverridableMembers
|
||||||
|
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||||
|
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
||||||
|
|
||||||
|
import kotlin.contracts.*
|
||||||
|
|
||||||
|
class Foo {
|
||||||
|
fun myRun(block: () -> Unit) {
|
||||||
|
contract {
|
||||||
|
<!INAPPLICABLE_CANDIDATE!>callsInPlace<!>(block, InvocationKind.EXACTLY_ONCE)
|
||||||
|
}
|
||||||
|
block()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun require(x: Boolean) {
|
||||||
|
contract { returns() implies (x) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test_1(foo: Foo, x: Any) {
|
||||||
|
foo.require(x is String)
|
||||||
|
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test_2(foo: Foo): Int {
|
||||||
|
val x: Int
|
||||||
|
foo.myRun {
|
||||||
|
x = 1
|
||||||
|
}
|
||||||
|
return x + 1
|
||||||
|
}
|
||||||
+31
@@ -0,0 +1,31 @@
|
|||||||
|
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +AllowContractsForNonOverridableMembers
|
||||||
|
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||||
|
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
||||||
|
|
||||||
|
import kotlin.contracts.*
|
||||||
|
|
||||||
|
class Foo {
|
||||||
|
fun myRun(block: () -> Unit) {
|
||||||
|
contract {
|
||||||
|
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||||
|
}
|
||||||
|
block()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun require(x: Boolean) {
|
||||||
|
contract { returns() implies (x) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test_1(foo: Foo, x: Any) {
|
||||||
|
foo.require(x is String)
|
||||||
|
<!DEBUG_INFO_SMARTCAST!>x<!>.length
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test_2(foo: Foo): Int {
|
||||||
|
val x: Int
|
||||||
|
foo.myRun {
|
||||||
|
x = 1
|
||||||
|
}
|
||||||
|
return x + 1
|
||||||
|
}
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public fun test_1(/*0*/ foo: Foo, /*1*/ x: kotlin.Any): kotlin.Unit
|
||||||
|
public fun test_2(/*0*/ foo: Foo): kotlin.Int
|
||||||
|
|
||||||
|
public final class Foo {
|
||||||
|
public constructor Foo()
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public final fun myRun(/*0*/ block: () -> kotlin.Unit): kotlin.Unit
|
||||||
|
CallsInPlace(block, EXACTLY_ONCE)
|
||||||
|
|
||||||
|
public final fun require(/*0*/ x: kotlin.Boolean): kotlin.Unit
|
||||||
|
Returns(WILDCARD) -> x
|
||||||
|
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
// !LANGUAGE: +AllowContractsForCustomFunctions +ReadDeserializedContracts +AllowContractsForNonOverridableMembers
|
||||||
|
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||||
|
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||||
|
|
||||||
|
package test
|
||||||
|
|
||||||
|
import kotlin.contracts.*
|
||||||
|
|
||||||
|
class Foo {
|
||||||
|
fun <X, Y, Z, R> callsEffectWithKind(block: (X, Y, Z) -> R) {
|
||||||
|
contract {
|
||||||
|
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun returnsImplies(x: Boolean) {
|
||||||
|
contract { returns() implies (x) }
|
||||||
|
}
|
||||||
|
}
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
public final class Foo {
|
||||||
|
/*primary*/ public constructor Foo()
|
||||||
|
public final fun </*0*/ X, /*1*/ Y, /*2*/ Z, /*3*/ R> callsEffectWithKind(/*0*/ block: (X, Y, Z) -> R): kotlin.Unit
|
||||||
|
CallsInPlace(block, EXACTLY_ONCE)
|
||||||
|
|
||||||
|
public final fun returnsImplies(/*0*/ x: kotlin.Boolean): kotlin.Unit
|
||||||
|
Returns(WILDCARD) -> x
|
||||||
|
|
||||||
|
}
|
||||||
+29
-9
@@ -1189,9 +1189,14 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW
|
|||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/callInContractDescription.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/callInContractDescription.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("contractCallSites.kt")
|
@TestMetadata("contractCallSites.1.3.kt")
|
||||||
public void testContractCallSites() throws Exception {
|
public void testContractCallSites_1_3() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/contractCallSites.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/contractCallSites.1.3.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("contractCallSites.1.4.kt")
|
||||||
|
public void testContractCallSites_1_4() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/contractCallSites.1.4.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("emptyContract.kt")
|
@TestMetadata("emptyContract.kt")
|
||||||
@@ -1234,14 +1239,24 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW
|
|||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/recursiveContractCustomContractFunction.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/recursiveContractCustomContractFunction.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("referenceToProperty.kt")
|
@TestMetadata("referenceToProperty.1.3.kt")
|
||||||
public void testReferenceToProperty() throws Exception {
|
public void testReferenceToProperty_1_3() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/referenceToProperty.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/referenceToProperty.1.3.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("typeReferences.kt")
|
@TestMetadata("referenceToProperty.1.4.kt")
|
||||||
public void testTypeReferences() throws Exception {
|
public void testReferenceToProperty_1_4() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/typeReferences.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/referenceToProperty.1.4.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("typeReferences.1.3.kt")
|
||||||
|
public void testTypeReferences_1_3() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/typeReferences.1.3.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("typeReferences.1.4.kt")
|
||||||
|
public void testTypeReferences_1_4() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/typeReferences.1.4.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("unlabeledReceiver.kt")
|
@TestMetadata("unlabeledReceiver.kt")
|
||||||
@@ -1321,6 +1336,11 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW
|
|||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/compositions.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/compositions.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("contractsOnMembers.kt")
|
||||||
|
public void testContractsOnMembers() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/contractsOnMembers.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("deeplyNested.kt")
|
@TestMetadata("deeplyNested.kt")
|
||||||
public void testDeeplyNested() throws Exception {
|
public void testDeeplyNested() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/deeplyNested.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/deeplyNested.kt");
|
||||||
|
|||||||
compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java
Generated
+29
-9
@@ -1189,9 +1189,14 @@ public class DiagnosticsTestWithStdLibUsingJavacGenerated extends AbstractDiagno
|
|||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/callInContractDescription.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/callInContractDescription.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("contractCallSites.kt")
|
@TestMetadata("contractCallSites.1.3.kt")
|
||||||
public void testContractCallSites() throws Exception {
|
public void testContractCallSites_1_3() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/contractCallSites.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/contractCallSites.1.3.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("contractCallSites.1.4.kt")
|
||||||
|
public void testContractCallSites_1_4() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/contractCallSites.1.4.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("emptyContract.kt")
|
@TestMetadata("emptyContract.kt")
|
||||||
@@ -1234,14 +1239,24 @@ public class DiagnosticsTestWithStdLibUsingJavacGenerated extends AbstractDiagno
|
|||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/recursiveContractCustomContractFunction.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/recursiveContractCustomContractFunction.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("referenceToProperty.kt")
|
@TestMetadata("referenceToProperty.1.3.kt")
|
||||||
public void testReferenceToProperty() throws Exception {
|
public void testReferenceToProperty_1_3() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/referenceToProperty.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/referenceToProperty.1.3.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("typeReferences.kt")
|
@TestMetadata("referenceToProperty.1.4.kt")
|
||||||
public void testTypeReferences() throws Exception {
|
public void testReferenceToProperty_1_4() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/typeReferences.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/referenceToProperty.1.4.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("typeReferences.1.3.kt")
|
||||||
|
public void testTypeReferences_1_3() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/typeReferences.1.3.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("typeReferences.1.4.kt")
|
||||||
|
public void testTypeReferences_1_4() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/typeReferences.1.4.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("unlabeledReceiver.kt")
|
@TestMetadata("unlabeledReceiver.kt")
|
||||||
@@ -1321,6 +1336,11 @@ public class DiagnosticsTestWithStdLibUsingJavacGenerated extends AbstractDiagno
|
|||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/compositions.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/compositions.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("contractsOnMembers.kt")
|
||||||
|
public void testContractsOnMembers() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/contractsOnMembers.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("deeplyNested.kt")
|
@TestMetadata("deeplyNested.kt")
|
||||||
public void testDeeplyNested() throws Exception {
|
public void testDeeplyNested() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/deeplyNested.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/deeplyNested.kt");
|
||||||
|
|||||||
@@ -4650,6 +4650,11 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest {
|
|||||||
runTest("compiler/testData/loadJava/compiledKotlinWithStdlib/contracts/callsEffect.kt");
|
runTest("compiler/testData/loadJava/compiledKotlinWithStdlib/contracts/callsEffect.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("contractsOnMembers.kt")
|
||||||
|
public void testContractsOnMembers() throws Exception {
|
||||||
|
runTest("compiler/testData/loadJava/compiledKotlinWithStdlib/contracts/contractsOnMembers.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("deeplyNestedExpression.kt")
|
@TestMetadata("deeplyNestedExpression.kt")
|
||||||
public void testDeeplyNestedExpression() throws Exception {
|
public void testDeeplyNestedExpression() throws Exception {
|
||||||
runTest("compiler/testData/loadJava/compiledKotlinWithStdlib/contracts/deeplyNestedExpression.kt");
|
runTest("compiler/testData/loadJava/compiledKotlinWithStdlib/contracts/deeplyNestedExpression.kt");
|
||||||
|
|||||||
+5
@@ -4651,6 +4651,11 @@ public class IrLoadJavaTestGenerated extends AbstractIrLoadJavaTest {
|
|||||||
runTest("compiler/testData/loadJava/compiledKotlinWithStdlib/contracts/callsEffect.kt");
|
runTest("compiler/testData/loadJava/compiledKotlinWithStdlib/contracts/callsEffect.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("contractsOnMembers.kt")
|
||||||
|
public void testContractsOnMembers() throws Exception {
|
||||||
|
runTest("compiler/testData/loadJava/compiledKotlinWithStdlib/contracts/contractsOnMembers.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("deeplyNestedExpression.kt")
|
@TestMetadata("deeplyNestedExpression.kt")
|
||||||
public void testDeeplyNestedExpression() throws Exception {
|
public void testDeeplyNestedExpression() throws Exception {
|
||||||
runTest("compiler/testData/loadJava/compiledKotlinWithStdlib/contracts/deeplyNestedExpression.kt");
|
runTest("compiler/testData/loadJava/compiledKotlinWithStdlib/contracts/deeplyNestedExpression.kt");
|
||||||
|
|||||||
Generated
+5
@@ -4650,6 +4650,11 @@ public class LoadJavaUsingJavacTestGenerated extends AbstractLoadJavaUsingJavacT
|
|||||||
runTest("compiler/testData/loadJava/compiledKotlinWithStdlib/contracts/callsEffect.kt");
|
runTest("compiler/testData/loadJava/compiledKotlinWithStdlib/contracts/callsEffect.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("contractsOnMembers.kt")
|
||||||
|
public void testContractsOnMembers() throws Exception {
|
||||||
|
runTest("compiler/testData/loadJava/compiledKotlinWithStdlib/contracts/contractsOnMembers.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("deeplyNestedExpression.kt")
|
@TestMetadata("deeplyNestedExpression.kt")
|
||||||
public void testDeeplyNestedExpression() throws Exception {
|
public void testDeeplyNestedExpression() throws Exception {
|
||||||
runTest("compiler/testData/loadJava/compiledKotlinWithStdlib/contracts/deeplyNestedExpression.kt");
|
runTest("compiler/testData/loadJava/compiledKotlinWithStdlib/contracts/deeplyNestedExpression.kt");
|
||||||
|
|||||||
@@ -121,6 +121,7 @@ enum class LanguageFeature(
|
|||||||
AllowNullOperatorsForResult(KOTLIN_1_4),
|
AllowNullOperatorsForResult(KOTLIN_1_4),
|
||||||
AllowResultInReturnType(KOTLIN_1_4),
|
AllowResultInReturnType(KOTLIN_1_4),
|
||||||
PreferJavaFieldOverload(KOTLIN_1_4),
|
PreferJavaFieldOverload(KOTLIN_1_4),
|
||||||
|
AllowContractsForNonOverridableMembers(KOTLIN_1_4),
|
||||||
|
|
||||||
ProperVisibilityForCompanionObjectInstanceField(sinceVersion = null, kind = BUG_FIX),
|
ProperVisibilityForCompanionObjectInstanceField(sinceVersion = null, kind = BUG_FIX),
|
||||||
// Temporarily disabled, see KT-27084/KT-22379
|
// Temporarily disabled, see KT-27084/KT-22379
|
||||||
|
|||||||
Reference in New Issue
Block a user