File tree 4 files changed +43
-0
lines changed
fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/extended
testData/diagnostics/tests/controlFlowAnalysis/deadCode
4 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -62,6 +62,10 @@ object UnusedChecker : AbstractFirPropertyInitializationChecker(MppCheckerKind.C
62
62
private val FirPropertySymbol .ignoreWarnings: Boolean
63
63
get() = name == SpecialNames .UNDERSCORE_FOR_UNUSED_VAR ||
64
64
source == null ||
65
+ // if <receiver> variable is reported as unused,
66
+ // then the assignment itself is a dead code because of its RHS expression,
67
+ // which will be eventually reported
68
+ source?.kind is KtFakeSourceElementKind .DesugaredAugmentedAssign ||
65
69
source?.elementType == KtNodeTypes .DESTRUCTURING_DECLARATION ||
66
70
initializerSource?.kind == KtFakeSourceElementKind .DesugaredForLoop
67
71
Original file line number Diff line number Diff line change @@ -3,6 +3,15 @@ fun testAssignment() {
3
3
< ! UNREACHABLE_CODE ! >< ! ASSIGNED_VALUE_IS_NEVER_READ ! > a< ! > = < ! > todo()
4
4
}
5
5
6
+ class Foo {
7
+ var property: Int = 0
8
+ }
9
+
10
+ fun testClassPropertyAssignment (foo : Foo ) {
11
+ foo.property = 1
12
+ foo< ! UNREACHABLE_CODE ! > .property = < ! > todo()
13
+ }
14
+
6
15
fun testVariableDeclaration () {
7
16
< ! UNREACHABLE_CODE ! > val < ! UNUSED_VARIABLE ! > a< ! > = < ! > todo()
8
17
}
@@ -14,5 +23,10 @@ fun testPlusAssign() {
14
23
a < ! UNREACHABLE_CODE ! > + = < ! > todo()
15
24
}
16
25
26
+ fun testClassPropertyPlusAssign (foo : Foo ) {
27
+ foo.property + = 1
28
+ foo< ! UNREACHABLE_CODE ! > .property< ! > + = todo() as Int
29
+ }
30
+
17
31
18
32
fun todo (): Nothing = throw Exception ()
Original file line number Diff line number Diff line change @@ -3,6 +3,15 @@ fun testAssignment() {
3
3
< ! UNREACHABLE_CODE ! > a = < ! > todo()
4
4
}
5
5
6
+ class Foo {
7
+ var property: Int = 0
8
+ }
9
+
10
+ fun testClassPropertyAssignment (foo : Foo ) {
11
+ foo.property = 1
12
+ foo< ! UNREACHABLE_CODE ! > .property = < ! > todo()
13
+ }
14
+
6
15
fun testVariableDeclaration () {
7
16
< ! UNREACHABLE_CODE ! > val < ! UNUSED_VARIABLE ! > a< ! > = < ! > todo()
8
17
}
@@ -14,5 +23,10 @@ fun testPlusAssign() {
14
23
a < ! UNREACHABLE_CODE ! > + = < ! > todo()
15
24
}
16
25
26
+ fun testClassPropertyPlusAssign (foo : Foo ) {
27
+ foo.property + = 1
28
+ foo.property < ! UNREACHABLE_CODE ! > + = < ! > todo() as Int
29
+ }
30
+
17
31
18
32
fun todo (): Nothing = throw Exception ()
Original file line number Diff line number Diff line change 1
1
package
2
2
3
3
public fun testAssignment(): kotlin.Unit
4
+ public fun testClassPropertyAssignment(/*0*/ foo: Foo): kotlin.Unit
5
+ public fun testClassPropertyPlusAssign(/*0*/ foo: Foo): kotlin.Unit
4
6
public fun testPlusAssign(): kotlin.Unit
5
7
public fun testVariableDeclaration(): kotlin.Unit
6
8
public fun todo(): kotlin.Nothing
9
+
10
+ public final class Foo {
11
+ public constructor Foo()
12
+ public final var property: kotlin.Int
13
+ public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
14
+ public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
15
+ public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
16
+ }
17
+
You can’t perform that action at this time.
0 commit comments