[FIR] KT-56877: Allow checking types of containing classes in contracts
This commit is contained in:
committed by
Space Team
parent
c7a71fec17
commit
c156dfe855
+6
-5
@@ -9,11 +9,9 @@ import org.jetbrains.kotlin.contracts.description.EventOccurrencesRange
|
||||
import org.jetbrains.kotlin.fir.FirElement
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.contracts.description.*
|
||||
import org.jetbrains.kotlin.fir.declarations.FirContractDescriptionOwner
|
||||
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirProperty
|
||||
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.expressions.*
|
||||
import org.jetbrains.kotlin.fir.resolve.getContainingClass
|
||||
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
||||
import org.jetbrains.kotlin.fir.types.coneType
|
||||
import org.jetbrains.kotlin.fir.visitors.FirDefaultVisitor
|
||||
@@ -156,7 +154,10 @@ class ConeEffectExtractor(
|
||||
data: Nothing?
|
||||
): ConeContractDescriptionElement? {
|
||||
val declaration = thisReceiverExpression.calleeReference.boundSymbol?.fir ?: return null
|
||||
return if (declaration == owner || owner.isAccessorOf(declaration)) {
|
||||
val callableOwner = owner as? FirCallableDeclaration
|
||||
val ownerHasReceiver = callableOwner?.receiverParameter != null
|
||||
val ownerIsMemberOfDeclaration = callableOwner?.getContainingClass(session) == declaration
|
||||
return if (declaration == owner || owner.isAccessorOf(declaration) || ownerIsMemberOfDeclaration && !ownerHasReceiver) {
|
||||
val type = thisReceiverExpression.typeRef.coneType
|
||||
toValueParameterReference(type, -1, "this")
|
||||
} else {
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ open class Result {
|
||||
|
||||
fun isSuccess1(): Boolean {
|
||||
contract {
|
||||
<!ERROR_IN_CONTRACT_DESCRIPTION!>returns(true) implies (this@Result is Success)<!>
|
||||
returns(true) implies (this@Result is Success)
|
||||
}
|
||||
return this@Result is Success
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -10,7 +10,7 @@ class Foo {
|
||||
inner class Bar {
|
||||
fun good() {
|
||||
contract {
|
||||
<!ERROR_IN_CONTRACT_DESCRIPTION!>returns() implies (this@Bar != null)<!>
|
||||
returns() implies (this@Bar != null)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user