Allow contracts on final non-override members since 1.4

This commit is contained in:
Dmitriy Novozhilov
2019-12-26 11:53:27 +03:00
parent 5a9070b6da
commit f083edfac2
34 changed files with 682 additions and 45 deletions
@@ -246,11 +246,15 @@ public class KtNamedFunction extends KtTypeParameterListOwnerStub<KotlinFunction
}
public boolean mayHaveContract() {
return mayHaveContract(true);
}
public boolean mayHaveContract(boolean isAllowedOnMembers) {
KotlinFunctionStub stub = getStub();
if (stub != null) {
return stub.mayHaveContract();
}
return KtPsiUtilKt.isContractPresentPsiCheck(this);
return KtPsiUtilKt.isContractPresentPsiCheck(this, isAllowedOnMembers);
}
}
@@ -296,9 +296,9 @@ inline fun <reified T : KtElement, R> flatMapDescendantsOfTypeVisitor(
// ----------- Contracts -------------------------------------------------------------------------------------------------------------------
fun KtNamedFunction.isContractPresentPsiCheck(): Boolean {
fun KtNamedFunction.isContractPresentPsiCheck(isAllowedOnMembers: Boolean): Boolean {
val contractAllowedHere =
isTopLevel &&
(isAllowedOnMembers || isTopLevel) &&
hasBlockBody() &&
!hasModifier(KtTokens.OPERATOR_KEYWORD)
if (!contractAllowedHere) return false