Fix array access expression getKtType() bug
For an array access expression e.g., `foo[3]`, KtFirExpressionTypeProvider first tries `getReturnTypeForArrayStyleAssignmentTarget(..)` method that determines the type of the array access expression when it is in the form of "set" the value. However, the method also returns a non-null result for an array access expression that reads its value i.e., "get". In this case, the result of `getKtType()` becomes wrong. This commit lets the method return a null for the type of "get" array access expression.
This commit is contained in:
committed by
Nikolay Krasko
parent
b173b1fe24
commit
50c293f83f
+6
@@ -258,5 +258,11 @@ public class Fe10IdeNormalAnalysisSourceModuleHLExpressionTypeTestGenerated exte
|
|||||||
public void testArrayCompoundAssignementTarget() throws Exception {
|
public void testArrayCompoundAssignementTarget() throws Exception {
|
||||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expressionType/assignment/arrayCompoundAssignementTarget.kt");
|
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expressionType/assignment/arrayCompoundAssignementTarget.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("readArrayElement.kt")
|
||||||
|
public void testReadArrayElement() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expressionType/assignment/readArrayElement.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
@@ -90,6 +90,7 @@ internal class KtFirExpressionTypeProvider(
|
|||||||
if (expression !is KtArrayAccessExpression) return null
|
if (expression !is KtArrayAccessExpression) return null
|
||||||
val assignment = expression.parent as? KtBinaryExpression ?: return null
|
val assignment = expression.parent as? KtBinaryExpression ?: return null
|
||||||
if (assignment.operationToken !in KtTokens.ALL_ASSIGNMENTS) return null
|
if (assignment.operationToken !in KtTokens.ALL_ASSIGNMENTS) return null
|
||||||
|
if (assignment.left != expression) return null
|
||||||
val setTargetArgumentParameter = fir.argumentMapping?.entries?.last()?.value ?: return null
|
val setTargetArgumentParameter = fir.argumentMapping?.entries?.last()?.value ?: return null
|
||||||
return setTargetArgumentParameter.returnTypeRef.coneType.asKtType()
|
return setTargetArgumentParameter.returnTypeRef.coneType.asKtType()
|
||||||
}
|
}
|
||||||
|
|||||||
+6
@@ -258,5 +258,11 @@ public class FirIdeDependentAnalysisSourceModuleHLExpressionTypeTestGenerated ex
|
|||||||
public void testArrayCompoundAssignementTarget() throws Exception {
|
public void testArrayCompoundAssignementTarget() throws Exception {
|
||||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expressionType/assignment/arrayCompoundAssignementTarget.kt");
|
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expressionType/assignment/arrayCompoundAssignementTarget.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("readArrayElement.kt")
|
||||||
|
public void testReadArrayElement() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expressionType/assignment/readArrayElement.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
@@ -258,5 +258,11 @@ public class FirIdeNormalAnalysisSourceModuleHLExpressionTypeTestGenerated exten
|
|||||||
public void testArrayCompoundAssignementTarget() throws Exception {
|
public void testArrayCompoundAssignementTarget() throws Exception {
|
||||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expressionType/assignment/arrayCompoundAssignementTarget.kt");
|
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expressionType/assignment/arrayCompoundAssignementTarget.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("readArrayElement.kt")
|
||||||
|
public void testReadArrayElement() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expressionType/assignment/readArrayElement.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
@@ -258,5 +258,11 @@ public class FirStandaloneNormalAnalysisSourceModuleHLExpressionTypeTestGenerate
|
|||||||
public void testArrayCompoundAssignementTarget() throws Exception {
|
public void testArrayCompoundAssignementTarget() throws Exception {
|
||||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expressionType/assignment/arrayCompoundAssignementTarget.kt");
|
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expressionType/assignment/arrayCompoundAssignementTarget.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("readArrayElement.kt")
|
||||||
|
public void testReadArrayElement() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expressionType/assignment/readArrayElement.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
class FOO {
|
||||||
|
var str: String = ""
|
||||||
|
operator fun plusAssign(tk: String?) {
|
||||||
|
str += tk
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun main(args: Array<String?>) {
|
||||||
|
val foo: FOO = FOO()
|
||||||
|
if (args.size > 2)
|
||||||
|
foo += <expr>args[2]</expr>
|
||||||
|
else
|
||||||
|
foo += foo.toString()
|
||||||
|
}
|
||||||
+2
@@ -0,0 +1,2 @@
|
|||||||
|
expression: args[2]
|
||||||
|
type: kotlin.String?
|
||||||
Reference in New Issue
Block a user