Use information from stub for contracts presence
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user