Report UNUSED_EXPRESSION on anonymous functions

This commit is contained in:
Denis Zharkov
2016-03-23 20:11:51 +03:00
parent 16736e3a0e
commit 628f9050fb
6 changed files with 24 additions and 22 deletions
+1
View File
@@ -9,6 +9,7 @@
- Show only changed files in notification "Kotlin not configured" - Show only changed files in notification "Kotlin not configured"
- Configure Kotlin: restore all changed files in undo action - Configure Kotlin: restore all changed files in undo action
- Enable precise incremental compilation by default - Enable precise incremental compilation by default
- Report warning about unused anonymous functions
### JVM ### JVM
- Remove the compiler option "Xmultifile-facades-open" - Remove the compiler option "Xmultifile-facades-open"
@@ -260,6 +260,7 @@ fun Instruction.calcSideEffectFree(): Boolean {
} }
else -> when (element) { else -> when (element) {
is KtNamedFunction -> element.name == null
is KtConstantExpression, is KtLambdaExpression, is KtStringTemplateExpression -> true is KtConstantExpression, is KtLambdaExpression, is KtStringTemplateExpression -> true
else -> false else -> false
} }
@@ -18,9 +18,9 @@ class Outer {
} }
fun outerFun() { fun outerFun() {
fun () {} <!UNUSED_EXPRESSION!>fun () {}<!>
fun B.() {} <!UNUSED_EXPRESSION!>fun B.() {}<!>
@a fun () {} <!UNUSED_EXPRESSION!>@a fun () {}<!>
fun @a A.() {} <!UNUSED_EXPRESSION!>fun @a A.() {}<!>
} }
@@ -1,21 +1,21 @@
fun unusedExpressions() { fun unusedExpressions() {
if (1 == 1) if (1 == 1)
fun(): Int {return 1} <!UNUSED_EXPRESSION!>fun(): Int {return 1}<!>
else else
fun() = 1 <!UNUSED_EXPRESSION!>fun() = 1<!>
if (1 == 1) { if (1 == 1) {
fun(): Int { <!UNUSED_EXPRESSION!>fun(): Int {
return 1 return 1
} }<!>
} }
else else
fun() = 1 <!UNUSED_EXPRESSION!>fun() = 1<!>
when (1) { when (1) {
0 -> fun(): Int {return 1} 0 -> <!UNUSED_EXPRESSION!>fun(): Int {return 1}<!>
else -> fun() = 1 else -> <!UNUSED_EXPRESSION!>fun() = 1<!>
} }
fun() = 1 <!UNUSED_EXPRESSION!>fun() = 1<!>
} }
@@ -58,11 +58,11 @@ class Outer {
} }
fun outerFun() { fun outerFun() {
fun () { <!UNUSED_EXPRESSION!>fun () {
} }<!>
fun () { <!UNUSED_EXPRESSION!>fun () {
} }<!>
} }
+6 -6
View File
@@ -1,17 +1,17 @@
// KT-306 Ambiguity when different this's have same-looking functions // KT-306 Ambiguity when different this's have same-looking functions
fun test() { fun test() {
(fun Foo.() { (<!UNUSED_EXPRESSION!>fun Foo.() {
bar() bar()
(fun Barr.() { (<!UNUSED_EXPRESSION!>fun Barr.() {
this.bar() this.bar()
bar() bar()
}) }<!>)
}) }<!>)
(fun Barr.() { (<!UNUSED_EXPRESSION!>fun Barr.() {
this.bar() this.bar()
bar() bar()
}) }<!>)
} }
class Foo { class Foo {