Minor. Fix reporting diagnostic in contract with callable reference
This commit is contained in:
+4
-6
@@ -35,10 +35,7 @@ import org.jetbrains.kotlin.contracts.parsing.effects.PsiReturnsEffectParser
|
||||
import org.jetbrains.kotlin.descriptors.ParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.KtBinaryExpression
|
||||
import org.jetbrains.kotlin.psi.KtCallExpression
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.psi.KtLambdaExpression
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getType
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
@@ -129,9 +126,10 @@ internal class PsiContractParserDispatcher(
|
||||
|
||||
fun parseVariable(expression: KtExpression?): VariableReference? {
|
||||
if (expression == null) return null
|
||||
val descriptor = expression.getResolvedCall(callContext.bindingContext)?.resultingDescriptor ?: return null
|
||||
val descriptor = expression.getResolvedCall(callContext.bindingContext)?.resultingDescriptor
|
||||
if (descriptor !is ParameterDescriptor) {
|
||||
collector.badDescription("only references to parameters are allowed in contract description", expression)
|
||||
if (expression !is KtConstantExpression)
|
||||
collector.badDescription("only references to parameters are allowed in contract description", expression)
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ fun case_2(value_1: Boolean): Boolean? {
|
||||
|
||||
// TESTCASE NUMBER: 3
|
||||
fun case_3(value_1: String): Boolean {
|
||||
<!ERROR_IN_CONTRACT_DESCRIPTION!>contract<!> { returns(false) implies (value_1 != "") }
|
||||
contract { returns(false) implies (value_1 != <!ERROR_IN_CONTRACT_DESCRIPTION!>""<!>) }
|
||||
return !(value_1 != "")
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ fun case_4(value_1: Nothing?, value_2: Boolean?): Boolean? {
|
||||
|
||||
// TESTCASE NUMBER: 5
|
||||
fun case_5(value_1: Any?, value_2: String?): Boolean? {
|
||||
<!ERROR_IN_CONTRACT_DESCRIPTION!>contract<!> { returns(null) implies (value_1 != null && value_2 != null || value_2 == ".") }
|
||||
contract { returns(null) implies (value_1 != null && value_2 != null || value_2 == <!ERROR_IN_CONTRACT_DESCRIPTION!>"."<!>) }
|
||||
return if (value_1 != null && value_2 != null || value_2 == ".") null else true
|
||||
}
|
||||
|
||||
|
||||
+19
@@ -51,3 +51,22 @@ fun case_6(value_1: Boolean): Boolean? {
|
||||
contract { returns(null) implies <!ERROR_IN_CONTRACT_DESCRIPTION, TYPE_MISMATCH!><!CONTRACT_NOT_ALLOWED, CONTRACT_NOT_ALLOWED!>contract<!> { returns(null) implies (!value_1) }<!> }
|
||||
return null
|
||||
}
|
||||
|
||||
// TESTCASE NUMBER: 7
|
||||
fun case_7(): Int {
|
||||
contract {
|
||||
callsInPlace(<!ERROR_IN_CONTRACT_DESCRIPTION!>::case_7<!>, InvocationKind.EXACTLY_ONCE)
|
||||
}
|
||||
return 1
|
||||
}
|
||||
|
||||
/*
|
||||
* TESTCASE NUMBER: 8
|
||||
* ISSUES: KT-26386
|
||||
*/
|
||||
fun case_8(): () -> Unit {
|
||||
contract {
|
||||
callsInPlace(<!ERROR_IN_CONTRACT_DESCRIPTION!>case_8()<!>, InvocationKind.EXACTLY_ONCE)
|
||||
}
|
||||
return {}
|
||||
}
|
||||
+3
@@ -3,5 +3,8 @@ package
|
||||
public fun case_1(): kotlin.Boolean
|
||||
public fun case_2(): kotlin.Boolean
|
||||
public fun case_3(): kotlin.Boolean
|
||||
public fun case_4(): kotlin.Boolean?
|
||||
public fun case_5(): kotlin.Boolean?
|
||||
public fun case_6(/*0*/ value_1: kotlin.Boolean): kotlin.Boolean?
|
||||
public fun case_7(): kotlin.Int
|
||||
public fun case_8(): () -> kotlin.Unit
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ fun case_1(x: Any?): Boolean {
|
||||
|
||||
// TESTCASE NUMBER: 2
|
||||
fun case_2(x: Any?) {
|
||||
<!ERROR_IN_CONTRACT_DESCRIPTION!>contract<!> { returns() implies (x == "...") }
|
||||
contract { returns() implies (x == <!ERROR_IN_CONTRACT_DESCRIPTION!>"..."<!>) }
|
||||
if (x != "...") throw Exception()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user