[kotlin-dfa] KotlinCallableReferenceInstruction make reusable in K2

Preparatory step for KTIJ-27359 K2 IDE: migrate KotlinConstantConditionsInspection to K2

GitOrigin-RevId: 9db97910ce84944036e5f3c57320b15547afb534
This commit is contained in:
Tagir Valeev
2024-03-01 16:14:41 +01:00
committed by intellij-monorepo-bot
parent 7588e39e41
commit c2adee386b
2 changed files with 4 additions and 4 deletions

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.kotlin.idea.inspections.dfa
import com.intellij.codeInspection.dataFlow.interpreter.DataFlowInterpreter
@@ -6,18 +6,18 @@ import com.intellij.codeInspection.dataFlow.java.JavaDfaHelpers
import com.intellij.codeInspection.dataFlow.lang.ir.DfaInstructionState
import com.intellij.codeInspection.dataFlow.lang.ir.ExpressionPushingInstruction
import com.intellij.codeInspection.dataFlow.memory.DfaMemoryState
import com.intellij.codeInspection.dataFlow.types.DfType
import org.jetbrains.kotlin.psi.KtCallableReferenceExpression
/**
* Instruction to process Kotlin callable reference, assuming the qualifier is on the stack
* (or unknown value if there's no qualifier)
*/
class KotlinCallableReferenceInstruction(val expr: KtCallableReferenceExpression):
class KotlinCallableReferenceInstruction(val expr: KtCallableReferenceExpression, private val dfType: DfType):
ExpressionPushingInstruction(KotlinAnchor.KotlinExpressionAnchor(expr)) {
override fun accept(interpreter: DataFlowInterpreter, stateBefore: DfaMemoryState): Array<DfaInstructionState> {
val qualifier = stateBefore.pop()
JavaDfaHelpers.dropLocality(qualifier, stateBefore)
val dfType = expr.getKotlinType().toDfType()
pushResult(interpreter, stateBefore, dfType)
return nextStates(interpreter, stateBefore)
}

View File

@@ -256,7 +256,7 @@ class KtControlFlowBuilder(val factory: DfaValueFactory, val context: KtExpressi
private fun processCallableReference(expr: KtCallableReferenceExpression) {
processExpression(expr.receiverExpression)
addInstruction(KotlinCallableReferenceInstruction(expr))
addInstruction(KotlinCallableReferenceInstruction(expr, expr.getKotlinType().toDfType()))
}
private fun processThisExpression(expr: KtThisExpression) {