Use information from stub for contracts presence
This commit is contained in:
@@ -255,17 +255,17 @@ class FunctionDescriptorResolver(
|
|||||||
dataFlowInfo: DataFlowInfo,
|
dataFlowInfo: DataFlowInfo,
|
||||||
function: KtFunction
|
function: KtFunction
|
||||||
): LazyContractProvider? {
|
): LazyContractProvider? {
|
||||||
val provideByDeferredForceResolve = LazyContractProvider {
|
if (function !is KtNamedFunction) return null
|
||||||
expressionTypingServices.getBodyExpressionType(trace, scope, dataFlowInfo, function, functionDescriptor)
|
|
||||||
}
|
|
||||||
|
|
||||||
val isContractsEnabled = languageVersionSettings.supportsFeature(LanguageFeature.AllowContractsForCustomFunctions) ||
|
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
|
// 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)
|
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(
|
private fun createValueParameterDescriptors(
|
||||||
|
|||||||
@@ -293,11 +293,11 @@ inline fun <reified T : KtElement, R> flatMapDescendantsOfTypeVisitor(
|
|||||||
|
|
||||||
// ----------- Contracts -------------------------------------------------------------------------------------------------------------------
|
// ----------- Contracts -------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
fun KtElement.isContractPresentPsiCheck(): Boolean {
|
fun KtNamedFunction.isContractPresentPsiCheck(): Boolean {
|
||||||
val contractAllowedHere = this is KtNamedFunction &&
|
val contractAllowedHere =
|
||||||
isTopLevel &&
|
isTopLevel &&
|
||||||
hasBlockBody() &&
|
hasBlockBody() &&
|
||||||
!hasModifier(KtTokens.OPERATOR_KEYWORD)
|
!hasModifier(KtTokens.OPERATOR_KEYWORD)
|
||||||
if (!contractAllowedHere) return false
|
if (!contractAllowedHere) return false
|
||||||
|
|
||||||
val firstExpression = ((this as? KtFunction)?.bodyExpression as? KtBlockExpression)?.statements?.firstOrNull() ?: return false
|
val firstExpression = ((this as? KtFunction)?.bodyExpression as? KtBlockExpression)?.statements?.firstOrNull() ?: return false
|
||||||
|
|||||||
Reference in New Issue
Block a user