IDEA-380311 [java-highlighting] Invalid code "cannot referenced from static context" not highlighted properly in Java

Follow-up: proper qualified references handling

GitOrigin-RevId: c7f470065ab5c4ad97c9fb6ba02d6fa603e62a84
This commit is contained in:
Tagir Valeev
2026-03-03 07:57:52 +00:00
committed by intellij-monorepo-bot
parent 792b57745a
commit acef03c3e4
3 changed files with 44 additions and 0 deletions
@@ -1700,6 +1700,10 @@ final class ExpressionChecker {
newExpression.getClassOrAnonymousClassReference() == expression) {
return;
}
if (parent instanceof PsiNewExpression newExpression && newExpression.getQualifier() != null) {
// The qualifier will be checked instead
return;
}
if (parent instanceof PsiThisExpression || parent instanceof PsiSuperExpression) return;
}
if (!(expression instanceof PsiThisExpression) && !(expression instanceof PsiSuperExpression) ||
@@ -0,0 +1,39 @@
class A {
A(C c) {}
static class B extends A {
B() {
super(<error descr="'A.this' cannot be referenced from a static context">A.this</error>.new C());
}
B(int x) {
super(<error descr="'A.this' cannot be referenced from a static context">A.this</error>.getC());
}
B(double x) {
super(<error descr="'A.this' cannot be referenced from a static context">A.this</error>.c);
}
}
class B1 extends A {
B1() {
super(A.this.new C());
}
B1(int x) {
super(A.this.getC());
}
B1(double x) {
super(A.this.c);
}
}
private C getC() {
return new C();
}
private C c = new C();
private class C {}
}
@@ -50,4 +50,5 @@ public class LightAdvHighlightingJdk8Test extends LightDaemonAnalyzerTestCase {
}
public void testCyclicInheritanceOfTypeAnnotation() { doTest(true, true); }
public void testReferenceToPrivateClass() { doTest(true, true); }
public void testReferenceToPrivateClassOuterThis() { doTest(true, true); }
}