diff --git a/compiler/fir/analysis-tests/testData/resolve/properties/kotlinOverridesJavaComplex.kt b/compiler/fir/analysis-tests/testData/resolve/properties/kotlinOverridesJavaComplex.kt new file mode 100644 index 00000000000..89d8068ffa2 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/properties/kotlinOverridesJavaComplex.kt @@ -0,0 +1,36 @@ +// FILE: Named.java + +public interface Named { + String getName(); +} + +// FILE: Psi.java + +public interface Psi { + +} + +// FILE: Member.java + +public interface Member extends Psi { + +} + +// FILE: Test.kt + +public interface Light + +public class LightMember : Light, Member { + override fun getName(): String = "Light" +} + +public interface Field : Named + +public class LightField : LightMember(), Field { + fun test(other: Any?) { + if (other is LightField<*>) { + other.name + } + } +} + diff --git a/compiler/fir/analysis-tests/testData/resolve/properties/kotlinOverridesJavaComplex.txt b/compiler/fir/analysis-tests/testData/resolve/properties/kotlinOverridesJavaComplex.txt new file mode 100644 index 00000000000..eaf30f72de9 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/properties/kotlinOverridesJavaComplex.txt @@ -0,0 +1,30 @@ +FILE: Test.kt + public abstract interface Light : R|kotlin/Any| { + } + public final class LightMember : R|Light|, R|Member| { + public constructor(): R|LightMember| { + super() + } + + public final override fun getName(): R|kotlin/String| { + ^getName String(Light) + } + + } + public abstract interface Field : R|Named| { + } + public final class LightField : R|LightMember|, R|Field| { + public constructor(): R|LightField| { + super|>() + } + + public final fun test(other: R|kotlin/Any?|): R|kotlin/Unit| { + when () { + (R|/other| is R|LightField<*>|) -> { + R|/other|.R|/LightMember.name| + } + } + + } + + } diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java index d0e0dedef1a..c761766f36e 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java @@ -1807,6 +1807,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest { runTest("compiler/fir/analysis-tests/testData/resolve/properties/javaAccessorsComplex.kt"); } + @TestMetadata("kotlinOverridesJavaComplex.kt") + public void testKotlinOverridesJavaComplex() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/properties/kotlinOverridesJavaComplex.kt"); + } + @TestMetadata("noBackingFieldForExtension.kt") public void testNoBackingFieldForExtension() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/properties/noBackingFieldForExtension.kt"); diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java index 29228cbf02c..9bde1c6ddb7 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java @@ -1807,6 +1807,11 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos runTest("compiler/fir/analysis-tests/testData/resolve/properties/javaAccessorsComplex.kt"); } + @TestMetadata("kotlinOverridesJavaComplex.kt") + public void testKotlinOverridesJavaComplex() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/properties/kotlinOverridesJavaComplex.kt"); + } + @TestMetadata("noBackingFieldForExtension.kt") public void testNoBackingFieldForExtension() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/properties/noBackingFieldForExtension.kt"); diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassSubstitutionScope.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassSubstitutionScope.kt index ec1fda61b3b..7c921821b06 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassSubstitutionScope.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassSubstitutionScope.kt @@ -68,13 +68,15 @@ class FirClassSubstitutionScope( functionSymbol: FirFunctionSymbol<*>, processor: (FirFunctionSymbol<*>, Int) -> ProcessorAction ): ProcessorAction { - val unwrapped = functionSymbol.overriddenSymbol as FirFunctionSymbol<*>? ?: functionSymbol - val overriddenDepth = if (unwrapped != functionSymbol) 1 else 0 - if (!processor(unwrapped, overriddenDepth)) { + if (!useSiteMemberScope.processOverriddenFunctionsWithDepth(functionSymbol, processor)) { + return ProcessorAction.STOP + } + val unwrapped = functionSymbol.overriddenSymbol as FirFunctionSymbol<*>? ?: return ProcessorAction.NEXT + if (!processor(unwrapped, 1)) { return ProcessorAction.STOP } return useSiteMemberScope.processOverriddenFunctionsWithDepth(unwrapped) { symbol, depth -> - processor(symbol, depth + overriddenDepth) + processor(symbol, depth + 1) } }