[java-highlighting] IDEA-308514 Incorrect Java error highlighting when accessing private method of var local variable

GitOrigin-RevId: 29c869bc79161b6adf24f0090ee591cb9abc1c6b
This commit is contained in:
Mikhail Pyltsin
2023-07-20 15:30:26 +02:00
committed by intellij-monorepo-bot
parent 7a5fc9111f
commit b65d25e4eb
3 changed files with 14 additions and 1 deletions

View File

@@ -170,7 +170,13 @@ public class PsiTypeElementImpl extends CompositePsiElement implements PsiTypeEl
if (declarationScope instanceof PsiForeachStatement) {
PsiExpression iteratedValue = ((PsiForeachStatement)declarationScope).getIteratedValue();
if (iteratedValue != null) {
return JavaGenericsUtil.getCollectionItemType(iteratedValue);
PsiType type = JavaGenericsUtil.getCollectionItemType(iteratedValue);
//Upward projection is applied to the type of the initializer when determining the type of the
//variable
if (type instanceof PsiCapturedWildcardType) {
return ((PsiCapturedWildcardType)type).getUpperBound();
}
return type;
}
return null;
}

View File

@@ -0,0 +1,6 @@
public class VarCaptureForLoop {
private void foo() {}
public void bar(Iterable<? extends VarCaptureForLoop> data) {
for (var it : data) it.foo();
}
}

View File

@@ -454,4 +454,5 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testOnlyUncheckedWarningCastWithInnerClasses(){doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, true);}
public void testOnlyUncheckedWarningCastWithDuplicatedArguments(){doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, true);}
public void testCastUnboxingConversionWithWidening(){doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, true);}
public void testVarCaptureForLoop(){doTest(LanguageLevel.JDK_10, JavaSdkVersion.JDK_10, true);}
}