diff --git a/Changelog.md b/Changelog.md index d95274875f8..e536d43baa9 100644 --- a/Changelog.md +++ b/Changelog.md @@ -9,6 +9,7 @@ - Show only changed files in notification "Kotlin not configured" - Configure Kotlin: restore all changed files in undo action - Enable precise incremental compilation by default +- Report warning about unused anonymous functions ### JVM - Remove the compiler option "Xmultifile-facades-open" diff --git a/compiler/frontend/src/org/jetbrains/kotlin/cfg/pseudocode/pseudocodeUtils.kt b/compiler/frontend/src/org/jetbrains/kotlin/cfg/pseudocode/pseudocodeUtils.kt index 43de2fa24d5..4dfbf1f4cbf 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/cfg/pseudocode/pseudocodeUtils.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/cfg/pseudocode/pseudocodeUtils.kt @@ -260,6 +260,7 @@ fun Instruction.calcSideEffectFree(): Boolean { } else -> when (element) { + is KtNamedFunction -> element.name == null is KtConstantExpression, is KtLambdaExpression, is KtStringTemplateExpression -> true else -> false } diff --git a/compiler/testData/diagnostics/tests/declarationChecks/FunctionWithMissingNames.kt b/compiler/testData/diagnostics/tests/declarationChecks/FunctionWithMissingNames.kt index 525e844de5c..247d5892d79 100644 --- a/compiler/testData/diagnostics/tests/declarationChecks/FunctionWithMissingNames.kt +++ b/compiler/testData/diagnostics/tests/declarationChecks/FunctionWithMissingNames.kt @@ -18,9 +18,9 @@ class Outer { } fun outerFun() { - fun () {} - fun B.() {} + fun () {} + fun B.() {} - @a fun () {} - fun @a A.() {} + @a fun () {} + fun @a A.() {} } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/declarationChecks/anonymousFunUnusedLastExpressionInBlock.kt b/compiler/testData/diagnostics/tests/declarationChecks/anonymousFunUnusedLastExpressionInBlock.kt index e8ba7c71cb2..3189c97ccf6 100644 --- a/compiler/testData/diagnostics/tests/declarationChecks/anonymousFunUnusedLastExpressionInBlock.kt +++ b/compiler/testData/diagnostics/tests/declarationChecks/anonymousFunUnusedLastExpressionInBlock.kt @@ -1,21 +1,21 @@ fun unusedExpressions() { if (1 == 1) - fun(): Int {return 1} + fun(): Int {return 1} else - fun() = 1 + fun() = 1 if (1 == 1) { - fun(): Int { + fun(): Int { return 1 - } + } } else - fun() = 1 + fun() = 1 when (1) { - 0 -> fun(): Int {return 1} - else -> fun() = 1 + 0 -> fun(): Int {return 1} + else -> fun() = 1 } - fun() = 1 + fun() = 1 } diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/missingNames.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/missingNames.kt index fe4d64999cf..a885363b41a 100644 --- a/compiler/testData/diagnostics/tests/duplicateJvmSignature/missingNames.kt +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/missingNames.kt @@ -58,11 +58,11 @@ class Outer { } fun outerFun() { - fun () { + fun () { - } - fun () { + } + fun () { - } + } } diff --git a/compiler/testData/diagnostics/tests/regressions/kt306.kt b/compiler/testData/diagnostics/tests/regressions/kt306.kt index dba4b547214..e12d6e208f7 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt306.kt +++ b/compiler/testData/diagnostics/tests/regressions/kt306.kt @@ -1,17 +1,17 @@ // KT-306 Ambiguity when different this's have same-looking functions fun test() { - (fun Foo.() { + (fun Foo.() { bar() - (fun Barr.() { + (fun Barr.() { this.bar() bar() - }) - }) - (fun Barr.() { + }) + }) + (fun Barr.() { this.bar() bar() - }) + }) } class Foo {