[kotlin-dfa] KTIJ-28008 Debugger 'is' condition evaluation is incorrect when variable value has object type

GitOrigin-RevId: 04aeaea8818f9bf690394d2884235c3474d3152e
This commit is contained in:
Tagir Valeev
2023-12-01 18:37:13 +00:00
committed by intellij-monorepo-bot
parent 0d18a62f01
commit f23adba5b9
3 changed files with 22 additions and 2 deletions
@@ -95,7 +95,7 @@ class KtClassDef(val cls: ClassDescriptor) : TypeConstraints.ClassDef {
}
}
fun fromJvmClassName(context: KtElement, jvmClassName: String): TypeConstraints.ClassDef? {
fun fromJvmClassName(context: KtElement, jvmClassName: String): KtClassDef? {
var fqName = FqName.fromSegments(jvmClassName.split(Regex("[$/]")))
if (jvmClassName.startsWith("java/")) {
fqName = JavaToKotlinClassMap.mapJavaToKotlin(fqName)?.asSingleFqName() ?: fqName
@@ -23,6 +23,7 @@ import com.intellij.xdebugger.impl.dfaassist.DfaHint
import com.sun.jdi.Location
import com.sun.jdi.ObjectReference
import com.sun.jdi.Value
import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.idea.base.psi.KotlinPsiHeuristics
import org.jetbrains.kotlin.idea.caches.resolve.safeAnalyzeNonSourceRootCode
@@ -126,7 +127,7 @@ class KotlinDfaAssistProvider : DfaAssistProvider {
override fun constraintFromJvmClassName(anchor: PsiElement, jvmClassName: String): TypeConstraint {
val classDef = KtClassDef.fromJvmClassName(anchor as KtElement, jvmClassName) ?: return TypeConstraints.TOP
return TypeConstraints.exactClass(classDef)
return if (classDef.cls.kind == ClassKind.OBJECT) TypeConstraints.singleton(classDef) else TypeConstraints.exactClass(classDef)
}
class KotlinDebuggerDfaListener : DebuggerDfaListener {
@@ -218,6 +218,25 @@ class KotlinDfaAssistTest : DfaAssistTest() {
frame.setThisValue(MockObjectReference.createObjectReference(Nested(5), Nested::class.java, vm))
}
}
private interface I
private object O: I
fun testObject() {
doTest("""package org.jetbrains.kotlin.idea.debugger.test
class KotlinDfaAssistTest {
interface I
object O : I
fun test(i: I) {
<caret>if (i is O/*TRUE*/) {}
}
}
}
""") { vm, frame ->
frame.addVariable("i", MockObjectReference.createObjectReference(O, O::class.java, vm))
}
}
fun testQualified() {
doTest("""package org.jetbrains.kotlin.idea.debugger.test