Fix for KT-5995: Labeled val causes an exception from the back-end

#KT-5995 Fixed
This commit is contained in:
Michael Bogdanov
2014-10-11 14:51:20 +04:00
parent 860544d299
commit 9d72036ba5
4 changed files with 51 additions and 2 deletions
@@ -1430,7 +1430,12 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
StackValue answer = StackValue.none();
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) {
JetNamedDeclaration declaration = (JetNamedDeclaration) statement;
@@ -1459,7 +1464,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
v.mark(labelBeforeLastExpression);
}
StackValue result = isExpression ? gen(statement) : genStatement(statement);
StackValue result = isExpression ? gen(possiblyLabeledStatement) : genStatement(possiblyLabeledStatement);
if (!iterator.hasNext()) {
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);
}
@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")
public void testPropertyAccessor() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/labels/propertyAccessor.kt");