diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java index 101d9fec9bc..36f3c3ac1f8 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java @@ -125,9 +125,12 @@ public class JetFlowInformationProvider { public void checkFunction(@Nullable JetType expectedReturnType) { UnreachableCode unreachableCode = collectUnreachableCode(); - checkDefiniteReturn(expectedReturnType != null ? expectedReturnType : NO_EXPECTED_TYPE, unreachableCode); reportUnreachableCode(unreachableCode); + if (subroutine instanceof JetFunctionLiteral) return; + + checkDefiniteReturn(expectedReturnType != null ? expectedReturnType : NO_EXPECTED_TYPE, unreachableCode); + markTailCalls(); } @@ -196,7 +199,7 @@ public class JetFlowInformationProvider { JetElement element = localDeclarationInstruction.getElement(); if (element instanceof JetDeclarationWithBody) { JetDeclarationWithBody localDeclaration = (JetDeclarationWithBody) element; - if (localDeclaration instanceof JetFunctionLiteral) continue; + CallableDescriptor functionDescriptor = (CallableDescriptor) trace.getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, localDeclaration); JetType expectedType = functionDescriptor != null ? functionDescriptor.getReturnType() : null; diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/kt5200DeadCodeInLambdas.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/kt5200DeadCodeInLambdas.kt new file mode 100644 index 00000000000..0d53ea4e81a --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/kt5200DeadCodeInLambdas.kt @@ -0,0 +1,27 @@ +//KT-5200 Mark unreachable code in lambdas + +fun test1(): String { + doCall @local { + () : String -> + throw NullPointerException() + "b3" //unmarked + } + + return "OK" +} + +fun test2(nonLocal: String, b: Boolean): String { + doCall @local { + () : String -> + if (b) { + return@local "b1" + } else { + return@local "b2" + } + "b3" //unmarked + } + + return nonLocal +} + +inline fun doCall(block: ()-> String) = block() diff --git a/compiler/testData/diagnostics/tests/regressions/kt411.kt b/compiler/testData/diagnostics/tests/regressions/kt411.kt index 3c6ee7ef2a5..2f5c43386f5 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt411.kt +++ b/compiler/testData/diagnostics/tests/regressions/kt411.kt @@ -37,7 +37,7 @@ fun t3() : String { else { return 2 } - return@l 0 + return@l 0 } ) invoker( diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index 6f347d12173..80b66aba665 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -1546,6 +1546,11 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/kt2585_3.kt"); } + @TestMetadata("kt5200DeadCodeInLambdas.kt") + public void testKt5200DeadCodeInLambdas() throws Exception { + doTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/kt5200DeadCodeInLambdas.kt"); + } + } @TestMetadata("compiler/testData/diagnostics/tests/controlFlowAnalysis/definiteReturn")