mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 21:11:28 +07:00
[java-highlighting] IDEA-341846 Code with instanceof for a local class inside a generic function is marked as red
- skip methods to capture parameters GitOrigin-RevId: df0c152d33bb9f880dad2428b7635d06209b3e0c
This commit is contained in:
committed by
intellij-monorepo-bot
parent
d1bc45d383
commit
b4dd504e01
@@ -977,7 +977,17 @@ public final class PsiUtil extends PsiUtilCore {
|
||||
|
||||
if (currentOwner.hasModifierProperty(PsiModifier.STATIC)) break;
|
||||
if (currentOwner instanceof PsiClass && isLocalClass((PsiClass)currentOwner)) {
|
||||
currentOwner = PsiTreeUtil.getParentOfType(currentOwner, PsiTypeParameterListOwner.class);
|
||||
//otherwise, parameters will be taken from methods
|
||||
boolean ownerIsStatic = false;
|
||||
do {
|
||||
currentOwner = PsiTreeUtil.getParentOfType(currentOwner, PsiTypeParameterListOwner.class);
|
||||
if (currentOwner != null && currentOwner.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
ownerIsStatic = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (currentOwner instanceof PsiMethod);
|
||||
if (ownerIsStatic) break;
|
||||
continue;
|
||||
}
|
||||
currentOwner = currentOwner.getContainingClass();
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
class C<A> {
|
||||
static <T> Object foo(Object x) {
|
||||
class Local {
|
||||
}
|
||||
return (x instanceof Local) ? x : new Local();
|
||||
}
|
||||
|
||||
static <T> Object foo2(Object x) {
|
||||
class Local<T> {
|
||||
}
|
||||
return (x instanceof Local) ? x : new Local();
|
||||
}
|
||||
|
||||
Object foo3(Object x) {
|
||||
class Local {
|
||||
}
|
||||
return (x instanceof <error descr="Illegal generic type for instanceof">Local</error>) ? x : new Local();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(C.<Integer>foo(""));
|
||||
}
|
||||
}
|
||||
@@ -1206,4 +1206,5 @@ public class GenericsHighlighting8Test extends LightDaemonAnalyzerTestCase {
|
||||
public void testLowerBoundAssignabilityCheck() { doTest(); }
|
||||
public void testIgnoreErasureForProperTypeBound() { doTest(); }
|
||||
public void testInferenceErrorAttribution() {doTest();}
|
||||
public void testLocalClassParameters() {doTest();}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user