Skip to content

Commit

Permalink
[kotlin debugger] IDEA-361168 Fix smart step into constructor with va…
Browse files Browse the repository at this point in the history
…lue class params

GitOrigin-RevId: 5196ca3224053a436403bee997801d51600b6662
  • Loading branch information
zuevmaxim authored and intellij-monorepo-bot committed Oct 24, 2024
1 parent 8b3f52a commit f95f3dd
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -80,6 +82,7 @@ class KotlinSmartStepTargetFilterer(
.handleMangling(methodInfo)
.handleValueClassMethods(methodInfo)
.handleDefaultArgs()
.handleDefaultConstructorMarker()
.handleDefaultInterfaces()
.handleAccessMethods()
.handleInvokeSuspend(methodInfo)
Expand Down Expand Up @@ -123,7 +126,7 @@ class KotlinSmartStepTargetFilterer(

context(KaSession)
private fun primaryConstructorMatches(declaration: KtClass, owner: String, name: String, signature: String): Boolean {
if (name != "<init>" || 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
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
}
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f95f3dd

Please sign in to comment.