From 1da35029a6944a02e3cfca98167090530dd6e49d Mon Sep 17 00:00:00 2001 From: Mark Punzalan Date: Tue, 30 Mar 2021 05:17:42 +0000 Subject: [PATCH] Restore UNUSED_* diagnostics to relevant tests. --- .../diagnostics/tests/UnusedParameters.fir.kt | 44 +++++++++++++++++++ .../diagnostics/tests/UnusedParameters.kt | 16 +++---- .../tests/backingField/FieldAsParam.fir.kt | 3 +- .../tests/backingField/FieldAsParam.kt | 3 +- .../unusedParameters.fir.kt | 2 +- .../unusedParameters.kt | 18 ++++---- .../ShadowParameterInFunctionBody.fir.kt | 1 + .../ShadowParameterInFunctionBody.kt | 3 +- .../ShadowParameterInNestedBlockInFor.fir.kt | 3 +- .../ShadowParameterInNestedBlockInFor.kt | 9 ++-- .../ShadowVariableInNestedBlock.fir.kt | 3 +- .../shadowing/ShadowVariableInNestedBlock.kt | 7 +-- .../ShadowVariableInNestedClosure.fir.kt | 3 +- .../ShadowVariableInNestedClosure.kt | 3 +- .../inference/intersectionInputType.fir.kt | 12 ----- .../inference/intersectionInputType.kt | 1 + 16 files changed, 87 insertions(+), 44 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/UnusedParameters.fir.kt delete mode 100644 compiler/testData/diagnostics/testsWithStdLib/inference/intersectionInputType.fir.kt diff --git a/compiler/testData/diagnostics/tests/UnusedParameters.fir.kt b/compiler/testData/diagnostics/tests/UnusedParameters.fir.kt new file mode 100644 index 00000000000..5fc389588e2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/UnusedParameters.fir.kt @@ -0,0 +1,44 @@ +// !DIAGNOSTICS: +UNUSED_PARAMETER +import kotlin.reflect.KProperty + +class C(a: Int, b: Int, c: Int, d: Int, e: Int = d, val f: String) { + init { + a + a + } + + val g = b + + init { + c + c + } +} + +fun f(a: Int, b: Int, c: Int = b) { + a + a +} + +fun Any.getValue(thisRef: Any?, prop: KProperty<*>): String = ":)" +fun Any.setValue(thisRef: Any?, prop: KProperty<*>, value: String) { +} + +fun Any.provideDelegate(thisRef: Any?, prop: KProperty<*>) { +} + +operator fun Int.getValue(thisRef: Any?, prop: KProperty<*>): String = ":)" + +operator fun Int.setValue(thisRef: Any?, prop: KProperty<*>, value: String) { +} + +operator fun Int.provideDelegate(thisRef: Any?, prop: KProperty<*>) { +} + + +fun get(p: Any) { +} + +fun set(p: Any) { +} + +fun foo(s: String) { + s.xxx = 1 +} diff --git a/compiler/testData/diagnostics/tests/UnusedParameters.kt b/compiler/testData/diagnostics/tests/UnusedParameters.kt index a78a5534a4b..881d669d07b 100644 --- a/compiler/testData/diagnostics/tests/UnusedParameters.kt +++ b/compiler/testData/diagnostics/tests/UnusedParameters.kt @@ -1,7 +1,7 @@ -// FIR_IDENTICAL +// !DIAGNOSTICS: +UNUSED_PARAMETER import kotlin.reflect.KProperty -class C(a: Int, b: Int, c: Int, d: Int, e: Int = d, val f: String) { +class C(a: Int, b: Int, c: Int, d: Int, e: Int = d, val f: String) { init { a + a } @@ -13,15 +13,15 @@ class C(a: Int, b: Int, c: Int, d: Int, e: Int = d, val f: String) { } } -fun f(a: Int, b: Int, c: Int = b) { +fun f(a: Int, b: Int, c: Int = b) { a + a } -fun Any.getValue(thisRef: Any?, prop: KProperty<*>): String = ":)" -fun Any.setValue(thisRef: Any?, prop: KProperty<*>, value: String) { +fun Any.getValue(thisRef: Any?, prop: KProperty<*>): String = ":)" +fun Any.setValue(thisRef: Any?, prop: KProperty<*>, value: String) { } -fun Any.provideDelegate(thisRef: Any?, prop: KProperty<*>) { +fun Any.provideDelegate(thisRef: Any?, prop: KProperty<*>) { } operator fun Int.getValue(thisRef: Any?, prop: KProperty<*>): String = ":)" @@ -33,10 +33,10 @@ operator fun Int.provideDelegate(thisRef: Any?, prop: KProperty<*>) { } -fun get(p: Any) { +fun get(p: Any) { } -fun set(p: Any) { +fun set(p: Any) { } fun foo(s: String) { diff --git a/compiler/testData/diagnostics/tests/backingField/FieldAsParam.fir.kt b/compiler/testData/diagnostics/tests/backingField/FieldAsParam.fir.kt index 33541e1b809..71116f23c79 100644 --- a/compiler/testData/diagnostics/tests/backingField/FieldAsParam.fir.kt +++ b/compiler/testData/diagnostics/tests/backingField/FieldAsParam.fir.kt @@ -1,3 +1,4 @@ +// !DIAGNOSTICS: +UNUSED_PARAMETER var y: Int = 1 // No backing field! @@ -5,4 +6,4 @@ var x: Int get() = y set(field) { y = field - } \ No newline at end of file + } diff --git a/compiler/testData/diagnostics/tests/backingField/FieldAsParam.kt b/compiler/testData/diagnostics/tests/backingField/FieldAsParam.kt index d193ca46cbf..e5da9f1dc03 100644 --- a/compiler/testData/diagnostics/tests/backingField/FieldAsParam.kt +++ b/compiler/testData/diagnostics/tests/backingField/FieldAsParam.kt @@ -1,8 +1,9 @@ +// !DIAGNOSTICS: +UNUSED_PARAMETER var y: Int = 1 // No backing field! var x: Int get() = y - set(field) { + set(field) { y = field } diff --git a/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/unusedParameters.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/unusedParameters.fir.kt index 5b43ff7c912..34f2df67940 100644 --- a/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/unusedParameters.fir.kt +++ b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/unusedParameters.fir.kt @@ -1,5 +1,5 @@ // !CHECK_TYPE -// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER +UNUSED_DESTRUCTURED_PARAMETER_ENTRY data class A(val x: Int, val y: String) data class B(val u: Double, val w: Short) diff --git a/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/unusedParameters.kt b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/unusedParameters.kt index c307b2c5706..4cd61485e73 100644 --- a/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/unusedParameters.kt +++ b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/unusedParameters.kt @@ -1,5 +1,5 @@ // !CHECK_TYPE -// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER +UNUSED_DESTRUCTURED_PARAMETER_ENTRY data class A(val x: Int, val y: String) data class B(val u: Double, val w: Short) @@ -7,36 +7,36 @@ fun foo(block: (A) -> Unit) { } fun foobar(block: (A, B) -> Unit) { } fun bar() { - foo { (a, b) -> + foo { (a, b) -> a checkType { _() } } - foo { (a, b) -> + foo { (a, b) -> b checkType { _() } } - foo { (a: Int, b: String) -> + foo { (a: Int, b: String) -> a checkType { _() } } - foo { (a: Int, b: String) -> + foo { (a: Int, b: String) -> b checkType { _() } } - foobar { (a, b), c -> + foobar { (a, b), c -> a checkType { _() } } - foobar { a, (b, c) -> + foobar { a, (b, c) -> c checkType { _() } } - foobar { (a, b), (c, d) -> + foobar { (a, b), (c, d) -> a checkType { _() } d checkType { _() } } - foobar { (a, b), (c, d) -> + foobar { (a, b), (c, d) -> b checkType { _() } c checkType { _() } } diff --git a/compiler/testData/diagnostics/tests/shadowing/ShadowParameterInFunctionBody.fir.kt b/compiler/testData/diagnostics/tests/shadowing/ShadowParameterInFunctionBody.fir.kt index 8b55c6d58ae..caba2ede5d8 100644 --- a/compiler/testData/diagnostics/tests/shadowing/ShadowParameterInFunctionBody.fir.kt +++ b/compiler/testData/diagnostics/tests/shadowing/ShadowParameterInFunctionBody.fir.kt @@ -1,3 +1,4 @@ +// !DIAGNOSTICS: +UNUSED_PARAMETER fun f(p: Int): Int { val p = 2 return p diff --git a/compiler/testData/diagnostics/tests/shadowing/ShadowParameterInFunctionBody.kt b/compiler/testData/diagnostics/tests/shadowing/ShadowParameterInFunctionBody.kt index fb210cfba51..6f68a67e690 100644 --- a/compiler/testData/diagnostics/tests/shadowing/ShadowParameterInFunctionBody.kt +++ b/compiler/testData/diagnostics/tests/shadowing/ShadowParameterInFunctionBody.kt @@ -1,4 +1,5 @@ -fun f(p: Int): Int { +// !DIAGNOSTICS: +UNUSED_PARAMETER +fun f(p: Int): Int { val p = 2 return p } diff --git a/compiler/testData/diagnostics/tests/shadowing/ShadowParameterInNestedBlockInFor.fir.kt b/compiler/testData/diagnostics/tests/shadowing/ShadowParameterInNestedBlockInFor.fir.kt index 1b2cec3f6e2..48446b3d904 100644 --- a/compiler/testData/diagnostics/tests/shadowing/ShadowParameterInNestedBlockInFor.fir.kt +++ b/compiler/testData/diagnostics/tests/shadowing/ShadowParameterInNestedBlockInFor.fir.kt @@ -1,7 +1,8 @@ +// !DIAGNOSTICS: +UNUSED_PARAMETER +UNUSED_LAMBDA_EXPRESSION +UNUSED_VARIABLE fun f(i: Int) { for (j in 1..100) { { var i = 12 } } -} \ No newline at end of file +} diff --git a/compiler/testData/diagnostics/tests/shadowing/ShadowParameterInNestedBlockInFor.kt b/compiler/testData/diagnostics/tests/shadowing/ShadowParameterInNestedBlockInFor.kt index e3e91fbe857..0b01c07a3d7 100644 --- a/compiler/testData/diagnostics/tests/shadowing/ShadowParameterInNestedBlockInFor.kt +++ b/compiler/testData/diagnostics/tests/shadowing/ShadowParameterInNestedBlockInFor.kt @@ -1,7 +1,8 @@ -fun f(i: Int) { +// !DIAGNOSTICS: +UNUSED_PARAMETER +UNUSED_LAMBDA_EXPRESSION +UNUSED_VARIABLE +fun f(i: Int) { for (j in 1..100) { - { - var i = 12 - } + { + var i = 12 + } } } diff --git a/compiler/testData/diagnostics/tests/shadowing/ShadowVariableInNestedBlock.fir.kt b/compiler/testData/diagnostics/tests/shadowing/ShadowVariableInNestedBlock.fir.kt index 8346a2e57e9..d1b5e6414ed 100644 --- a/compiler/testData/diagnostics/tests/shadowing/ShadowVariableInNestedBlock.fir.kt +++ b/compiler/testData/diagnostics/tests/shadowing/ShadowVariableInNestedBlock.fir.kt @@ -1,7 +1,8 @@ +// !DIAGNOSTICS: +UNUSED_LAMBDA_EXPRESSION +UNUSED_VARIABLE fun ff(): Int { var i = 1 { val i = 2 } return i -} \ No newline at end of file +} diff --git a/compiler/testData/diagnostics/tests/shadowing/ShadowVariableInNestedBlock.kt b/compiler/testData/diagnostics/tests/shadowing/ShadowVariableInNestedBlock.kt index 2fd755bdc1c..2f154270fba 100644 --- a/compiler/testData/diagnostics/tests/shadowing/ShadowVariableInNestedBlock.kt +++ b/compiler/testData/diagnostics/tests/shadowing/ShadowVariableInNestedBlock.kt @@ -1,7 +1,8 @@ +// !DIAGNOSTICS: +UNUSED_LAMBDA_EXPRESSION +UNUSED_VARIABLE fun ff(): Int { var i = 1 - { - val i = 2 - } + { + val i = 2 + } return i } diff --git a/compiler/testData/diagnostics/tests/shadowing/ShadowVariableInNestedClosure.fir.kt b/compiler/testData/diagnostics/tests/shadowing/ShadowVariableInNestedClosure.fir.kt index 80db73b0a0f..89e76b77c90 100644 --- a/compiler/testData/diagnostics/tests/shadowing/ShadowVariableInNestedClosure.fir.kt +++ b/compiler/testData/diagnostics/tests/shadowing/ShadowVariableInNestedClosure.fir.kt @@ -1,5 +1,6 @@ +// !DIAGNOSTICS: +UNUSED_LAMBDA_EXPRESSION +UNUSED_VARIABLE fun f(): Int { var i = 17 { var i = 18 } return i -} \ No newline at end of file +} diff --git a/compiler/testData/diagnostics/tests/shadowing/ShadowVariableInNestedClosure.kt b/compiler/testData/diagnostics/tests/shadowing/ShadowVariableInNestedClosure.kt index f73d781953b..b1792f8fe38 100644 --- a/compiler/testData/diagnostics/tests/shadowing/ShadowVariableInNestedClosure.kt +++ b/compiler/testData/diagnostics/tests/shadowing/ShadowVariableInNestedClosure.kt @@ -1,5 +1,6 @@ +// !DIAGNOSTICS: +UNUSED_LAMBDA_EXPRESSION +UNUSED_VARIABLE fun f(): Int { var i = 17 - { var i = 18 } + { var i = 18 } return i } diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/intersectionInputType.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/intersectionInputType.fir.kt deleted file mode 100644 index 0b312e318b3..00000000000 --- a/compiler/testData/diagnostics/testsWithStdLib/inference/intersectionInputType.fir.kt +++ /dev/null @@ -1,12 +0,0 @@ -// !LANGUAGE: +NewInference - -import kotlin.test.assertEquals - -fun test() { - val u = when (true) { - true -> 42 - else -> 1.0 - } - - assertEquals(42, u) -} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/intersectionInputType.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/intersectionInputType.kt index 0b312e318b3..a1f3691d2c2 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/inference/intersectionInputType.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/intersectionInputType.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !LANGUAGE: +NewInference import kotlin.test.assertEquals