[AA] Fix getKtExpressionType for augmented array assignment
This previously worked on accident because the get call in an augmented array assignment wouldn't have a resolved argument list, and so `argumentsToSubstitutedValueParameters` would return null. Now, we additionally verify that we're in a `set` call. #KT-66124
This commit is contained in:
committed by
Space Team
parent
0cac6b66d5
commit
1876c8a9ee
+6
@@ -313,6 +313,12 @@ public class Fe10IdeNormalAnalysisSourceModuleHLExpressionTypeTestGenerated exte
|
||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expressionType/assignment/arrayCompoundAssignementTarget.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("augmentedArrayAssigment.kt")
|
||||
public void testAugmentedArrayAssigment() {
|
||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expressionType/assignment/augmentedArrayAssigment.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("readArrayElement.kt")
|
||||
public void testReadArrayElement() {
|
||||
|
||||
+3
-1
@@ -33,6 +33,7 @@ import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getOutermostParenthesizerOrThis
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.applyIf
|
||||
import org.jetbrains.kotlin.utils.exceptions.rethrowExceptionWithDetails
|
||||
import org.jetbrains.kotlin.utils.exceptions.withPsiEntry
|
||||
@@ -150,7 +151,8 @@ internal class KtFirExpressionTypeProvider(
|
||||
expression: KtExpression,
|
||||
fir: FirFunctionCall,
|
||||
): KtType? {
|
||||
if (fir.calleeReference !is FirResolvedNamedReference) return null
|
||||
// When we're in a call like `a[x] = y`, we want to get the `set` call's last argument's type.
|
||||
if (fir.calleeReference !is FirResolvedNamedReference || fir.calleeReference.name != OperatorNameConventions.SET) return null
|
||||
if (expression !is KtArrayAccessExpression) return null
|
||||
val assignment = expression.parent as? KtBinaryExpression ?: return null
|
||||
if (assignment.operationToken !in KtTokens.ALL_ASSIGNMENTS) return null
|
||||
|
||||
+6
@@ -313,6 +313,12 @@ public class FirIdeDependentAnalysisSourceModuleHLExpressionTypeTestGenerated ex
|
||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expressionType/assignment/arrayCompoundAssignementTarget.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("augmentedArrayAssigment.kt")
|
||||
public void testAugmentedArrayAssigment() {
|
||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expressionType/assignment/augmentedArrayAssigment.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("readArrayElement.kt")
|
||||
public void testReadArrayElement() {
|
||||
|
||||
+6
@@ -313,6 +313,12 @@ public class FirIdeNormalAnalysisSourceModuleHLExpressionTypeTestGenerated exten
|
||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expressionType/assignment/arrayCompoundAssignementTarget.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("augmentedArrayAssigment.kt")
|
||||
public void testAugmentedArrayAssigment() {
|
||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expressionType/assignment/augmentedArrayAssigment.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("readArrayElement.kt")
|
||||
public void testReadArrayElement() {
|
||||
|
||||
+6
@@ -313,6 +313,12 @@ public class FirStandaloneNormalAnalysisSourceModuleHLExpressionTypeTestGenerate
|
||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expressionType/assignment/arrayCompoundAssignementTarget.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("augmentedArrayAssigment.kt")
|
||||
public void testAugmentedArrayAssigment() {
|
||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expressionType/assignment/augmentedArrayAssigment.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("readArrayElement.kt")
|
||||
public void testReadArrayElement() {
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
operator fun Array<String>.get(index1: Int, index2: Int) = this[index1 + index2]
|
||||
operator fun Array<String>.set(index1: Int, index2: Int, elem: String) {
|
||||
this[index1 + index2] = elem
|
||||
}
|
||||
|
||||
fun test(s: Array<String>) {
|
||||
<expr>s[2, -2]</expr> += "K"
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
expression: s[2, -2]
|
||||
type: kotlin.String
|
||||
Reference in New Issue
Block a user