isContractPresentPsiCheck¶
fun KtNamedFunction.isContractPresentPsiCheck(isAllowedOnMembers: Boolean): Boolean
Best-effort PSI check for whether this function's body begins with a contract { ... } call, taking into account whether contracts are allowed on member functions via isAllowedOnMembers. false is definitive; true is not a guarantee.
Example:¶
@OptIn(kotlin.contracts.ExperimentalContracts::class)
fun declaredContract() {
kotlin.contracts.contract { returns() }
}
private fun contract() {}
fun sameNameOnly() {
contract()
}
This check returns true for both declaredContract and sameNameOnly: it recognizes the first call by its PSI shape and name without resolving which contract function is called.