diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt index 45650620fdc..c2bf7588346 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt @@ -1527,15 +1527,17 @@ open class FirExpressionsResolveTransformer(transformer: FirAbstractBodyResolveT lhsGetCall: FirFunctionCall, transformedRhs: FirExpression ): AugmentedArraySetAsGetSetCallDesugaringInfo { + val initializer = lhsGetCall.explicitReceiver ?: buildErrorExpression { + source = augmentedArraySetCall.source + ?.fakeElement(KtFakeSourceElementKind.DesugaredCompoundAssignment) + diagnostic = ConeSyntaxDiagnostic("No receiver for array access") + } val arrayVariable = generateTemporaryVariable( session.moduleData, source = lhsGetCall.explicitReceiver?.source?.fakeElement(KtFakeSourceElementKind.DesugaredCompoundAssignment), name = SpecialNames.ARRAY, - initializer = lhsGetCall.explicitReceiver ?: buildErrorExpression { - source = augmentedArraySetCall.source - ?.fakeElement(KtFakeSourceElementKind.DesugaredCompoundAssignment) - diagnostic = ConeSyntaxDiagnostic("No receiver for array access") - } + initializer = initializer, + typeRef = initializer.typeRef.copyWithNewSourceKind(KtFakeSourceElementKind.DesugaredCompoundAssignment), ) val indexVariables = lhsGetCall.arguments.flatMap { diff --git a/compiler/testData/diagnostics/tests/AssignToArrayElement.kt b/compiler/testData/diagnostics/tests/AssignToArrayElement.kt index 7600d50611e..a5389ee6fb8 100644 --- a/compiler/testData/diagnostics/tests/AssignToArrayElement.kt +++ b/compiler/testData/diagnostics/tests/AssignToArrayElement.kt @@ -1,6 +1,9 @@ // FIR_IDENTICAL +// !DIAGNOSTICS: -DEBUG_INFO_SMARTCAST + fun getArray(): Array = throw Exception() fun getList(): MutableList = throw Exception() +fun getNullableList(): MutableList? = throw Exception() fun fn() { getArray()[1] = 2 getList()[1] = 2 @@ -8,4 +11,9 @@ fun fn() { getList()[1]++ getArray()[1] += 2 getList()[1] += 2 + + val nullable = getNullableList() + if (nullable != null) { + nullable[1] += 1 + } } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/AssignToArrayElement.txt b/compiler/testData/diagnostics/tests/AssignToArrayElement.txt index 005e1f56b37..15712579dc1 100644 --- a/compiler/testData/diagnostics/tests/AssignToArrayElement.txt +++ b/compiler/testData/diagnostics/tests/AssignToArrayElement.txt @@ -3,3 +3,5 @@ package public fun fn(): kotlin.Unit public fun getArray(): kotlin.Array public fun getList(): kotlin.collections.MutableList +public fun getNullableList(): kotlin.collections.MutableList? + diff --git a/compiler/testData/diagnostics/testsWithStdLib/smartcasts/unsoundSmartcast.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/smartcasts/unsoundSmartcast.fir.kt index b95f03fc4f4..0de795dd2a7 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/smartcasts/unsoundSmartcast.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/smartcasts/unsoundSmartcast.fir.kt @@ -4,7 +4,7 @@ fun test1() { var x: MutableList? = mutableListOf(1) x!! - x[if (true) { x = null; 0 } else 0] += x[0] + x[if (true) { x = null; 0 } else 0] += x[0] x[0].inv() } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/13.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/13.fir.kt index 0d950cdecae..d4fa15e2cf3 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/13.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/13.fir.kt @@ -15,7 +15,7 @@ // TESTCASE NUMBER: 1 fun case_1(x: Class?) { x!! - x[if (true) {x=null;0} else 0] += x[0] + x[if (true) {x=null;0} else 0] += x[0] x x[0].inv() } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/26.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/26.fir.kt index d45eef5fe12..79a036b6fab 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/26.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/26.fir.kt @@ -18,7 +18,7 @@ fun case_1() { var x: MutableList? = mutableListOf(1) x!! - ? & kotlin.collections.MutableList")!>x[if (true) {x=null;0} else 0] += ?")!>x[0] + ? & kotlin.collections.MutableList"), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.MutableList"), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.MutableList")!>x[if (true) {x=null;0} else 0] += ?")!>x[0] ?")!>x ?")!>x[0].inv() }