Allow no else in annotated when-statements
This commit is contained in:
+4
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user