From f95f3dd43858ef8f99a8ce405cc02d00c1e9186e Mon Sep 17 00:00:00 2001 From: Maksim Zuev Date: Thu, 24 Oct 2024 13:02:49 +0200 Subject: [PATCH] [kotlin debugger] IDEA-361168 Fix smart step into constructor with value class params GitOrigin-RevId: 5196ca3224053a436403bee997801d51600b6662 --- .../base/util/KotlinDebuggerConstants.kt | 1 + .../stepping/KotlinSteppingCommandProvider.kt | 2 +- .../KotlinSmartStepTargetFilterer.kt | 15 ++++++++++++++- .../K2IdeK1CodeKotlinSteppingTestGenerated.java | 5 +++++ .../K2IdeK2CodeKotlinSteppingTestGenerated.java | 5 +++++ .../K2IndyLambdaKotlinSteppingTestGenerated.java | 5 +++++ .../IndyLambdaIrKotlinSteppingTestGenerated.java | 5 +++++ .../test/IrKotlinSteppingTestGenerated.java | 5 +++++ .../K1IdeK2CodeKotlinSteppingTestGenerated.java | 5 +++++ ...martStepIntoConstructorWithValueClassParam.kt | 16 ++++++++++++++++ ...artStepIntoConstructorWithValueClassParam.out | 8 ++++++++ 11 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 plugins/kotlin/jvm-debugger/test/testData/stepping/custom/smartStepIntoConstructorWithValueClassParam.kt create mode 100644 plugins/kotlin/jvm-debugger/test/testData/stepping/custom/smartStepIntoConstructorWithValueClassParam.out diff --git a/plugins/kotlin/jvm-debugger/base/util/src/org/jetbrains/kotlin/idea/debugger/base/util/KotlinDebuggerConstants.kt b/plugins/kotlin/jvm-debugger/base/util/src/org/jetbrains/kotlin/idea/debugger/base/util/KotlinDebuggerConstants.kt index 1ca52464ca9a4..c6064d1b8d18c 100644 --- a/plugins/kotlin/jvm-debugger/base/util/src/org/jetbrains/kotlin/idea/debugger/base/util/KotlinDebuggerConstants.kt +++ b/plugins/kotlin/jvm-debugger/base/util/src/org/jetbrains/kotlin/idea/debugger/base/util/KotlinDebuggerConstants.kt @@ -31,4 +31,5 @@ object KotlinDebuggerConstants { const val INLINE_SCOPE_NUMBER_SEPARATOR = '\\' val INLINE_ONLY_ANNOTATION_FQ_NAME = FqName("kotlin.internal.InlineOnly") + val DEFAULT_CONSTRUCTOR_MARKER_FQ_NAME = FqName("kotlin.jvm.internal.DefaultConstructorMarker") } diff --git a/plugins/kotlin/jvm-debugger/core/src/org/jetbrains/kotlin/idea/debugger/core/stepping/KotlinSteppingCommandProvider.kt b/plugins/kotlin/jvm-debugger/core/src/org/jetbrains/kotlin/idea/debugger/core/stepping/KotlinSteppingCommandProvider.kt index 0e4a24a0b864a..7c5cbe9255c44 100644 --- a/plugins/kotlin/jvm-debugger/core/src/org/jetbrains/kotlin/idea/debugger/core/stepping/KotlinSteppingCommandProvider.kt +++ b/plugins/kotlin/jvm-debugger/core/src/org/jetbrains/kotlin/idea/debugger/core/stepping/KotlinSteppingCommandProvider.kt @@ -241,7 +241,7 @@ fun Method.isSyntheticMethodForDefaultParameters(): Boolean { if (size < 3) return false // We should check not only the marker parameter, as it is present also // for object constructor and sealed class constructor - return arguments[size - 2] == "int" && arguments[size - 1] == "kotlin.jvm.internal.DefaultConstructorMarker" + return arguments[size - 2] == "int" && arguments[size - 1] == KotlinDebuggerConstants.DEFAULT_CONSTRUCTOR_MARKER_FQ_NAME.asString() } private fun isInlineFunctionFromLibrary(positionManager: PositionManager, location: Location, token: LocationToken): Boolean { diff --git a/plugins/kotlin/jvm-debugger/core/src/org/jetbrains/kotlin/idea/debugger/stepping/smartStepInto/KotlinSmartStepTargetFilterer.kt b/plugins/kotlin/jvm-debugger/core/src/org/jetbrains/kotlin/idea/debugger/stepping/smartStepInto/KotlinSmartStepTargetFilterer.kt index 21ae5b549cc48..698c1fc3cd5cf 100644 --- a/plugins/kotlin/jvm-debugger/core/src/org/jetbrains/kotlin/idea/debugger/stepping/smartStepInto/KotlinSmartStepTargetFilterer.kt +++ b/plugins/kotlin/jvm-debugger/core/src/org/jetbrains/kotlin/idea/debugger/stepping/smartStepInto/KotlinSmartStepTargetFilterer.kt @@ -2,6 +2,7 @@ package org.jetbrains.kotlin.idea.debugger.stepping.smartStepInto import com.intellij.debugger.engine.DebugProcessImpl +import com.intellij.debugger.engine.JVMNameUtil import com.intellij.debugger.impl.DebuggerUtilsEx import com.intellij.openapi.application.readAction import com.intellij.openapi.application.runReadAction @@ -19,6 +20,7 @@ import org.jetbrains.kotlin.analysis.api.types.KaClassType import org.jetbrains.kotlin.analysis.api.types.KaType import org.jetbrains.kotlin.analysis.api.types.KaTypeParameterType import org.jetbrains.kotlin.asJava.LightClassUtil +import org.jetbrains.kotlin.fileClasses.internalNameWithoutInnerClasses import org.jetbrains.kotlin.idea.debugger.base.util.KotlinDebuggerConstants import org.jetbrains.kotlin.idea.debugger.base.util.fqnToInternalName import org.jetbrains.kotlin.idea.debugger.base.util.internalNameToFqn @@ -80,6 +82,7 @@ class KotlinSmartStepTargetFilterer( .handleMangling(methodInfo) .handleValueClassMethods(methodInfo) .handleDefaultArgs() + .handleDefaultConstructorMarker() .handleDefaultInterfaces() .handleAccessMethods() .handleInvokeSuspend(methodInfo) @@ -123,7 +126,7 @@ class KotlinSmartStepTargetFilterer( context(KaSession) private fun primaryConstructorMatches(declaration: KtClass, owner: String, name: String, signature: String): Boolean { - if (name != "" || signature != "()V") return false + if (name != JVMNameUtil.CONSTRUCTOR_NAME || signature != "()V") return false val symbol = declaration.symbol as? KaClassSymbol ?: return false val internalClassName = symbol.getJvmInternalName() return owner == internalClassName @@ -187,6 +190,16 @@ private fun BytecodeSignature.handleDefaultArgs(): BytecodeSignature { ) } +private fun BytecodeSignature.handleDefaultConstructorMarker(): BytecodeSignature { + if (name != JVMNameUtil.CONSTRUCTOR_NAME) return this + val type = Type.getType(signature) + val defaultMarkerDescriptor = KotlinDebuggerConstants.DEFAULT_CONSTRUCTOR_MARKER_FQ_NAME + .internalNameWithoutInnerClasses + .internalNameToReferenceTypeName() + if (type.argumentTypes.lastOrNull()?.descriptor != defaultMarkerDescriptor) return this + return copy(signature = buildSignature(signature, dropCount = 1, fromStart = false)) +} + private fun BytecodeSignature.handleDefaultInterfaces(): BytecodeSignature { if (!owner.endsWith(JvmAbi.DEFAULT_IMPLS_SUFFIX)) return this return copy( diff --git a/plugins/kotlin/jvm-debugger/test/k2/test/org/jetbrains/kotlin/idea/k2/debugger/test/cases/K2IdeK1CodeKotlinSteppingTestGenerated.java b/plugins/kotlin/jvm-debugger/test/k2/test/org/jetbrains/kotlin/idea/k2/debugger/test/cases/K2IdeK1CodeKotlinSteppingTestGenerated.java index 37309e9553539..58f1e9c780fd5 100644 --- a/plugins/kotlin/jvm-debugger/test/k2/test/org/jetbrains/kotlin/idea/k2/debugger/test/cases/K2IdeK1CodeKotlinSteppingTestGenerated.java +++ b/plugins/kotlin/jvm-debugger/test/k2/test/org/jetbrains/kotlin/idea/k2/debugger/test/cases/K2IdeK1CodeKotlinSteppingTestGenerated.java @@ -1698,6 +1698,11 @@ public void testSmartStepIntoConstructor() throws Exception { runTest("../testData/stepping/custom/smartStepIntoConstructor.kt"); } + @TestMetadata("smartStepIntoConstructorWithValueClassParam.kt") + public void testSmartStepIntoConstructorWithValueClassParam() throws Exception { + runTest("../testData/stepping/custom/smartStepIntoConstructorWithValueClassParam.kt"); + } + @TestMetadata("smartStepIntoDeferredLambdas.kt") public void testSmartStepIntoDeferredLambdas() throws Exception { runTest("../testData/stepping/custom/smartStepIntoDeferredLambdas.kt"); diff --git a/plugins/kotlin/jvm-debugger/test/k2/test/org/jetbrains/kotlin/idea/k2/debugger/test/cases/K2IdeK2CodeKotlinSteppingTestGenerated.java b/plugins/kotlin/jvm-debugger/test/k2/test/org/jetbrains/kotlin/idea/k2/debugger/test/cases/K2IdeK2CodeKotlinSteppingTestGenerated.java index 1211e85672399..20943e3f4a60b 100644 --- a/plugins/kotlin/jvm-debugger/test/k2/test/org/jetbrains/kotlin/idea/k2/debugger/test/cases/K2IdeK2CodeKotlinSteppingTestGenerated.java +++ b/plugins/kotlin/jvm-debugger/test/k2/test/org/jetbrains/kotlin/idea/k2/debugger/test/cases/K2IdeK2CodeKotlinSteppingTestGenerated.java @@ -1698,6 +1698,11 @@ public void testSmartStepIntoConstructor() throws Exception { runTest("../testData/stepping/custom/smartStepIntoConstructor.kt"); } + @TestMetadata("smartStepIntoConstructorWithValueClassParam.kt") + public void testSmartStepIntoConstructorWithValueClassParam() throws Exception { + runTest("../testData/stepping/custom/smartStepIntoConstructorWithValueClassParam.kt"); + } + @TestMetadata("smartStepIntoDeferredLambdas.kt") public void testSmartStepIntoDeferredLambdas() throws Exception { runTest("../testData/stepping/custom/smartStepIntoDeferredLambdas.kt"); diff --git a/plugins/kotlin/jvm-debugger/test/k2/test/org/jetbrains/kotlin/idea/k2/debugger/test/cases/K2IndyLambdaKotlinSteppingTestGenerated.java b/plugins/kotlin/jvm-debugger/test/k2/test/org/jetbrains/kotlin/idea/k2/debugger/test/cases/K2IndyLambdaKotlinSteppingTestGenerated.java index b5f9f7689c3b3..e3f26daf497ec 100644 --- a/plugins/kotlin/jvm-debugger/test/k2/test/org/jetbrains/kotlin/idea/k2/debugger/test/cases/K2IndyLambdaKotlinSteppingTestGenerated.java +++ b/plugins/kotlin/jvm-debugger/test/k2/test/org/jetbrains/kotlin/idea/k2/debugger/test/cases/K2IndyLambdaKotlinSteppingTestGenerated.java @@ -1698,6 +1698,11 @@ public void testSmartStepIntoConstructor() throws Exception { runTest("../testData/stepping/custom/smartStepIntoConstructor.kt"); } + @TestMetadata("smartStepIntoConstructorWithValueClassParam.kt") + public void testSmartStepIntoConstructorWithValueClassParam() throws Exception { + runTest("../testData/stepping/custom/smartStepIntoConstructorWithValueClassParam.kt"); + } + @TestMetadata("smartStepIntoDeferredLambdas.kt") public void testSmartStepIntoDeferredLambdas() throws Exception { runTest("../testData/stepping/custom/smartStepIntoDeferredLambdas.kt"); diff --git a/plugins/kotlin/jvm-debugger/test/test/org/jetbrains/kotlin/idea/debugger/test/IndyLambdaIrKotlinSteppingTestGenerated.java b/plugins/kotlin/jvm-debugger/test/test/org/jetbrains/kotlin/idea/debugger/test/IndyLambdaIrKotlinSteppingTestGenerated.java index eab2e6a3da8f6..8155f3d2436f5 100644 --- a/plugins/kotlin/jvm-debugger/test/test/org/jetbrains/kotlin/idea/debugger/test/IndyLambdaIrKotlinSteppingTestGenerated.java +++ b/plugins/kotlin/jvm-debugger/test/test/org/jetbrains/kotlin/idea/debugger/test/IndyLambdaIrKotlinSteppingTestGenerated.java @@ -1698,6 +1698,11 @@ public void testSmartStepIntoConstructor() throws Exception { runTest("testData/stepping/custom/smartStepIntoConstructor.kt"); } + @TestMetadata("smartStepIntoConstructorWithValueClassParam.kt") + public void testSmartStepIntoConstructorWithValueClassParam() throws Exception { + runTest("testData/stepping/custom/smartStepIntoConstructorWithValueClassParam.kt"); + } + @TestMetadata("smartStepIntoDeferredLambdas.kt") public void testSmartStepIntoDeferredLambdas() throws Exception { runTest("testData/stepping/custom/smartStepIntoDeferredLambdas.kt"); diff --git a/plugins/kotlin/jvm-debugger/test/test/org/jetbrains/kotlin/idea/debugger/test/IrKotlinSteppingTestGenerated.java b/plugins/kotlin/jvm-debugger/test/test/org/jetbrains/kotlin/idea/debugger/test/IrKotlinSteppingTestGenerated.java index 01af103286239..e608f870bbc1c 100644 --- a/plugins/kotlin/jvm-debugger/test/test/org/jetbrains/kotlin/idea/debugger/test/IrKotlinSteppingTestGenerated.java +++ b/plugins/kotlin/jvm-debugger/test/test/org/jetbrains/kotlin/idea/debugger/test/IrKotlinSteppingTestGenerated.java @@ -1698,6 +1698,11 @@ public void testSmartStepIntoConstructor() throws Exception { runTest("testData/stepping/custom/smartStepIntoConstructor.kt"); } + @TestMetadata("smartStepIntoConstructorWithValueClassParam.kt") + public void testSmartStepIntoConstructorWithValueClassParam() throws Exception { + runTest("testData/stepping/custom/smartStepIntoConstructorWithValueClassParam.kt"); + } + @TestMetadata("smartStepIntoDeferredLambdas.kt") public void testSmartStepIntoDeferredLambdas() throws Exception { runTest("testData/stepping/custom/smartStepIntoDeferredLambdas.kt"); diff --git a/plugins/kotlin/jvm-debugger/test/test/org/jetbrains/kotlin/idea/debugger/test/K1IdeK2CodeKotlinSteppingTestGenerated.java b/plugins/kotlin/jvm-debugger/test/test/org/jetbrains/kotlin/idea/debugger/test/K1IdeK2CodeKotlinSteppingTestGenerated.java index 5f8ff173155fa..ac411905eeb33 100644 --- a/plugins/kotlin/jvm-debugger/test/test/org/jetbrains/kotlin/idea/debugger/test/K1IdeK2CodeKotlinSteppingTestGenerated.java +++ b/plugins/kotlin/jvm-debugger/test/test/org/jetbrains/kotlin/idea/debugger/test/K1IdeK2CodeKotlinSteppingTestGenerated.java @@ -1698,6 +1698,11 @@ public void testSmartStepIntoConstructor() throws Exception { runTest("testData/stepping/custom/smartStepIntoConstructor.kt"); } + @TestMetadata("smartStepIntoConstructorWithValueClassParam.kt") + public void testSmartStepIntoConstructorWithValueClassParam() throws Exception { + runTest("testData/stepping/custom/smartStepIntoConstructorWithValueClassParam.kt"); + } + @TestMetadata("smartStepIntoDeferredLambdas.kt") public void testSmartStepIntoDeferredLambdas() throws Exception { runTest("testData/stepping/custom/smartStepIntoDeferredLambdas.kt"); diff --git a/plugins/kotlin/jvm-debugger/test/testData/stepping/custom/smartStepIntoConstructorWithValueClassParam.kt b/plugins/kotlin/jvm-debugger/test/testData/stepping/custom/smartStepIntoConstructorWithValueClassParam.kt new file mode 100644 index 0000000000000..8892b9d643804 --- /dev/null +++ b/plugins/kotlin/jvm-debugger/test/testData/stepping/custom/smartStepIntoConstructorWithValueClassParam.kt @@ -0,0 +1,16 @@ +package smartStepIntoConstructorWithValueClassParam + +class Clazz(var name: String, var age: UInt) { + fun foo() = name +} + +fun testValueClass() { + // SMART_STEP_INTO_BY_INDEX: 2 + // RESUME: 1 + //Breakpoint! + Clazz("hello", 42u).foo() +} + +fun main() { + testValueClass() +} diff --git a/plugins/kotlin/jvm-debugger/test/testData/stepping/custom/smartStepIntoConstructorWithValueClassParam.out b/plugins/kotlin/jvm-debugger/test/testData/stepping/custom/smartStepIntoConstructorWithValueClassParam.out new file mode 100644 index 0000000000000..34f74b9480237 --- /dev/null +++ b/plugins/kotlin/jvm-debugger/test/testData/stepping/custom/smartStepIntoConstructorWithValueClassParam.out @@ -0,0 +1,8 @@ +LineBreakpoint created at smartStepIntoConstructorWithValueClassParam.kt:11 +Run Java +Connected to the target VM +smartStepIntoConstructorWithValueClassParam.kt:11 +smartStepIntoConstructorWithValueClassParam.kt:4 +Disconnected from the target VM + +Process finished with exit code 0