[FE] Fix exception from the 'UnusedChecker' on a destructuring

^KT-55973 Fixed
This commit is contained in:
Yan Zhulanow
2023-01-17 05:03:01 +09:00
committed by Space Team
parent 84baee1ef1
commit 9873fe84f2
6 changed files with 36 additions and 1 deletions
@@ -69,4 +69,10 @@ public class Fe10IdeNormalAnalysisSourceModuleCollectDiagnosticsTestGenerated ex
public void testUnresolved() throws Exception {
runTest("analysis/analysis-api/testData/components/diagnosticsProvider/diagnostics/unresolved.kt");
}
@Test
@TestMetadata("unusedDestructuring.kt")
public void testUnusedDestructuring() throws Exception {
runTest("analysis/analysis-api/testData/components/diagnosticsProvider/diagnostics/unusedDestructuring.kt");
}
}
@@ -69,4 +69,10 @@ public class FirIdeNormalAnalysisSourceModuleCollectDiagnosticsTestGenerated ext
public void testUnresolved() throws Exception {
runTest("analysis/analysis-api/testData/components/diagnosticsProvider/diagnostics/unresolved.kt");
}
@Test
@TestMetadata("unusedDestructuring.kt")
public void testUnusedDestructuring() throws Exception {
runTest("analysis/analysis-api/testData/components/diagnosticsProvider/diagnostics/unusedDestructuring.kt");
}
}
@@ -69,4 +69,10 @@ public class FirStandaloneNormalAnalysisSourceModuleCollectDiagnosticsTestGenera
public void testUnresolved() throws Exception {
runTest("analysis/analysis-api/testData/components/diagnosticsProvider/diagnostics/unresolved.kt");
}
@Test
@TestMetadata("unusedDestructuring.kt")
public void testUnusedDestructuring() throws Exception {
runTest("analysis/analysis-api/testData/components/diagnosticsProvider/diagnostics/unusedDestructuring.kt");
}
}
@@ -0,0 +1,11 @@
class Test {
private fun test(x: Int, y: Int) {
val (_, _) = invert(x, y)
}
private fun invert(x: Int, y: Int): Point {
return Point(-x, -y)
}
}
data class Point(val x: Int, val y: Int)
@@ -0,0 +1 @@
Diagnostics from elements:
@@ -79,7 +79,12 @@ object UnusedChecker : AbstractFirPropertyInitializationChecker() {
variableSymbol.lazyResolveToPhase(FirResolvePhase.BODY_RESOLVE)
@OptIn(SymbolInternals::class)
val variable = variableSymbol.fir
val variableSource = variable.source.takeIf { it?.elementType != KtNodeTypes.DESTRUCTURING_DECLARATION }
val variableSource = variable.source
if (variableSource?.elementType == KtNodeTypes.DESTRUCTURING_DECLARATION) {
continue
}
when {
data == VariableStatus.UNUSED -> {
when {