diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java index 7eb07985d72..e34bfa46cd9 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java @@ -32,6 +32,7 @@ import org.jetbrains.jet.lang.cfg.pseudocode.instructions.eval.AccessTarget; import org.jetbrains.jet.lang.cfg.pseudocode.instructions.eval.InstructionWithValue; import org.jetbrains.jet.lang.cfg.pseudocode.instructions.eval.MagicKind; import org.jetbrains.jet.lang.descriptors.*; +import org.jetbrains.jet.lang.descriptors.impl.AnonymousFunctionDescriptor; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.psiUtil.PsiUtilPackage; import org.jetbrains.jet.lang.resolve.BindingContext; @@ -100,6 +101,13 @@ public class JetControlFlowProcessor { } private void generateImplicitReturnValue(@NotNull JetExpression bodyExpression, @NotNull JetElement subroutine) { + CallableDescriptor subroutineDescriptor = (CallableDescriptor) trace.get(BindingContext.DECLARATION_TO_DESCRIPTOR, subroutine); + if (subroutineDescriptor == null) return; + + JetType returnType = subroutineDescriptor.getReturnType(); + KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance(); + if (returnType != null && builtIns.isUnit(returnType) && subroutineDescriptor instanceof AnonymousFunctionDescriptor) return; + PseudoValue returnValue = builder.getBoundValue(bodyExpression); if (returnValue == null) return; diff --git a/compiler/testData/cfg/controlStructures/Finally.instructions b/compiler/testData/cfg/controlStructures/Finally.instructions index 78f28d8213d..171f5c6d1cf 100644 --- a/compiler/testData/cfg/controlStructures/Finally.instructions +++ b/compiler/testData/cfg/controlStructures/Finally.instructions @@ -152,9 +152,8 @@ L6: read (Unit) PREV:[jf(L6|)] L7: merge(if (2 > 3) { return@l }|!) -> - 4 ret(*|) L5 L5: - NEXT:[] PREV:[ret L5, ret(*|) L5] + 4 NEXT:[] PREV:[ret L5, merge(if (2 > 3) { return@l }|!) -> ] error: PREV:[] sink: @@ -235,9 +234,8 @@ L10 [skipFinallyToErrorBlock]: 7 mark({ 2 }) PREV:[jmp(L10 [skipFinallyToErrorBlock])] r(2) -> 4 merge(try { 1 if (2 > 3) { return@l } } finally { 2 }|) -> - 3 ret(*|) L4 L4: - NEXT:[] PREV:[ret L4, ret(*|) L4] + 3 NEXT:[] PREV:[ret L4, merge(try { 1 if (2 > 3) { return@l } } finally { 2 }|) -> ] error: PREV:[jmp(error)] sink: diff --git a/compiler/testData/cfg/controlStructures/Finally.values b/compiler/testData/cfg/controlStructures/Finally.values index 28444560382..cf07ef29545 100644 --- a/compiler/testData/cfg/controlStructures/Finally.values +++ b/compiler/testData/cfg/controlStructures/Finally.values @@ -74,8 +74,8 @@ try { 1 @l{ () -> if (2 > 3) { return@l } } } finally { 2 } : * NEW: 2 > 3 : Boolean NEW: call(2 > 3, compareTo|, ) -> return@l !: * { return@l } !: * COPY -if (2 > 3) { return@l } : Unit NEW: merge(if (2 > 3) { return@l }|!) -> -if (2 > 3) { return@l } : Unit COPY +if (2 > 3) { return@l } : * NEW: merge(if (2 > 3) { return@l }|!) -> +if (2 > 3) { return@l } : * COPY ===================== == t4 == fun t4() { @@ -113,12 +113,12 @@ fun t4() { 2 > 3 : Boolean NEW: call(2 > 3, compareTo|, ) -> return@l !: * { return@l } !: * COPY -if (2 > 3) { return@l } : Unit NEW: merge(if (2 > 3) { return@l }|!) -> -{ 1 if (2 > 3) { return@l } } : Unit COPY +if (2 > 3) { return@l } : * NEW: merge(if (2 > 3) { return@l }|!) -> +{ 1 if (2 > 3) { return@l } } : * COPY 2 : * NEW: r(2) -> { 2 } : * COPY -try { 1 if (2 > 3) { return@l } } finally { 2 } : Unit NEW: merge(try { 1 if (2 > 3) { return@l } } finally { 2 }|) -> -try { 1 if (2 > 3) { return@l } } finally { 2 } : Unit COPY +try { 1 if (2 > 3) { return@l } } finally { 2 } : * NEW: merge(try { 1 if (2 > 3) { return@l } } finally { 2 }|) -> +try { 1 if (2 > 3) { return@l } } finally { 2 } : * COPY ===================== == t5 == fun t5() { diff --git a/compiler/testData/cfg/expressions/parenthesizedSelector.instructions b/compiler/testData/cfg/expressions/parenthesizedSelector.instructions index 728ed8fea38..156ec1dc1fc 100644 --- a/compiler/testData/cfg/expressions/parenthesizedSelector.instructions +++ b/compiler/testData/cfg/expressions/parenthesizedSelector.instructions @@ -78,9 +78,8 @@ L3: r("") -> mark((foo)()) call((foo)(), invoke|, ) -> - 3 ret(*|) L4 L4: - NEXT:[] + 3 NEXT:[] error: PREV:[] sink: diff --git a/compiler/testData/cfg/expressions/parenthesizedSelector.values b/compiler/testData/cfg/expressions/parenthesizedSelector.values index 63458d23c72..bbe1634bf92 100644 --- a/compiler/testData/cfg/expressions/parenthesizedSelector.values +++ b/compiler/testData/cfg/expressions/parenthesizedSelector.values @@ -36,7 +36,7 @@ with(1) { "".(foo)() } : * NEW: call(with(1) { "". "" : String NEW: r("") -> foo : {<: String.() -> Unit} NEW: r(foo|) -> (foo) : {<: String.() -> Unit} COPY -(foo)() : Unit NEW: call((foo)(), invoke|, ) -> -"".(foo)() : Unit COPY -"".(foo)() : Unit COPY +(foo)() : * NEW: call((foo)(), invoke|, ) -> +"".(foo)() : * COPY +"".(foo)() : * COPY ===================== diff --git a/compiler/testData/diagnostics/tests/FunctionCalleeExpressions.kt b/compiler/testData/diagnostics/tests/FunctionCalleeExpressions.kt index 0d277cd3a25..f02c1b21a01 100644 --- a/compiler/testData/diagnostics/tests/FunctionCalleeExpressions.kt +++ b/compiler/testData/diagnostics/tests/FunctionCalleeExpressions.kt @@ -60,7 +60,7 @@ fun main1() { 1.({Int.() -> 1})() 1.(f())() 1.if(true){f()}else{f()}() - 1.if(true){Int.() -> 1}else{f()}() + 1.if(true){Int.() -> 1}else{f()}() 1.if(true){Int.() -> 1}else{Int.() -> 1}() 1."sdf"() diff --git a/compiler/testData/diagnostics/tests/FunctionReturnTypes.kt b/compiler/testData/diagnostics/tests/FunctionReturnTypes.kt index b7f3f2c2507..d6a60379441 100644 --- a/compiler/testData/diagnostics/tests/FunctionReturnTypes.kt +++ b/compiler/testData/diagnostics/tests/FunctionReturnTypes.kt @@ -205,4 +205,4 @@ fun testFunctionLiterals() { object A {} } -} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/Varargs.kt b/compiler/testData/diagnostics/tests/Varargs.kt index dff85f3bfe1..ce75543d839 100644 --- a/compiler/testData/diagnostics/tests/Varargs.kt +++ b/compiler/testData/diagnostics/tests/Varargs.kt @@ -11,7 +11,7 @@ fun test() { v1({}) v1({}, {}) v1({}, 1, {}) - v1({}, {}, {it}) + v1({}, {}, {it}) v1({}) {} v1 {} -} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/expressionInUnitLiteral.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/expressionInUnitLiteral.kt new file mode 100644 index 00000000000..8b4f59abd84 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/expressionInUnitLiteral.kt @@ -0,0 +1,8 @@ +fun main(args: Array) { + "".run { + "" + } +} + + +fun T.run(f: (T) -> Unit): Unit = f(this) diff --git a/compiler/testData/diagnostics/tests/controlStructures/emptyIf.kt b/compiler/testData/diagnostics/tests/controlStructures/emptyIf.kt index b44d512f18c..919ca8d6b3b 100644 --- a/compiler/testData/diagnostics/tests/controlStructures/emptyIf.kt +++ b/compiler/testData/diagnostics/tests/controlStructures/emptyIf.kt @@ -13,4 +13,4 @@ fun test() { foo({if (1==1);}()) return if (true); -} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlStructures/kt770.kt351.kt735_StatementType.kt b/compiler/testData/diagnostics/tests/controlStructures/kt770.kt351.kt735_StatementType.kt index 0b4e3efab96..65bd1fcd1da 100644 --- a/compiler/testData/diagnostics/tests/controlStructures/kt770.kt351.kt735_StatementType.kt +++ b/compiler/testData/diagnostics/tests/controlStructures/kt770.kt351.kt735_StatementType.kt @@ -48,13 +48,13 @@ fun test2(): Unit { while(true) {} } fun testCoercionToUnit() { val simple: ()-> Unit = { - 41 + 41 } val withIf: ()-> Unit = { if (true) { - 3 + 3 } else { - 45 + 45 } } val i = 34 @@ -66,8 +66,8 @@ fun testCoercionToUnit() { doSmth(d) } - 2 -> '4' - else -> true + 2 -> '4' + else -> true } } diff --git a/compiler/testData/diagnostics/tests/functionLiterals/unusedLiteralInsideUnitLiteral.kt b/compiler/testData/diagnostics/tests/functionLiterals/unusedLiteralInsideUnitLiteral.kt new file mode 100644 index 00000000000..22ac992b5fe --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/unusedLiteralInsideUnitLiteral.kt @@ -0,0 +1,8 @@ +fun main(args: Array) { + "".run { + {} + } +} + + +fun T.run(f: (T) -> Unit): Unit = f(this) diff --git a/compiler/testData/diagnostics/tests/j+k/ambiguousSamAdapters.kt b/compiler/testData/diagnostics/tests/j+k/ambiguousSamAdapters.kt index 22d85ac3514..55e229f2b00 100644 --- a/compiler/testData/diagnostics/tests/j+k/ambiguousSamAdapters.kt +++ b/compiler/testData/diagnostics/tests/j+k/ambiguousSamAdapters.kt @@ -13,6 +13,5 @@ public class A { fun main() { A.foo { "Hello!" } - A.foo(Runnable { "Hello!" }) -} - + A.foo(Runnable { "Hello!" }) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/labels/kt3988.kt b/compiler/testData/diagnostics/tests/labels/kt3988.kt index 55c97eaf2ff..252226acd65 100644 --- a/compiler/testData/diagnostics/tests/labels/kt3988.kt +++ b/compiler/testData/diagnostics/tests/labels/kt3988.kt @@ -15,7 +15,7 @@ fun new2(body: Comment2.() -> Unit) = body fun main(args: Array) { new { new2 { - this@new //UNRESOLVED REFERENCE + this@new //UNRESOLVED REFERENCE } } } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/NoElseReturnedCoercionToUnit.kt b/compiler/testData/diagnostics/tests/when/NoElseReturnedCoercionToUnit.kt index 695f64ab91c..4c0f410c0f2 100644 --- a/compiler/testData/diagnostics/tests/when/NoElseReturnedCoercionToUnit.kt +++ b/compiler/testData/diagnostics/tests/when/NoElseReturnedCoercionToUnit.kt @@ -1,7 +1,7 @@ fun foo(x: Int) { r { when (x) { - 2 -> 0 + 2 -> 0 } } } diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index b5e4883fbde..1a0671ea85a 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -1541,6 +1541,11 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInWhileFromBreak.kt"); } + @TestMetadata("expressionInUnitLiteral.kt") + public void testExpressionInUnitLiteral() throws Exception { + doTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/expressionInUnitLiteral.kt"); + } + @TestMetadata("kt2585_1.kt") public void testKt2585_1() throws Exception { doTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/kt2585_1.kt"); @@ -3493,6 +3498,11 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest("compiler/testData/diagnostics/tests/functionLiterals/unusedLiteral.kt"); } + @TestMetadata("unusedLiteralInsideUnitLiteral.kt") + public void testUnusedLiteralInsideUnitLiteral() throws Exception { + doTest("compiler/testData/diagnostics/tests/functionLiterals/unusedLiteralInsideUnitLiteral.kt"); + } + @TestMetadata("compiler/testData/diagnostics/tests/functionLiterals/return") public static class Return extends AbstractJetDiagnosticsTest { public void testAllFilesPresentInReturn() throws Exception { diff --git a/idea/testData/checker/infos/CapturedInInlinedClosure.kt b/idea/testData/checker/infos/CapturedInInlinedClosure.kt index 40f7c432d11..accd50524fd 100644 --- a/idea/testData/checker/infos/CapturedInInlinedClosure.kt +++ b/idea/testData/checker/infos/CapturedInInlinedClosure.kt @@ -22,10 +22,10 @@ fun inline() { fun notInline() { val y2 = 1 run { y2 } - run2 { y2 } + run2 { y2 } val y3 = 1 - run2 { y3 } + run2 { y3 } run { y3 } // wrapped, using in not inline @@ -33,7 +33,7 @@ fun notInline() { { z }() val z1 = 3 - run2 { z1 } + run2 { z1 } } fun nestedDifferent() { // inline within non-inline and vice-versa