diff --git a/java/java-psi-impl/src/com/intellij/psi/scope/conflictResolvers/JavaVariableConflictResolver.java b/java/java-psi-impl/src/com/intellij/psi/scope/conflictResolvers/JavaVariableConflictResolver.java index d3066dff8f40..b644014b9d60 100644 --- a/java/java-psi-impl/src/com/intellij/psi/scope/conflictResolvers/JavaVariableConflictResolver.java +++ b/java/java-psi-impl/src/com/intellij/psi/scope/conflictResolvers/JavaVariableConflictResolver.java @@ -1,6 +1,7 @@ -// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.psi.scope.conflictResolvers; +import com.intellij.psi.PsiAnonymousClass; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiField; @@ -91,7 +92,8 @@ public class JavaVariableConflictResolver implements PsiConflictResolver{ if (oldClassIsInheritor == null) { oldClassIsInheritor = oldClass != null && newClass != null && oldClass.isInheritor(newClass, true); } - if (oldClassIsInheritor) { + if (oldClassIsInheritor && (scope instanceof PsiAnonymousClass || + !(scope instanceof PsiClass && ((PsiClass)scope).isInheritorDeep(oldClass, newClass)))) { // both fields are accessible // field in derived hides field in base conflicts.remove(candidate); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/AmbiguousConstants.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/AmbiguousConstants.java index 93e9e73c0c9f..d17f9f5e5683 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/AmbiguousConstants.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/AmbiguousConstants.java @@ -28,4 +28,40 @@ class Shadowing { interface C extends B { int Y = C.X; } +} + +class MultipleInheritance2 { + interface I1 { + String X = "x"; + } + static class Y implements I1 { + public static final String X = "y"; + } + + static class Z extends Y { + { + System.out.println(X); + } + } + + static class Z1 extends Y implements I1 { + { + System.out.println(X); + } + } + + interface I2 extends I1 {} + static class Z2 extends Y implements I2 { + { + System.out.println(X); + } + } + + static class Z3 extends Y implements Runnable, I2 { + { + System.out.println(X); + } + + public void run() {} + } } \ No newline at end of file