[FE 1.0] Don't report UNUSED_* warnings on local properties with delegate
^KT-25527 Fixed
This commit is contained in:
committed by
teamcity
parent
4d5a4ccd6b
commit
89b1307e16
+6
@@ -5944,6 +5944,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
|||||||
runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/unresolvedReference.kt");
|
runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/unresolvedReference.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("unusedPropertyWithCustomAccessors.kt")
|
||||||
|
public void testUnusedPropertyWithCustomAccessors() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/unusedPropertyWithCustomAccessors.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("useUninitializedInLambda.kt")
|
@TestMetadata("useUninitializedInLambda.kt")
|
||||||
public void testUseUninitializedInLambda() throws Exception {
|
public void testUseUninitializedInLambda() throws Exception {
|
||||||
|
|||||||
+6
@@ -5944,6 +5944,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
|||||||
runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/unresolvedReference.kt");
|
runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/unresolvedReference.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("unusedPropertyWithCustomAccessors.kt")
|
||||||
|
public void testUnusedPropertyWithCustomAccessors() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/unusedPropertyWithCustomAccessors.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("useUninitializedInLambda.kt")
|
@TestMetadata("useUninitializedInLambda.kt")
|
||||||
public void testUseUninitializedInLambda() throws Exception {
|
public void testUseUninitializedInLambda() throws Exception {
|
||||||
|
|||||||
+6
@@ -5944,6 +5944,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
|||||||
runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/unresolvedReference.kt");
|
runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/unresolvedReference.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("unusedPropertyWithCustomAccessors.kt")
|
||||||
|
public void testUnusedPropertyWithCustomAccessors() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/unusedPropertyWithCustomAccessors.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("useUninitializedInLambda.kt")
|
@TestMetadata("useUninitializedInLambda.kt")
|
||||||
public void testUseUninitializedInLambda() throws Exception {
|
public void testUseUninitializedInLambda() throws Exception {
|
||||||
|
|||||||
+9
-2
@@ -676,7 +676,9 @@ class ControlFlowInformationProviderImpl private constructor(
|
|||||||
when (expressionInQuestion) {
|
when (expressionInQuestion) {
|
||||||
is KtBinaryExpression -> if (expressionInQuestion.operationToken === KtTokens.EQ) {
|
is KtBinaryExpression -> if (expressionInQuestion.operationToken === KtTokens.EQ) {
|
||||||
expressionInQuestion.right?.let {
|
expressionInQuestion.right?.let {
|
||||||
report(Errors.UNUSED_VALUE.on(expressionInQuestion, it, variableDescriptor), ctxt)
|
if (!variableDescriptor.isLocalVariableWithDelegate) {
|
||||||
|
report(Errors.UNUSED_VALUE.on(expressionInQuestion, it, variableDescriptor), ctxt)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is KtPostfixExpression -> {
|
is KtPostfixExpression -> {
|
||||||
@@ -689,6 +691,9 @@ class ControlFlowInformationProviderImpl private constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val VariableDescriptor.isLocalVariableWithDelegate: Boolean
|
||||||
|
get() = this is LocalVariableDescriptor && this.isDelegated
|
||||||
|
|
||||||
private fun processUnusedDeclaration(
|
private fun processUnusedDeclaration(
|
||||||
element: KtNamedDeclaration,
|
element: KtNamedDeclaration,
|
||||||
variableDescriptor: VariableDescriptor,
|
variableDescriptor: VariableDescriptor,
|
||||||
@@ -710,7 +715,9 @@ class ControlFlowInformationProviderImpl private constructor(
|
|||||||
processUnusedParameter(ctxt, element, variableDescriptor)
|
processUnusedParameter(ctxt, element, variableDescriptor)
|
||||||
}
|
}
|
||||||
} else if (variableUseState === ONLY_WRITTEN_NEVER_READ && KtPsiUtil.isRemovableVariableDeclaration(element)) {
|
} else if (variableUseState === ONLY_WRITTEN_NEVER_READ && KtPsiUtil.isRemovableVariableDeclaration(element)) {
|
||||||
report(Errors.ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE.on(element, variableDescriptor), ctxt)
|
if (!variableDescriptor.isLocalVariableWithDelegate) {
|
||||||
|
report(Errors.ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE.on(element, variableDescriptor), ctxt)
|
||||||
|
}
|
||||||
} else if (variableUseState === WRITTEN_AFTER_READ && element is KtVariableDeclaration) {
|
} else if (variableUseState === WRITTEN_AFTER_READ && element is KtVariableDeclaration) {
|
||||||
when (element) {
|
when (element) {
|
||||||
is KtProperty ->
|
is KtProperty ->
|
||||||
|
|||||||
Vendored
+40
@@ -0,0 +1,40 @@
|
|||||||
|
// ISSUE: KT-25527
|
||||||
|
|
||||||
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
|
fun test_1(delegate: Delegate) {
|
||||||
|
var p1 by delegate
|
||||||
|
p1 = 10
|
||||||
|
|
||||||
|
var p2 by delegate
|
||||||
|
p2++
|
||||||
|
|
||||||
|
var p3 by delegate
|
||||||
|
++p3
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test_2() {
|
||||||
|
var p1 = 0
|
||||||
|
p1 = 10
|
||||||
|
|
||||||
|
var p2: Int
|
||||||
|
p2 = 10
|
||||||
|
|
||||||
|
var p3 = 1
|
||||||
|
p3++
|
||||||
|
|
||||||
|
var p4 = 1
|
||||||
|
++p4
|
||||||
|
}
|
||||||
|
|
||||||
|
class Delegate {
|
||||||
|
var prop: Int = 0
|
||||||
|
|
||||||
|
operator fun getValue(thisRef: Any?, property: KProperty<*>): Int {
|
||||||
|
return prop
|
||||||
|
}
|
||||||
|
|
||||||
|
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: Int) {
|
||||||
|
prop = value
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+40
@@ -0,0 +1,40 @@
|
|||||||
|
// ISSUE: KT-25527
|
||||||
|
|
||||||
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
|
fun test_1(delegate: Delegate) {
|
||||||
|
var p1 by delegate
|
||||||
|
p1 = 10
|
||||||
|
|
||||||
|
var p2 by delegate
|
||||||
|
<!UNUSED_CHANGED_VALUE!>p2++<!>
|
||||||
|
|
||||||
|
var p3 by delegate
|
||||||
|
++p3
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test_2() {
|
||||||
|
var <!ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE!>p1<!> = 0
|
||||||
|
<!UNUSED_VALUE!>p1 =<!> 10
|
||||||
|
|
||||||
|
var <!ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE!>p2<!>: Int
|
||||||
|
<!UNUSED_VALUE!>p2 =<!> 10
|
||||||
|
|
||||||
|
var p3 = 1
|
||||||
|
<!UNUSED_CHANGED_VALUE!>p3++<!>
|
||||||
|
|
||||||
|
var p4 = 1
|
||||||
|
++p4
|
||||||
|
}
|
||||||
|
|
||||||
|
class Delegate {
|
||||||
|
var prop: Int = 0
|
||||||
|
|
||||||
|
operator fun getValue(thisRef: Any?, property: KProperty<*>): Int {
|
||||||
|
return prop
|
||||||
|
}
|
||||||
|
|
||||||
|
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: Int) {
|
||||||
|
prop = value
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+14
@@ -0,0 +1,14 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public fun test_1(/*0*/ delegate: Delegate): kotlin.Unit
|
||||||
|
public fun test_2(): kotlin.Unit
|
||||||
|
|
||||||
|
public final class Delegate {
|
||||||
|
public constructor Delegate()
|
||||||
|
public final var prop: kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public final operator fun getValue(/*0*/ thisRef: kotlin.Any?, /*1*/ property: kotlin.reflect.KProperty<*>): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public final operator fun setValue(/*0*/ thisRef: kotlin.Any?, /*1*/ property: kotlin.reflect.KProperty<*>, /*2*/ value: kotlin.Int): kotlin.Unit
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
Generated
+6
@@ -5950,6 +5950,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
|||||||
runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/unresolvedReference.kt");
|
runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/unresolvedReference.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("unusedPropertyWithCustomAccessors.kt")
|
||||||
|
public void testUnusedPropertyWithCustomAccessors() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/unusedPropertyWithCustomAccessors.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("useUninitializedInLambda.kt")
|
@TestMetadata("useUninitializedInLambda.kt")
|
||||||
public void testUseUninitializedInLambda() throws Exception {
|
public void testUseUninitializedInLambda() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user