From c5fd496cc97626c5577f44731e6eb9bcff8bb91e Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Wed, 27 Jan 2016 17:07:03 +0300 Subject: [PATCH] Fix KT-10805 for 'when'. --- .../PatternMatchingTypingVisitor.kt | 2 +- .../tests/when/whenWithNothingAndLambdas.kt | 37 +++++++++++++++++++ .../tests/when/whenWithNothingAndLambdas.txt | 8 ++++ .../checkers/DiagnosticsTestGenerated.java | 6 +++ 4 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/diagnostics/tests/when/whenWithNothingAndLambdas.kt create mode 100644 compiler/testData/diagnostics/tests/when/whenWithNothingAndLambdas.txt diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/PatternMatchingTypingVisitor.kt b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/PatternMatchingTypingVisitor.kt index ed8a28a962f..add3bd1ddff 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/PatternMatchingTypingVisitor.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/PatternMatchingTypingVisitor.kt @@ -179,7 +179,7 @@ class PatternMatchingTypingVisitor internal constructor(facade: ExpressionTyping val entryExpression = whenEntry.expression ?: continue val entryTypeInfo = BindingContextUtils.getRecordedTypeInfo(entryExpression, bindingContext) ?: - throw AssertionError("When entry was not processed") + continue val entryType = entryTypeInfo.type val entryDataFlowInfo = diff --git a/compiler/testData/diagnostics/tests/when/whenWithNothingAndLambdas.kt b/compiler/testData/diagnostics/tests/when/whenWithNothingAndLambdas.kt new file mode 100644 index 00000000000..0aada5bcd69 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/whenWithNothingAndLambdas.kt @@ -0,0 +1,37 @@ +val test1 = when { + true -> { { true } } + else -> TODO() +} + +val test1a: () -> Boolean = when { + true -> { { true } } + else -> TODO() +} + +val test2 = when { + true -> { { true } } + else -> when { + true -> { { true } } + else -> TODO() + } +} + +val test2a: () -> Boolean = when { + true -> { { true } } + else -> when { + true -> { { true } } // TODO + else -> TODO() + } +} + +val test3 = when { + true -> { { true } } + true -> { { true } } + else -> TODO() +} + +val test3a: () -> Boolean = when { + true -> { { true } } + true -> { { true } } + else -> TODO() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/whenWithNothingAndLambdas.txt b/compiler/testData/diagnostics/tests/when/whenWithNothingAndLambdas.txt new file mode 100644 index 00000000000..75f0c0ce49b --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/whenWithNothingAndLambdas.txt @@ -0,0 +1,8 @@ +package + +public val test1: kotlin.Nothing +public val test1a: () -> kotlin.Boolean +public val test2: kotlin.Nothing +public val test2a: () -> kotlin.Boolean +public val test3: kotlin.Nothing +public val test3a: () -> kotlin.Boolean diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index d3253f39674..c9b7752d224 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -18869,6 +18869,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/when/WhenTypeDisjunctions.kt"); doTest(fileName); } + + @TestMetadata("whenWithNothingAndLambdas.kt") + public void testWhenWithNothingAndLambdas() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/when/whenWithNothingAndLambdas.kt"); + doTest(fileName); + } } }