[K2]: Missing error and miscompilation in destructuring declaration delegation

In convertDestructingDeclaration, property delegates are mistakenly
treated as valid expressions for destructuring, but they should be
ignored.

#KT-65021 Fixed
This commit is contained in:
Anastasia.Nekrasova
2024-01-24 22:12:00 +02:00
committed by Space Team
parent b0367d9399
commit 1d817e2ace
8 changed files with 94 additions and 0 deletions
@@ -11609,6 +11609,22 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
}
}
@Nested
@TestMetadata("compiler/testData/diagnostics/tests/destructuring")
@TestDataPath("$PROJECT_ROOT")
public class Destructuring {
@Test
public void testAllFilesPresentInDestructuring() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/destructuring"), Pattern.compile("^(.+)\\.(kt|kts)$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true);
}
@Test
@TestMetadata("delegationInDestructuring.kt")
public void testDelegationInDestructuring() throws Exception {
runTest("compiler/testData/diagnostics/tests/destructuring/delegationInDestructuring.kt");
}
}
@Nested
@TestMetadata("compiler/testData/diagnostics/tests/duplicateJvmSignature")
@TestDataPath("$PROJECT_ROOT")
@@ -11609,6 +11609,22 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
}
}
@Nested
@TestMetadata("compiler/testData/diagnostics/tests/destructuring")
@TestDataPath("$PROJECT_ROOT")
public class Destructuring {
@Test
public void testAllFilesPresentInDestructuring() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/destructuring"), Pattern.compile("^(.+)\\.(kt|kts)$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true);
}
@Test
@TestMetadata("delegationInDestructuring.kt")
public void testDelegationInDestructuring() throws Exception {
runTest("compiler/testData/diagnostics/tests/destructuring/delegationInDestructuring.kt");
}
}
@Nested
@TestMetadata("compiler/testData/diagnostics/tests/duplicateJvmSignature")
@TestDataPath("$PROJECT_ROOT")
@@ -11603,6 +11603,22 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
}
}
@Nested
@TestMetadata("compiler/testData/diagnostics/tests/destructuring")
@TestDataPath("$PROJECT_ROOT")
public class Destructuring {
@Test
public void testAllFilesPresentInDestructuring() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/destructuring"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true, "multiplatform");
}
@Test
@TestMetadata("delegationInDestructuring.kt")
public void testDelegationInDestructuring() throws Exception {
runTest("compiler/testData/diagnostics/tests/destructuring/delegationInDestructuring.kt");
}
}
@Nested
@TestMetadata("compiler/testData/diagnostics/tests/duplicateJvmSignature")
@TestDataPath("$PROJECT_ROOT")
@@ -11609,6 +11609,22 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
}
}
@Nested
@TestMetadata("compiler/testData/diagnostics/tests/destructuring")
@TestDataPath("$PROJECT_ROOT")
public class Destructuring {
@Test
public void testAllFilesPresentInDestructuring() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/destructuring"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true, "multiplatform");
}
@Test
@TestMetadata("delegationInDestructuring.kt")
public void testDelegationInDestructuring() throws Exception {
runTest("compiler/testData/diagnostics/tests/destructuring/delegationInDestructuring.kt");
}
}
@Nested
@TestMetadata("compiler/testData/diagnostics/tests/duplicateJvmSignature")
@TestDataPath("$PROJECT_ROOT")
@@ -1475,6 +1475,8 @@ class LightTreeRawFirDeclarationBuilder(
MODIFIER_LIST -> annotations += convertAnnotationList(it)
VAR_KEYWORD -> isVar = true
DESTRUCTURING_DECLARATION_ENTRY -> entries += convertDestructingDeclarationEntry(it)
// Property delegates should be ignored as they aren't a valid initializers
PROPERTY_DELEGATE -> {}
else -> if (it.isExpression()) firExpression =
expressionConverter.getAsFirExpression(it, "Initializer required for destructuring declaration")
}
@@ -0,0 +1,6 @@
// WITH_STDLIB
fun foo() {
<!INITIALIZER_REQUIRED_FOR_DESTRUCTURING_DECLARATION!>val (a, b) by listOf(1, 2)<!>
<!INITIALIZER_REQUIRED_FOR_DESTRUCTURING_DECLARATION!>val (c, d) by lazy { listOf(3, 4) }<!>
}
@@ -0,0 +1,6 @@
// WITH_STDLIB
fun foo() {
<!INITIALIZER_REQUIRED_FOR_DESTRUCTURING_DECLARATION!>val (a, b) by <!DEBUG_INFO_MISSING_UNRESOLVED!>listOf<!>(1, 2)<!>
<!INITIALIZER_REQUIRED_FOR_DESTRUCTURING_DECLARATION!>val (c, d) by <!DEBUG_INFO_MISSING_UNRESOLVED!>lazy<!> { <!DEBUG_INFO_MISSING_UNRESOLVED!>listOf<!>(3, 4) }<!>
}
@@ -11609,6 +11609,22 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
}
}
@Nested
@TestMetadata("compiler/testData/diagnostics/tests/destructuring")
@TestDataPath("$PROJECT_ROOT")
public class Destructuring {
@Test
public void testAllFilesPresentInDestructuring() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/destructuring"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true);
}
@Test
@TestMetadata("delegationInDestructuring.kt")
public void testDelegationInDestructuring() throws Exception {
runTest("compiler/testData/diagnostics/tests/destructuring/delegationInDestructuring.kt");
}
}
@Nested
@TestMetadata("compiler/testData/diagnostics/tests/duplicateJvmSignature")
@TestDataPath("$PROJECT_ROOT")