KT-59504 [FIR] Check _ on destructuring declarations
Previously the checker was ignoring them, leading to missing diagnostics ^KT-59504 Fixed
This commit is contained in:
committed by
Space Team
parent
59129501cb
commit
b1551c67e0
+6
@@ -9191,6 +9191,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
||||
runTest("compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/lastDestructuringDeclarationInBlock.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("missingComponentN.kt")
|
||||
public void testMissingComponentN() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/missingComponentN.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("RedeclarationInForLoop.kt")
|
||||
public void testRedeclarationInForLoop() throws Exception {
|
||||
|
||||
+6
@@ -9191,6 +9191,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
||||
runTest("compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/lastDestructuringDeclarationInBlock.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("missingComponentN.kt")
|
||||
public void testMissingComponentN() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/missingComponentN.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("RedeclarationInForLoop.kt")
|
||||
public void testRedeclarationInForLoop() throws Exception {
|
||||
|
||||
+6
@@ -9191,6 +9191,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
||||
runTest("compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/lastDestructuringDeclarationInBlock.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("missingComponentN.kt")
|
||||
public void testMissingComponentN() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/missingComponentN.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("RedeclarationInForLoop.kt")
|
||||
public void testRedeclarationInForLoop() throws Exception {
|
||||
|
||||
+6
@@ -9197,6 +9197,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
||||
runTest("compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/lastDestructuringDeclarationInBlock.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("missingComponentN.kt")
|
||||
public void testMissingComponentN() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/missingComponentN.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("RedeclarationInForLoop.kt")
|
||||
public void testRedeclarationInForLoop() throws Exception {
|
||||
|
||||
-2
@@ -26,13 +26,11 @@ import org.jetbrains.kotlin.fir.symbols.SymbolInternals
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.lazyResolveToPhase
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.name.SpecialNames
|
||||
import org.jetbrains.kotlin.types.AbstractTypeChecker
|
||||
|
||||
object FirDestructuringDeclarationChecker : FirPropertyChecker() {
|
||||
override fun check(declaration: FirProperty, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
val source = declaration.source ?: return
|
||||
if (declaration.name == SpecialNames.UNDERSCORE_FOR_UNUSED_VAR) return
|
||||
// val (...) = `destructuring_declaration`
|
||||
if (source.elementType == KtNodeTypes.DESTRUCTURING_DECLARATION) {
|
||||
checkInitializer(source, declaration.initializer, reporter, context)
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ fun useDeclaredVariables() {
|
||||
}
|
||||
|
||||
fun checkersShouldRun() {
|
||||
val (@A a, _) = <!COMPONENT_FUNCTION_MISSING, UNRESOLVED_REFERENCE!>unresolved<!>
|
||||
val (@A a, _) = <!COMPONENT_FUNCTION_MISSING, COMPONENT_FUNCTION_MISSING, UNRESOLVED_REFERENCE!>unresolved<!>
|
||||
}
|
||||
|
||||
annotation class A
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
class A {
|
||||
operator fun component1() = 1
|
||||
operator fun component2() = ""
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val (_, _) = A()
|
||||
val (_, _, _) = <!COMPONENT_FUNCTION_MISSING!>A()<!>
|
||||
|
||||
val (_: Int, _: String) = A()
|
||||
val (_: String, _) = <!COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH!>A()<!>
|
||||
|
||||
val f: (A) -> Int = { (_, _) -> 1 }
|
||||
val g: (A) -> Int = { <!COMPONENT_FUNCTION_MISSING!>(_, _, _)<!> -> 2 }
|
||||
val h: (A) -> Int = { (<!COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH!>_: String<!>, _) -> 3}
|
||||
}
|
||||
compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/missingComponentN.kt
Vendored
+16
@@ -0,0 +1,16 @@
|
||||
class A {
|
||||
operator fun component1() = 1
|
||||
operator fun component2() = ""
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val (_, _) = A()
|
||||
val (_, _, _) = <!COMPONENT_FUNCTION_MISSING!>A()<!>
|
||||
|
||||
val (_: Int, _: String) = A()
|
||||
val (_: String, _) = <!COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH!>A()<!>
|
||||
|
||||
val f: (A) -> Int = { (_, _) -> 1 }
|
||||
val g: (A) -> Int = { (_, _, <!COMPONENT_FUNCTION_MISSING!>_<!>) -> 2 }
|
||||
val h: (A) -> Int = { (<!COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH!>_: String<!>, _) -> 3}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package
|
||||
|
||||
public fun test(): kotlin.Unit
|
||||
|
||||
public final class A {
|
||||
public constructor A()
|
||||
public final operator fun component1(): kotlin.Int
|
||||
public final operator fun component2(): kotlin.String
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
Vendored
+1
-1
@@ -25,7 +25,7 @@ fun test() {
|
||||
foo(<!UNRESOLVED_REFERENCE!>_<!>, <!UNRESOLVED_REFERENCE!>_<!>)
|
||||
}
|
||||
|
||||
for ((_ : String, _ : Int) in C()) {
|
||||
for ((_ : String, _ : Int) in <!COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH, COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH!>C()<!>) {
|
||||
foo(<!UNRESOLVED_REFERENCE!>_<!>, <!UNRESOLVED_REFERENCE!>_<!>)
|
||||
}
|
||||
|
||||
|
||||
Vendored
+1
-1
@@ -50,7 +50,7 @@ fun bar() {
|
||||
_ checkType { _<String>() }
|
||||
}
|
||||
|
||||
foo { (_: String, b) ->
|
||||
foo { (<!COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH!>_: String<!>, b) ->
|
||||
<!UNRESOLVED_REFERENCE!>_<!>.hashCode()
|
||||
b checkType { _<String>() }
|
||||
}
|
||||
|
||||
Generated
+6
@@ -9197,6 +9197,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/lastDestructuringDeclarationInBlock.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("missingComponentN.kt")
|
||||
public void testMissingComponentN() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/missingComponentN.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("RedeclarationInForLoop.kt")
|
||||
public void testRedeclarationInForLoop() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user