When-statements & correct line numbers
This commit is contained in:
@@ -39,4 +39,9 @@ public class CodegenStatementVisitor extends JetVisitor<StackValue, StackValue>
|
||||
public StackValue visitTryExpression(JetTryExpression expression, StackValue data) {
|
||||
return codegen.generateTryExpression(expression, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StackValue visitWhenExpression(JetWhenExpression expression, StackValue data) {
|
||||
return codegen.generateWhenExpression(expression, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3378,10 +3378,14 @@ The "returned" value of try expression with no finally is either the last expres
|
||||
|
||||
@Override
|
||||
public StackValue visitWhenExpression(JetWhenExpression expression, StackValue receiver) {
|
||||
return generateWhenExpression(expression, false);
|
||||
}
|
||||
|
||||
public StackValue generateWhenExpression(JetWhenExpression expression, boolean isStatement) {
|
||||
JetExpression expr = expression.getSubjectExpression();
|
||||
JetType subjectJetType = bindingContext.get(BindingContext.EXPRESSION_TYPE, expr);
|
||||
final Type subjectType = asmTypeOrVoid(subjectJetType);
|
||||
final Type resultType = expressionType(expression);
|
||||
final Type resultType = isStatement ? Type.VOID_TYPE : expressionType(expression);
|
||||
final int subjectLocal = expr != null ? myFrameMap.enterTemp(subjectType) : -1;
|
||||
if (subjectLocal != -1) {
|
||||
gen(expr, subjectType);
|
||||
@@ -3432,6 +3436,8 @@ The "returned" value of try expression with no finally is either the last expres
|
||||
v.mark(nextCondition);
|
||||
throwNewException(CLASS_NO_PATTERN_MATCHED_EXCEPTION);
|
||||
}
|
||||
|
||||
markLineNumber(expression);
|
||||
v.mark(end);
|
||||
|
||||
myFrameMap.leaveTemp(subjectType);
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
fun z() {}
|
||||
|
||||
fun foo(x: Int) {
|
||||
when {
|
||||
x == 21 -> z()
|
||||
x == 42 -> z()
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fun z() {}
|
||||
|
||||
fun foo(x: Int) {
|
||||
when (x) {
|
||||
21 -> z()
|
||||
42 -> z()
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
fun foo(x: Int) {
|
||||
when {
|
||||
x == 21 -> foo(x)
|
||||
x == 42 -> foo(x)
|
||||
else -> foo(x)
|
||||
}
|
||||
|
||||
val t = when {
|
||||
x == 21 -> foo(x)
|
||||
x == 42 -> foo(x)
|
||||
else -> foo(x)
|
||||
}
|
||||
}
|
||||
|
||||
// 3 4 5 9 10 11 8
|
||||
@@ -0,0 +1,15 @@
|
||||
fun foo(x: Int) {
|
||||
when (x) {
|
||||
21 -> foo(x)
|
||||
42 -> foo(x)
|
||||
else -> foo(x)
|
||||
}
|
||||
|
||||
val t = when (x) {
|
||||
21 -> foo(x)
|
||||
42 -> foo(x)
|
||||
else -> foo(x)
|
||||
}
|
||||
}
|
||||
|
||||
// 2 3 4 5 8 9 10 11 8
|
||||
@@ -319,6 +319,14 @@ public class LineNumberTest extends TestCaseWithTmpdir {
|
||||
doTestCustom();
|
||||
}
|
||||
|
||||
public void testWhen() {
|
||||
doTestCustom();
|
||||
}
|
||||
|
||||
public void testWhenSubject() {
|
||||
doTestCustom();
|
||||
}
|
||||
|
||||
public void testStaticDelegate() {
|
||||
JetFile foo = createPsiFile("staticDelegate/foo.kt");
|
||||
JetFile bar = createPsiFile("staticDelegate/bar.kt");
|
||||
|
||||
@@ -52,4 +52,12 @@ public class StatementGenTest extends CodegenTestCase {
|
||||
public void testTryCatchFinally() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testWhen() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testWhenSubject() {
|
||||
doTest();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user