From 9a86b83a0cc71809c469828bbb0f42a0817beb82 Mon Sep 17 00:00:00 2001 From: Ivan Kochurkin Date: Tue, 13 Feb 2024 15:18:57 +0100 Subject: [PATCH] [FIR] Fix crash on assignment expression with incorrect lvalue with LT mode ^KT-65241 Fixed --- .../DiagnosticCompilerTestFE10TestdataTestGenerated.java | 6 ++++++ ...eversedDiagnosticCompilerFE10TestDataTestGenerated.java | 6 ++++++ .../FirLightTreeOldFrontendDiagnosticsTestGenerated.java | 6 ++++++ .../runners/FirPsiOldFrontendDiagnosticsTestGenerated.java | 6 ++++++ .../converter/LightTreeRawFirExpressionBuilder.kt | 2 +- .../tests/exceptions/assignmentWithIncorrectLValue.fir.kt | 7 +++++++ .../tests/exceptions/assignmentWithIncorrectLValue.kt | 7 +++++++ .../integration/smoke/syntaxErrors/test.compile.expected | 3 +++ .../kotlin/test/runners/DiagnosticTestGenerated.java | 6 ++++++ 9 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/diagnostics/tests/exceptions/assignmentWithIncorrectLValue.fir.kt create mode 100644 compiler/testData/diagnostics/tests/exceptions/assignmentWithIncorrectLValue.kt diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java index 66ff23aeba4..4f8c29bd29d 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java @@ -13184,6 +13184,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia runTest("compiler/testData/diagnostics/tests/exceptions/annotationWithWrongArgInDanglingModifierList.kt"); } + @Test + @TestMetadata("assignmentWithIncorrectLValue.kt") + public void testAssignmentWithIncorrectLValue() { + runTest("compiler/testData/diagnostics/tests/exceptions/assignmentWithIncorrectLValue.kt"); + } + @Test @TestMetadata("expectedSomeTypesOnBranchForWhenExpressionOfErroneousType.kt") public void testExpectedSomeTypesOnBranchForWhenExpressionOfErroneousType() { diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java index c665057ada3..aad6d76526e 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java @@ -13184,6 +13184,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated runTest("compiler/testData/diagnostics/tests/exceptions/annotationWithWrongArgInDanglingModifierList.kt"); } + @Test + @TestMetadata("assignmentWithIncorrectLValue.kt") + public void testAssignmentWithIncorrectLValue() { + runTest("compiler/testData/diagnostics/tests/exceptions/assignmentWithIncorrectLValue.kt"); + } + @Test @TestMetadata("expectedSomeTypesOnBranchForWhenExpressionOfErroneousType.kt") public void testExpectedSomeTypesOnBranchForWhenExpressionOfErroneousType() { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java index 29c685a4cc2..43004a3d068 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java @@ -13178,6 +13178,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/tests/exceptions/annotationWithWrongArgInDanglingModifierList.kt"); } + @Test + @TestMetadata("assignmentWithIncorrectLValue.kt") + public void testAssignmentWithIncorrectLValue() { + runTest("compiler/testData/diagnostics/tests/exceptions/assignmentWithIncorrectLValue.kt"); + } + @Test @TestMetadata("expectedSomeTypesOnBranchForWhenExpressionOfErroneousType.kt") public void testExpectedSomeTypesOnBranchForWhenExpressionOfErroneousType() { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java index 3148c024509..49a17793af7 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java @@ -13184,6 +13184,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/tests/exceptions/annotationWithWrongArgInDanglingModifierList.kt"); } + @Test + @TestMetadata("assignmentWithIncorrectLValue.kt") + public void testAssignmentWithIncorrectLValue() { + runTest("compiler/testData/diagnostics/tests/exceptions/assignmentWithIncorrectLValue.kt"); + } + @Test @TestMetadata("expectedSomeTypesOnBranchForWhenExpressionOfErroneousType.kt") public void testExpectedSomeTypesOnBranchForWhenExpressionOfErroneousType() { diff --git a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/LightTreeRawFirExpressionBuilder.kt b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/LightTreeRawFirExpressionBuilder.kt index fa64ae2cb90..34d5371b657 100644 --- a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/LightTreeRawFirExpressionBuilder.kt +++ b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/LightTreeRawFirExpressionBuilder.kt @@ -625,7 +625,7 @@ class LightTreeRawFirExpressionBuilder( } return result ?: buildErrorExpression { - source = null + source = dotQualifiedExpression.toFirSourceElement() diagnostic = ConeSyntaxDiagnostic("Qualified expression without selector") // if there is no selector, we still want to resolve the receiver diff --git a/compiler/testData/diagnostics/tests/exceptions/assignmentWithIncorrectLValue.fir.kt b/compiler/testData/diagnostics/tests/exceptions/assignmentWithIncorrectLValue.fir.kt new file mode 100644 index 00000000000..50189445a6f --- /dev/null +++ b/compiler/testData/diagnostics/tests/exceptions/assignmentWithIncorrectLValue.fir.kt @@ -0,0 +1,7 @@ +// ISSUE: KT-65241 + +object A + +fun test() { + A.else = 42 +} diff --git a/compiler/testData/diagnostics/tests/exceptions/assignmentWithIncorrectLValue.kt b/compiler/testData/diagnostics/tests/exceptions/assignmentWithIncorrectLValue.kt new file mode 100644 index 00000000000..b3b6399079b --- /dev/null +++ b/compiler/testData/diagnostics/tests/exceptions/assignmentWithIncorrectLValue.kt @@ -0,0 +1,7 @@ +// ISSUE: KT-65241 + +object A + +fun test() { + A.else = 42 +} diff --git a/compiler/testData/integration/smoke/syntaxErrors/test.compile.expected b/compiler/testData/integration/smoke/syntaxErrors/test.compile.expected index 432fc50629a..ca2540daa93 100644 --- a/compiler/testData/integration/smoke/syntaxErrors/test.compile.expected +++ b/compiler/testData/integration/smoke/syntaxErrors/test.compile.expected @@ -3,6 +3,9 @@ ERR: test.kt:4:13: error: classifier 'class System : Any' does not have a companion object, so it cannot be used as an expression. val s = System.in ^^^^^^ +test.kt:4:13: error: syntax error: Qualified expression without selector. + val s = System.in + ^^^^^^^^^ test.kt:4:20: error: syntax error: Expecting an element. val s = System.in ^^ diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index 38c77876851..0a5822a2c77 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -13184,6 +13184,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/exceptions/annotationWithWrongArgInDanglingModifierList.kt"); } + @Test + @TestMetadata("assignmentWithIncorrectLValue.kt") + public void testAssignmentWithIncorrectLValue() { + runTest("compiler/testData/diagnostics/tests/exceptions/assignmentWithIncorrectLValue.kt"); + } + @Test @TestMetadata("expectedSomeTypesOnBranchForWhenExpressionOfErroneousType.kt") public void testExpectedSomeTypesOnBranchForWhenExpressionOfErroneousType() {