From 0eba48ae4673ccb6c471b830fa47a48c8cfcbab2 Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Mon, 6 Aug 2018 17:42:53 +0700 Subject: [PATCH] Adjust KotlinExpressionTypeProvider to new DataFlowInfo contracts Now, trivial info is not being perstisted in the maps of DataFlowInfo At the same time, we don't record trivial DataFlowInfo instances in binding context: org.jetbrains.kotlin.resolve.bindingContextUtil.BindingContextUtilsKt#recordDataFlowInfo Namely, it happens in case when expression is a callee expression of "variable as function" calls (see org.jetbrains.kotlin.idea.codeInsight.ExpressionTypeTestGenerated#testKt11601) At the same time, there's a hack in `org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilKt#getType` that helps to obtain type itself for these callees from the resolved calls. So, it will work anyway if we use `noTypeInfo` here, that is kind of correct since there's no non-trivial info anyway --- .../kotlin/idea/codeInsight/KotlinExpressionTypeProvider.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinExpressionTypeProvider.kt b/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinExpressionTypeProvider.kt index b4e94e374e9..c9771223421 100644 --- a/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinExpressionTypeProvider.kt +++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinExpressionTypeProvider.kt @@ -39,8 +39,10 @@ import org.jetbrains.kotlin.renderer.RenderingFormat import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.calls.callUtil.getType +import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode +import org.jetbrains.kotlin.types.expressions.typeInfoFactory.noTypeInfo class KotlinExpressionTypeProvider : ExpressionTypeProvider() { private val typeRenderer = DescriptorRenderer.COMPACT_WITH_SHORT_TYPES.withOptions { @@ -109,7 +111,7 @@ class KotlinExpressionTypeProvider : ExpressionTypeProvider() { } } - val expressionTypeInfo = bindingContext[BindingContext.EXPRESSION_TYPE_INFO, element] ?: return "Type is unknown" + val expressionTypeInfo = bindingContext[BindingContext.EXPRESSION_TYPE_INFO, element] ?: noTypeInfo(DataFlowInfo.EMPTY) val expressionType = element.getType(bindingContext) val result = expressionType?.let { typeRenderer.renderType(it) } ?: return "Type is unknown"