Use information from stub for contracts presence

This commit is contained in:
Nikolay Krasko
2018-10-11 11:49:05 +03:00
parent d3ec145f13
commit ac2bc22f54
2 changed files with 10 additions and 10 deletions
@@ -255,17 +255,17 @@ class FunctionDescriptorResolver(
dataFlowInfo: DataFlowInfo,
function: KtFunction
): LazyContractProvider? {
val provideByDeferredForceResolve = LazyContractProvider {
expressionTypingServices.getBodyExpressionType(trace, scope, dataFlowInfo, function, functionDescriptor)
}
if (function !is KtNamedFunction) return null
val isContractsEnabled = languageVersionSettings.supportsFeature(LanguageFeature.AllowContractsForCustomFunctions) ||
// We need to enable contracts if we're compiling "kotlin"-package to be able to ship contracts in stdlib in 1.2
languageVersionSettings.getFlag(AnalysisFlags.allowKotlinPackage)
if (!isContractsEnabled || !function.isContractPresentPsiCheck()) return null
if (!isContractsEnabled || !function.mayHaveContract()) return null
return provideByDeferredForceResolve
return LazyContractProvider {
expressionTypingServices.getBodyExpressionType(trace, scope, dataFlowInfo, function, functionDescriptor)
}
}
private fun createValueParameterDescriptors(
@@ -293,11 +293,11 @@ inline fun <reified T : KtElement, R> flatMapDescendantsOfTypeVisitor(
// ----------- Contracts -------------------------------------------------------------------------------------------------------------------
fun KtElement.isContractPresentPsiCheck(): Boolean {
val contractAllowedHere = this is KtNamedFunction &&
isTopLevel &&
hasBlockBody() &&
!hasModifier(KtTokens.OPERATOR_KEYWORD)
fun KtNamedFunction.isContractPresentPsiCheck(): Boolean {
val contractAllowedHere =
isTopLevel &&
hasBlockBody() &&
!hasModifier(KtTokens.OPERATOR_KEYWORD)
if (!contractAllowedHere) return false
val firstExpression = ((this as? KtFunction)?.bodyExpression as? KtBlockExpression)?.statements?.firstOrNull() ?: return false