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;
|
||||
}
|
||||
|
||||
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) {
|
||||
NotNullLazyValue<ExpressionCodegen> codegen = LockBasedStorageManager.NO_LOCKS.createLazyValue(createCodegen);
|
||||
|
||||
for (KtDeclaration declaration : ((KtDeclarationContainer) element).getDeclarations()) {
|
||||
if (declaration instanceof KtProperty) {
|
||||
if (shouldInitializeProperty((KtProperty) declaration)) {
|
||||
generateNopSeparatorIfNeeded(codegen);
|
||||
initializeProperty(codegen.invoke(), (KtProperty) declaration);
|
||||
}
|
||||
}
|
||||
else if (declaration instanceof KtDestructuringDeclaration) {
|
||||
generateNopSeparatorIfNeeded(codegen);
|
||||
codegen.invoke().initializeDestructuringDeclaration((KtDestructuringDeclaration) declaration, true);
|
||||
}
|
||||
else if (declaration instanceof KtAnonymousInitializer) {
|
||||
KtExpression body = ((KtAnonymousInitializer) declaration).getBody();
|
||||
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");
|
||||
}
|
||||
|
||||
@TestMetadata("initBlocks.kt")
|
||||
public void testInitBlocks() throws Exception {
|
||||
runTest("compiler/testData/lineNumber/custom/initBlocks.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("multilineFunctionCall.kt")
|
||||
public void testMultilineFunctionCall() throws Exception {
|
||||
runTest("compiler/testData/lineNumber/custom/multilineFunctionCall.kt");
|
||||
|
||||
+5
@@ -191,6 +191,11 @@ public class IrLineNumberTestGenerated extends AbstractIrLineNumberTest {
|
||||
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")
|
||||
public void testMultilineFunctionCall() throws Exception {
|
||||
runTest("compiler/testData/lineNumber/custom/multilineFunctionCall.kt");
|
||||
|
||||
Reference in New Issue
Block a user