Skip to content

Commit f95f3dd

Browse files
zuevmaximintellij-monorepo-bot
authored andcommitted
[kotlin debugger] IDEA-361168 Fix smart step into constructor with value class params
GitOrigin-RevId: 5196ca3224053a436403bee997801d51600b6662
1 parent 8b3f52a commit f95f3dd

File tree

11 files changed

+70
-2
lines changed

11 files changed

+70
-2
lines changed

plugins/kotlin/jvm-debugger/base/util/src/org/jetbrains/kotlin/idea/debugger/base/util/KotlinDebuggerConstants.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@ object KotlinDebuggerConstants {
3131
const val INLINE_SCOPE_NUMBER_SEPARATOR = '\\'
3232

3333
val INLINE_ONLY_ANNOTATION_FQ_NAME = FqName("kotlin.internal.InlineOnly")
34+
val DEFAULT_CONSTRUCTOR_MARKER_FQ_NAME = FqName("kotlin.jvm.internal.DefaultConstructorMarker")
3435
}

plugins/kotlin/jvm-debugger/core/src/org/jetbrains/kotlin/idea/debugger/core/stepping/KotlinSteppingCommandProvider.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ fun Method.isSyntheticMethodForDefaultParameters(): Boolean {
241241
if (size < 3) return false
242242
// We should check not only the marker parameter, as it is present also
243243
// for object constructor and sealed class constructor
244-
return arguments[size - 2] == "int" && arguments[size - 1] == "kotlin.jvm.internal.DefaultConstructorMarker"
244+
return arguments[size - 2] == "int" && arguments[size - 1] == KotlinDebuggerConstants.DEFAULT_CONSTRUCTOR_MARKER_FQ_NAME.asString()
245245
}
246246

247247
private fun isInlineFunctionFromLibrary(positionManager: PositionManager, location: Location, token: LocationToken): Boolean {

plugins/kotlin/jvm-debugger/core/src/org/jetbrains/kotlin/idea/debugger/stepping/smartStepInto/KotlinSmartStepTargetFilterer.kt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
package org.jetbrains.kotlin.idea.debugger.stepping.smartStepInto
33

44
import com.intellij.debugger.engine.DebugProcessImpl
5+
import com.intellij.debugger.engine.JVMNameUtil
56
import com.intellij.debugger.impl.DebuggerUtilsEx
67
import com.intellij.openapi.application.readAction
78
import com.intellij.openapi.application.runReadAction
@@ -19,6 +20,7 @@ import org.jetbrains.kotlin.analysis.api.types.KaClassType
1920
import org.jetbrains.kotlin.analysis.api.types.KaType
2021
import org.jetbrains.kotlin.analysis.api.types.KaTypeParameterType
2122
import org.jetbrains.kotlin.asJava.LightClassUtil
23+
import org.jetbrains.kotlin.fileClasses.internalNameWithoutInnerClasses
2224
import org.jetbrains.kotlin.idea.debugger.base.util.KotlinDebuggerConstants
2325
import org.jetbrains.kotlin.idea.debugger.base.util.fqnToInternalName
2426
import org.jetbrains.kotlin.idea.debugger.base.util.internalNameToFqn
@@ -80,6 +82,7 @@ class KotlinSmartStepTargetFilterer(
8082
.handleMangling(methodInfo)
8183
.handleValueClassMethods(methodInfo)
8284
.handleDefaultArgs()
85+
.handleDefaultConstructorMarker()
8386
.handleDefaultInterfaces()
8487
.handleAccessMethods()
8588
.handleInvokeSuspend(methodInfo)
@@ -123,7 +126,7 @@ class KotlinSmartStepTargetFilterer(
123126

124127
context(KaSession)
125128
private fun primaryConstructorMatches(declaration: KtClass, owner: String, name: String, signature: String): Boolean {
126-
if (name != "<init>" || signature != "()V") return false
129+
if (name != JVMNameUtil.CONSTRUCTOR_NAME || signature != "()V") return false
127130
val symbol = declaration.symbol as? KaClassSymbol ?: return false
128131
val internalClassName = symbol.getJvmInternalName()
129132
return owner == internalClassName
@@ -187,6 +190,16 @@ private fun BytecodeSignature.handleDefaultArgs(): BytecodeSignature {
187190
)
188191
}
189192

193+
private fun BytecodeSignature.handleDefaultConstructorMarker(): BytecodeSignature {
194+
if (name != JVMNameUtil.CONSTRUCTOR_NAME) return this
195+
val type = Type.getType(signature)
196+
val defaultMarkerDescriptor = KotlinDebuggerConstants.DEFAULT_CONSTRUCTOR_MARKER_FQ_NAME
197+
.internalNameWithoutInnerClasses
198+
.internalNameToReferenceTypeName()
199+
if (type.argumentTypes.lastOrNull()?.descriptor != defaultMarkerDescriptor) return this
200+
return copy(signature = buildSignature(signature, dropCount = 1, fromStart = false))
201+
}
202+
190203
private fun BytecodeSignature.handleDefaultInterfaces(): BytecodeSignature {
191204
if (!owner.endsWith(JvmAbi.DEFAULT_IMPLS_SUFFIX)) return this
192205
return copy(

plugins/kotlin/jvm-debugger/test/k2/test/org/jetbrains/kotlin/idea/k2/debugger/test/cases/K2IdeK1CodeKotlinSteppingTestGenerated.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,6 +1698,11 @@ public void testSmartStepIntoConstructor() throws Exception {
16981698
runTest("../testData/stepping/custom/smartStepIntoConstructor.kt");
16991699
}
17001700

1701+
@TestMetadata("smartStepIntoConstructorWithValueClassParam.kt")
1702+
public void testSmartStepIntoConstructorWithValueClassParam() throws Exception {
1703+
runTest("../testData/stepping/custom/smartStepIntoConstructorWithValueClassParam.kt");
1704+
}
1705+
17011706
@TestMetadata("smartStepIntoDeferredLambdas.kt")
17021707
public void testSmartStepIntoDeferredLambdas() throws Exception {
17031708
runTest("../testData/stepping/custom/smartStepIntoDeferredLambdas.kt");

plugins/kotlin/jvm-debugger/test/k2/test/org/jetbrains/kotlin/idea/k2/debugger/test/cases/K2IdeK2CodeKotlinSteppingTestGenerated.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,6 +1698,11 @@ public void testSmartStepIntoConstructor() throws Exception {
16981698
runTest("../testData/stepping/custom/smartStepIntoConstructor.kt");
16991699
}
17001700

1701+
@TestMetadata("smartStepIntoConstructorWithValueClassParam.kt")
1702+
public void testSmartStepIntoConstructorWithValueClassParam() throws Exception {
1703+
runTest("../testData/stepping/custom/smartStepIntoConstructorWithValueClassParam.kt");
1704+
}
1705+
17011706
@TestMetadata("smartStepIntoDeferredLambdas.kt")
17021707
public void testSmartStepIntoDeferredLambdas() throws Exception {
17031708
runTest("../testData/stepping/custom/smartStepIntoDeferredLambdas.kt");

plugins/kotlin/jvm-debugger/test/k2/test/org/jetbrains/kotlin/idea/k2/debugger/test/cases/K2IndyLambdaKotlinSteppingTestGenerated.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,6 +1698,11 @@ public void testSmartStepIntoConstructor() throws Exception {
16981698
runTest("../testData/stepping/custom/smartStepIntoConstructor.kt");
16991699
}
17001700

1701+
@TestMetadata("smartStepIntoConstructorWithValueClassParam.kt")
1702+
public void testSmartStepIntoConstructorWithValueClassParam() throws Exception {
1703+
runTest("../testData/stepping/custom/smartStepIntoConstructorWithValueClassParam.kt");
1704+
}
1705+
17011706
@TestMetadata("smartStepIntoDeferredLambdas.kt")
17021707
public void testSmartStepIntoDeferredLambdas() throws Exception {
17031708
runTest("../testData/stepping/custom/smartStepIntoDeferredLambdas.kt");

plugins/kotlin/jvm-debugger/test/test/org/jetbrains/kotlin/idea/debugger/test/IndyLambdaIrKotlinSteppingTestGenerated.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,6 +1698,11 @@ public void testSmartStepIntoConstructor() throws Exception {
16981698
runTest("testData/stepping/custom/smartStepIntoConstructor.kt");
16991699
}
17001700

1701+
@TestMetadata("smartStepIntoConstructorWithValueClassParam.kt")
1702+
public void testSmartStepIntoConstructorWithValueClassParam() throws Exception {
1703+
runTest("testData/stepping/custom/smartStepIntoConstructorWithValueClassParam.kt");
1704+
}
1705+
17011706
@TestMetadata("smartStepIntoDeferredLambdas.kt")
17021707
public void testSmartStepIntoDeferredLambdas() throws Exception {
17031708
runTest("testData/stepping/custom/smartStepIntoDeferredLambdas.kt");

plugins/kotlin/jvm-debugger/test/test/org/jetbrains/kotlin/idea/debugger/test/IrKotlinSteppingTestGenerated.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,6 +1698,11 @@ public void testSmartStepIntoConstructor() throws Exception {
16981698
runTest("testData/stepping/custom/smartStepIntoConstructor.kt");
16991699
}
17001700

1701+
@TestMetadata("smartStepIntoConstructorWithValueClassParam.kt")
1702+
public void testSmartStepIntoConstructorWithValueClassParam() throws Exception {
1703+
runTest("testData/stepping/custom/smartStepIntoConstructorWithValueClassParam.kt");
1704+
}
1705+
17011706
@TestMetadata("smartStepIntoDeferredLambdas.kt")
17021707
public void testSmartStepIntoDeferredLambdas() throws Exception {
17031708
runTest("testData/stepping/custom/smartStepIntoDeferredLambdas.kt");

plugins/kotlin/jvm-debugger/test/test/org/jetbrains/kotlin/idea/debugger/test/K1IdeK2CodeKotlinSteppingTestGenerated.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,6 +1698,11 @@ public void testSmartStepIntoConstructor() throws Exception {
16981698
runTest("testData/stepping/custom/smartStepIntoConstructor.kt");
16991699
}
17001700

1701+
@TestMetadata("smartStepIntoConstructorWithValueClassParam.kt")
1702+
public void testSmartStepIntoConstructorWithValueClassParam() throws Exception {
1703+
runTest("testData/stepping/custom/smartStepIntoConstructorWithValueClassParam.kt");
1704+
}
1705+
17011706
@TestMetadata("smartStepIntoDeferredLambdas.kt")
17021707
public void testSmartStepIntoDeferredLambdas() throws Exception {
17031708
runTest("testData/stepping/custom/smartStepIntoDeferredLambdas.kt");
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package smartStepIntoConstructorWithValueClassParam
2+
3+
class Clazz(var name: String, var age: UInt) {
4+
fun foo() = name
5+
}
6+
7+
fun testValueClass() {
8+
// SMART_STEP_INTO_BY_INDEX: 2
9+
// RESUME: 1
10+
//Breakpoint!
11+
Clazz("hello", 42u).foo()
12+
}
13+
14+
fun main() {
15+
testValueClass()
16+
}

0 commit comments

Comments
 (0)