mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-219623 Wrong inferred type on local variable
GitOrigin-RevId: fb54b2003a3f689b20bac8e74fb7d99f16302e55
This commit is contained in:
committed by
intellij-monorepo-bot
parent
b350b3472f
commit
e2e204d5e0
+13
-5
@@ -79,7 +79,9 @@ class InferenceCache {
|
||||
myTooComplexInstructions.addAll(interesting.first);
|
||||
}
|
||||
else {
|
||||
cacheDfaResult(dfaResult);
|
||||
Set<Instruction> stored = interesting.first;
|
||||
stored.add(instruction);
|
||||
cacheDfaResult(dfaResult, stored);
|
||||
}
|
||||
}
|
||||
DFAType dfaType = getCachedInferredType(descriptor, instruction);
|
||||
@@ -147,15 +149,21 @@ class InferenceCache {
|
||||
return pairs;
|
||||
}
|
||||
|
||||
private void cacheDfaResult(@NotNull List<TypeDfaState> dfaResult) {
|
||||
myVarTypes.accumulateAndGet(dfaResult, InferenceCache::addDfaResult);
|
||||
private void cacheDfaResult(@NotNull List<TypeDfaState> dfaResult,
|
||||
Set<Instruction> storingInstructions) {
|
||||
myVarTypes.accumulateAndGet(dfaResult, (oldState, newState) -> addDfaResult(oldState, newState, storingInstructions));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<TypeDfaState> addDfaResult(@NotNull List<TypeDfaState> oldTypes, @NotNull List<TypeDfaState> dfaResult) {
|
||||
private static List<TypeDfaState> addDfaResult(@NotNull List<TypeDfaState> oldTypes,
|
||||
@NotNull List<TypeDfaState> dfaResult,
|
||||
@NotNull Set<Instruction> storingInstructions) {
|
||||
List<TypeDfaState> newTypes = new ArrayList<>(oldTypes);
|
||||
Set<Integer> interestingInstructionNums = storingInstructions.stream().map(Instruction::num).collect(Collectors.toSet());
|
||||
for (int i = 0; i < dfaResult.size(); i++) {
|
||||
newTypes.set(i, newTypes.get(i).mergeWith(dfaResult.get(i)));
|
||||
if (interestingInstructionNums.contains(i)) {
|
||||
newTypes.set(i, newTypes.get(i).mergeWith(dfaResult.get(i)));
|
||||
}
|
||||
}
|
||||
return newTypes;
|
||||
}
|
||||
|
||||
+17
@@ -1164,4 +1164,21 @@ def test() {
|
||||
void 'test spread list of classes'() {
|
||||
doExprTest "[String, Integer]*.'class'", 'java.util.ArrayList<java.lang.Class<? extends java.lang.Class>>'
|
||||
}
|
||||
|
||||
void 'test reassigned local CS'() {
|
||||
doTest '''
|
||||
def aa = "1"
|
||||
a<caret>a.toUpperCase()
|
||||
if (false) {
|
||||
aa = new Object()
|
||||
aa
|
||||
}
|
||||
aa
|
||||
''', JAVA_LANG_STRING
|
||||
|
||||
myFixture.getDocument(file).getTextLength()
|
||||
def ref = file.findReferenceAt(myFixture.getDocument(file).getTextLength() - 2) as GrReferenceExpression
|
||||
def actual = ref.type
|
||||
assertType(JAVA_LANG_OBJECT, actual)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user