From 79bf174e9335d46e7fc30943472a8c4e2ac627f8 Mon Sep 17 00:00:00 2001 From: Mikhael Bogdanov Date: Wed, 20 Mar 2013 11:33:48 +0400 Subject: [PATCH] Warning for unused function literal in do..while --- .../expressions/ControlStructureTypingVisitor.java | 1 + .../tests/functionLiterals/unusedLiteral.kt | 12 ++++++++++++ .../jet/checkers/JetDiagnosticsTestGenerated.java | 5 +++++ 3 files changed, 18 insertions(+) create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/unusedLiteral.kt diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ControlStructureTypingVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ControlStructureTypingVisitor.java index 8460ae12c8a..f3c71c4b93d 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ControlStructureTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ControlStructureTypingVisitor.java @@ -237,6 +237,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor { else { facade.getTypeInfo(body, context.replaceScope(context.scope)); } + context.trace.report(UNUSED_FUNCTION_LITERAL.on(function)); } else if (body != null) { WritableScope writableScope = newWritableScopeImpl(context, "do..while body scope"); diff --git a/compiler/testData/diagnostics/tests/functionLiterals/unusedLiteral.kt b/compiler/testData/diagnostics/tests/functionLiterals/unusedLiteral.kt new file mode 100644 index 00000000000..10edbc1d7ee --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/unusedLiteral.kt @@ -0,0 +1,12 @@ +fun unusedLiteral(){ + {() -> + val i = 1 + } +} + + +fun unusedLiteralInDoWhile(){ + do{() -> + val i = 1 + } while(false) +} diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index 958c16c1446..7cedb124fa7 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -1849,6 +1849,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage doTest("compiler/testData/diagnostics/tests/functionLiterals/kt2906.kt"); } + @TestMetadata("unusedLiteral.kt") + public void testUnusedLiteral() throws Exception { + doTest("compiler/testData/diagnostics/tests/functionLiterals/unusedLiteral.kt"); + } + } @TestMetadata("compiler/testData/diagnostics/tests/generics")