Generate line numbers for closing '}' in 'init {}' blocks (KT-12787)
This commit is contained in:
@@ -472,21 +472,38 @@ public abstract class MemberCodegen<T extends KtPureElement/* TODO: & KtDeclarat
|
|||||||
return clInit;
|
return clInit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean nopSeparatorNeeded = false;
|
||||||
|
|
||||||
|
private void generateNopSeparatorIfNeeded(NotNullLazyValue<ExpressionCodegen> codegen) {
|
||||||
|
if (nopSeparatorNeeded) {
|
||||||
|
nopSeparatorNeeded = false;
|
||||||
|
codegen.invoke().v.nop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void generateInitializers(@NotNull Function0<ExpressionCodegen> createCodegen) {
|
protected void generateInitializers(@NotNull Function0<ExpressionCodegen> createCodegen) {
|
||||||
NotNullLazyValue<ExpressionCodegen> codegen = LockBasedStorageManager.NO_LOCKS.createLazyValue(createCodegen);
|
NotNullLazyValue<ExpressionCodegen> codegen = LockBasedStorageManager.NO_LOCKS.createLazyValue(createCodegen);
|
||||||
|
|
||||||
for (KtDeclaration declaration : ((KtDeclarationContainer) element).getDeclarations()) {
|
for (KtDeclaration declaration : ((KtDeclarationContainer) element).getDeclarations()) {
|
||||||
if (declaration instanceof KtProperty) {
|
if (declaration instanceof KtProperty) {
|
||||||
if (shouldInitializeProperty((KtProperty) declaration)) {
|
if (shouldInitializeProperty((KtProperty) declaration)) {
|
||||||
|
generateNopSeparatorIfNeeded(codegen);
|
||||||
initializeProperty(codegen.invoke(), (KtProperty) declaration);
|
initializeProperty(codegen.invoke(), (KtProperty) declaration);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (declaration instanceof KtDestructuringDeclaration) {
|
else if (declaration instanceof KtDestructuringDeclaration) {
|
||||||
|
generateNopSeparatorIfNeeded(codegen);
|
||||||
codegen.invoke().initializeDestructuringDeclaration((KtDestructuringDeclaration) declaration, true);
|
codegen.invoke().initializeDestructuringDeclaration((KtDestructuringDeclaration) declaration, true);
|
||||||
}
|
}
|
||||||
else if (declaration instanceof KtAnonymousInitializer) {
|
else if (declaration instanceof KtAnonymousInitializer) {
|
||||||
KtExpression body = ((KtAnonymousInitializer) declaration).getBody();
|
KtExpression body = ((KtAnonymousInitializer) declaration).getBody();
|
||||||
if (body != null) {
|
if (body != null) {
|
||||||
codegen.invoke().gen(body, Type.VOID_TYPE);
|
generateNopSeparatorIfNeeded(codegen);
|
||||||
|
|
||||||
|
ExpressionCodegen expressionCodegen = codegen.invoke();
|
||||||
|
expressionCodegen.gen(body, Type.VOID_TYPE);
|
||||||
|
expressionCodegen.markLineNumber(declaration, true);
|
||||||
|
nopSeparatorNeeded = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
class Foo {
|
||||||
|
var a: String
|
||||||
|
|
||||||
|
init {
|
||||||
|
a = x()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Bar {
|
||||||
|
init {
|
||||||
|
val a = 5
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
val b = 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Boo {
|
||||||
|
init {
|
||||||
|
val a = 5
|
||||||
|
}
|
||||||
|
|
||||||
|
val x = x()
|
||||||
|
|
||||||
|
init {
|
||||||
|
val b = 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun x() = ""
|
||||||
|
|
||||||
|
// IGNORE_BACKEND: JVM_IR
|
||||||
|
// 2 2 1 5 6 9 11 12 15 16 24 19 21 22 24 27 28 31
|
||||||
@@ -191,6 +191,11 @@ public class LineNumberTestGenerated extends AbstractLineNumberTest {
|
|||||||
runTest("compiler/testData/lineNumber/custom/inTheEndOfLambdaArgumentOfInlineCall.kt");
|
runTest("compiler/testData/lineNumber/custom/inTheEndOfLambdaArgumentOfInlineCall.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("initBlocks.kt")
|
||||||
|
public void testInitBlocks() throws Exception {
|
||||||
|
runTest("compiler/testData/lineNumber/custom/initBlocks.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("multilineFunctionCall.kt")
|
@TestMetadata("multilineFunctionCall.kt")
|
||||||
public void testMultilineFunctionCall() throws Exception {
|
public void testMultilineFunctionCall() throws Exception {
|
||||||
runTest("compiler/testData/lineNumber/custom/multilineFunctionCall.kt");
|
runTest("compiler/testData/lineNumber/custom/multilineFunctionCall.kt");
|
||||||
|
|||||||
+5
@@ -191,6 +191,11 @@ public class IrLineNumberTestGenerated extends AbstractIrLineNumberTest {
|
|||||||
runTest("compiler/testData/lineNumber/custom/inTheEndOfLambdaArgumentOfInlineCall.kt");
|
runTest("compiler/testData/lineNumber/custom/inTheEndOfLambdaArgumentOfInlineCall.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("initBlocks.kt")
|
||||||
|
public void testInitBlocks() throws Exception {
|
||||||
|
runTest("compiler/testData/lineNumber/custom/initBlocks.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("multilineFunctionCall.kt")
|
@TestMetadata("multilineFunctionCall.kt")
|
||||||
public void testMultilineFunctionCall() throws Exception {
|
public void testMultilineFunctionCall() throws Exception {
|
||||||
runTest("compiler/testData/lineNumber/custom/multilineFunctionCall.kt");
|
runTest("compiler/testData/lineNumber/custom/multilineFunctionCall.kt");
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package initBlocks
|
||||||
|
|
||||||
|
class Foo {
|
||||||
|
init {
|
||||||
|
//Breakpoint!
|
||||||
|
val a = 5
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
val b = 7
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
Foo()
|
||||||
|
}
|
||||||
|
|
||||||
|
// STEP_OVER: 5
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
LineBreakpoint created at initBlocks.kt:6
|
||||||
|
Run Java
|
||||||
|
Connected to the target VM
|
||||||
|
initBlocks.kt:6
|
||||||
|
initBlocks.kt:7
|
||||||
|
initBlocks.kt:10
|
||||||
|
initBlocks.kt:11
|
||||||
|
initBlocks.kt:15
|
||||||
|
initBlocks.kt:16
|
||||||
|
Disconnected from the target VM
|
||||||
|
|
||||||
|
Process finished with exit code 0
|
||||||
+1
-1
@@ -4,7 +4,7 @@ Connected to the target VM
|
|||||||
doNotSkipConstructors.kt:5
|
doNotSkipConstructors.kt:5
|
||||||
doNotSkipConstructors.kt:9
|
doNotSkipConstructors.kt:9
|
||||||
doNotSkipConstructors.kt:11
|
doNotSkipConstructors.kt:11
|
||||||
doNotSkipConstructors.kt:5
|
doNotSkipConstructors.kt:12
|
||||||
Disconnected from the target VM
|
Disconnected from the target VM
|
||||||
|
|
||||||
Process finished with exit code 0
|
Process finished with exit code 0
|
||||||
|
|||||||
+5
@@ -1077,6 +1077,11 @@ public class KotlinSteppingTestGenerated extends AbstractKotlinSteppingTest {
|
|||||||
runTest("idea/testData/debugger/tinyApp/src/stepping/custom/fwPropertyInInterface.kt");
|
runTest("idea/testData/debugger/tinyApp/src/stepping/custom/fwPropertyInInterface.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("initBlocks.kt")
|
||||||
|
public void testInitBlocks() throws Exception {
|
||||||
|
runTest("idea/testData/debugger/tinyApp/src/stepping/custom/initBlocks.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("inlineInObject.kt")
|
@TestMetadata("inlineInObject.kt")
|
||||||
public void testInlineInObject() throws Exception {
|
public void testInlineInObject() throws Exception {
|
||||||
runTest("idea/testData/debugger/tinyApp/src/stepping/custom/inlineInObject.kt");
|
runTest("idea/testData/debugger/tinyApp/src/stepping/custom/inlineInObject.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user