Allow no else in annotated when-statements

This commit is contained in:
Andrey Breslav
2013-09-23 02:05:07 +04:00
parent db9dd5d320
commit 8f6b6639c5
4 changed files with 21 additions and 1 deletions
@@ -70,6 +70,10 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
}
public JetTypeInfo visitWhenExpression(JetWhenExpression expression, ExpressionTypingContext contextWithExpectedType, boolean isStatement) {
if (isStatement) {
contextWithExpectedType.trace.record(BindingContext.STATEMENT, expression);
}
DataFlowUtils.recordExpectedType(contextWithExpectedType.trace, expression, contextWithExpectedType.expectedType);
ExpressionTypingContext context = contextWithExpectedType.replaceExpectedType(NO_EXPECTED_TYPE).replaceContextDependency(INDEPENDENT);
@@ -0,0 +1,8 @@
fun foo(a: Int) {
[ann]
when (a) {
1 -> {}
}
}
annotation class ann
@@ -5888,6 +5888,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/diagnostics/tests/when"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("AnnotatedWhenStatement.kt")
public void testAnnotatedWhenStatement() throws Exception {
doTest("compiler/testData/diagnostics/tests/when/AnnotatedWhenStatement.kt");
}
@TestMetadata("NoElseExpectedUnit.kt")
public void testNoElseExpectedUnit() throws Exception {
doTest("compiler/testData/diagnostics/tests/when/NoElseExpectedUnit.kt");
@@ -138,7 +138,10 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
@NotNull TranslationContext context) {
JetExpression expressionInside = expression.getExpression();
if (expressionInside != null) {
return expressionInside.accept(this, context);
JsNode translated = expressionInside.accept(this, context);
if (translated != null) {
return translated;
}
}
return context.program().getEmptyStatement();
}