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
This commit is contained in:
@@ -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<KtExpression>() {
|
||||
private val typeRenderer = DescriptorRenderer.COMPACT_WITH_SHORT_TYPES.withOptions {
|
||||
@@ -109,7 +111,7 @@ class KotlinExpressionTypeProvider : ExpressionTypeProvider<KtExpression>() {
|
||||
}
|
||||
}
|
||||
|
||||
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"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user