Fix for KT-5995: Labeled val causes an exception from the back-end
#KT-5995 Fixed
This commit is contained in:
@@ -1430,7 +1430,12 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
StackValue answer = StackValue.none();
|
StackValue answer = StackValue.none();
|
||||||
|
|
||||||
for (Iterator<JetElement> iterator = statements.iterator(); iterator.hasNext(); ) {
|
for (Iterator<JetElement> iterator = statements.iterator(); iterator.hasNext(); ) {
|
||||||
JetElement statement = iterator.next();
|
JetElement possiblyLabeledStatement = iterator.next();
|
||||||
|
|
||||||
|
JetElement statement = possiblyLabeledStatement instanceof JetExpression
|
||||||
|
? JetPsiUtil.safeDeparenthesize((JetExpression) possiblyLabeledStatement, true)
|
||||||
|
: possiblyLabeledStatement;
|
||||||
|
|
||||||
|
|
||||||
if (statement instanceof JetNamedDeclaration) {
|
if (statement instanceof JetNamedDeclaration) {
|
||||||
JetNamedDeclaration declaration = (JetNamedDeclaration) statement;
|
JetNamedDeclaration declaration = (JetNamedDeclaration) statement;
|
||||||
@@ -1459,7 +1464,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
v.mark(labelBeforeLastExpression);
|
v.mark(labelBeforeLastExpression);
|
||||||
}
|
}
|
||||||
|
|
||||||
StackValue result = isExpression ? gen(statement) : genStatement(statement);
|
StackValue result = isExpression ? gen(possiblyLabeledStatement) : genStatement(possiblyLabeledStatement);
|
||||||
|
|
||||||
if (!iterator.hasNext()) {
|
if (!iterator.hasNext()) {
|
||||||
answer = result;
|
answer = result;
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
data class A(val a: Int, val b: Int)
|
||||||
|
|
||||||
|
fun box() : String
|
||||||
|
{
|
||||||
|
@a val x = 1
|
||||||
|
@b fun a() = 2
|
||||||
|
@c val (z, z2) = A(1, 2)
|
||||||
|
|
||||||
|
if (x != 1) return "fail 1"
|
||||||
|
|
||||||
|
if (a() != 2) return "fail 2"
|
||||||
|
|
||||||
|
if (z != 1 || z2 != 2) return "fail 3"
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
data class A(val a: Int, val b: Int)
|
||||||
|
|
||||||
|
fun box() : String
|
||||||
|
{
|
||||||
|
(@a val x = 1)
|
||||||
|
(@b fun a() = 2)
|
||||||
|
(@c val (z, z2) = A(1, 2))
|
||||||
|
|
||||||
|
if (x != 1) return "fail 1"
|
||||||
|
|
||||||
|
if (a() != 2) return "fail 2"
|
||||||
|
|
||||||
|
if (z != 1 || z2 != 2) return "fail 3"
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -4075,6 +4075,18 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/labels"), Pattern.compile("^(.+)\\.kt$"), true);
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/labels"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("labeledDeclarations.kt")
|
||||||
|
public void testLabeledDeclarations() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/labels/labeledDeclarations.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("labeledDeclarations2.kt")
|
||||||
|
public void testLabeledDeclarations2() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/labels/labeledDeclarations2.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("propertyAccessor.kt")
|
@TestMetadata("propertyAccessor.kt")
|
||||||
public void testPropertyAccessor() throws Exception {
|
public void testPropertyAccessor() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/labels/propertyAccessor.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/labels/propertyAccessor.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user