Report CONTRACT_NOT_ALLOWED diagnostic on extension property getter/setter
KT-27090
This commit is contained in:
+2
-5
@@ -22,10 +22,7 @@ import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.contracts.description.ContractDescription
|
||||
import org.jetbrains.kotlin.contracts.description.ContractProviderKey
|
||||
import org.jetbrains.kotlin.contracts.description.LazyContractProvider
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.isOverridable
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.psi.psiUtil.isContractDescriptionCallPsiCheck
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
@@ -110,7 +107,7 @@ class ContractParsingServices(val languageVersionSettings: LanguageVersionSettin
|
||||
if (!callContext.isFirstStatement)
|
||||
collector.contractNotAllowed("Contract should be the first statement")
|
||||
|
||||
if (functionDescriptor == null)
|
||||
if (functionDescriptor == null || functionDescriptor is PropertyAccessorDescriptor)
|
||||
collector.contractNotAllowed("Contracts are allowed only for functions")
|
||||
|
||||
|
||||
|
||||
+2
-2
@@ -58,11 +58,11 @@ val topLevelAnonymousFunction = fun (x: Boolean) {
|
||||
|
||||
var topLevelPropertyAccessors: Int? = 42
|
||||
get() {
|
||||
<!CONTRACT_NOT_ALLOWED!>contract<!> { returns() implies (field != null) }
|
||||
<!CONTRACT_NOT_ALLOWED, CONTRACT_NOT_ALLOWED!>contract<!> { returns() implies (field != null) }
|
||||
return 42
|
||||
}
|
||||
set(value) {
|
||||
<!CONTRACT_NOT_ALLOWED!>contract<!> { returns() implies (field != null) }
|
||||
<!CONTRACT_NOT_ALLOWED, CONTRACT_NOT_ALLOWED!>contract<!> { returns() implies (field != null) }
|
||||
}
|
||||
|
||||
|
||||
|
||||
Vendored
+5
-6
@@ -7,7 +7,6 @@
|
||||
* SECTIONS: contracts, declarations, contractFunction
|
||||
* NUMBER: 4
|
||||
* DESCRIPTION: Check that fun with contract and CallsInPlace effect is an inline function.
|
||||
* UNEXPECTED BEHAVIOUR
|
||||
* ISSUES: KT-27090
|
||||
*/
|
||||
|
||||
@@ -16,7 +15,7 @@ import kotlin.contracts.*
|
||||
// TESTCASE NUMBER: 1
|
||||
val Boolean.case_1: () -> Unit
|
||||
get() {
|
||||
contract {
|
||||
<!CONTRACT_NOT_ALLOWED!>contract<!> {
|
||||
returns() implies (this@case_1)
|
||||
}
|
||||
return {}
|
||||
@@ -25,7 +24,7 @@ val Boolean.case_1: () -> Unit
|
||||
// TESTCASE NUMBER: 2
|
||||
val (() -> Unit).case_2: () -> Unit
|
||||
get() {
|
||||
contract {
|
||||
<!CONTRACT_NOT_ALLOWED!>contract<!> {
|
||||
callsInPlace(this@case_2, InvocationKind.EXACTLY_ONCE)
|
||||
}
|
||||
return {}
|
||||
@@ -37,7 +36,7 @@ var Boolean.case_3: () -> Unit
|
||||
return {}
|
||||
}
|
||||
set(value) {
|
||||
contract {
|
||||
<!CONTRACT_NOT_ALLOWED!>contract<!> {
|
||||
callsInPlace(value, InvocationKind.EXACTLY_ONCE)
|
||||
}
|
||||
}
|
||||
@@ -48,7 +47,7 @@ var (() -> Unit).case_4: () -> Unit
|
||||
return {}
|
||||
}
|
||||
set(value) {
|
||||
contract {
|
||||
<!CONTRACT_NOT_ALLOWED!>contract<!> {
|
||||
callsInPlace(this@case_4, InvocationKind.EXACTLY_ONCE)
|
||||
}
|
||||
}
|
||||
@@ -56,7 +55,7 @@ var (() -> Unit).case_4: () -> Unit
|
||||
// TESTCASE NUMBER: 5
|
||||
val Boolean.case_5: () -> Unit
|
||||
get() {
|
||||
contract {
|
||||
<!CONTRACT_NOT_ALLOWED!>contract<!> {
|
||||
returns() implies (this@case_5)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user