[kotlin-dfa] Fix anchor for array store (KTIJ-24314)

GitOrigin-RevId: 795f7978bd12cc4cf02abff89c913b9cc5583b14
This commit is contained in:
Tagir Valeev
2023-01-18 17:31:50 +01:00
committed by intellij-monorepo-bot
parent fc26ba2b00
commit d288fc7bb1
3 changed files with 19 additions and 2 deletions

View File

@@ -41,4 +41,9 @@ public class FoldArrayInstruction extends EvalInstruction {
DfType type = SpecialField.ARRAY_LENGTH.asDfType(myTargetType.meet(DfTypes.NOT_NULL_OBJECT), DfTypes.intValue(arguments.length));
return factory.fromDfType(type);
}
@Override
public String toString() {
return "FOLD_ARRAY " + myTargetType;
}
}

View File

@@ -348,7 +348,13 @@ class KtControlFlowBuilder(val factory: DfaValueFactory, val context: KtExpressi
for (idx in indexes) {
processExpression(idx)
val lastIndex = idx == indexes.last()
val anchor = if (lastIndex) KotlinExpressionAnchor(expr) else null
val anchor = if (lastIndex) {
if (storedValue != null)
KotlinExpressionAnchor(PsiTreeUtil.findCommonParent(expr, storedValue) as? KtExpression ?: expr)
else
KotlinExpressionAnchor(expr)
}
else null
val expectedType = if (lastIndex) expr.getKotlinType()?.toDfType() ?: DfType.TOP else DfType.TOP
var indexType = idx.getKotlinType()
val constructor = indexType?.constructor as? IntegerLiteralTypeConstructor

View File

@@ -56,4 +56,10 @@ fun nullableArraySize(x : Array<Int>?) {
}
}
data class X(val x: Int)
data class X(val x: Int)
fun storeNull() {
// KTIJ-24314
val array: Array<Int?> = arrayOf(0)
array[0] = 1
array[0] = null
}