diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java index 1b3c597d975..39e2685e56c 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java @@ -20954,6 +20954,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia runTest("compiler/testData/diagnostics/tests/j+k/kt60580.kt"); } + @Test + @TestMetadata("kt62197.kt") + public void testKt62197() throws Exception { + runTest("compiler/testData/diagnostics/tests/j+k/kt62197.kt"); + } + @Test @TestMetadata("kt6720_abstractProperty.kt") public void testKt6720_abstractProperty() throws Exception { diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java index 01eee7c15e6..78d97d48d40 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java @@ -20954,6 +20954,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated runTest("compiler/testData/diagnostics/tests/j+k/kt60580.kt"); } + @Test + @TestMetadata("kt62197.kt") + public void testKt62197() throws Exception { + runTest("compiler/testData/diagnostics/tests/j+k/kt62197.kt"); + } + @Test @TestMetadata("kt6720_abstractProperty.kt") public void testKt6720_abstractProperty() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java index 3fe86efd2da..386c221d863 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java @@ -20948,6 +20948,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/tests/j+k/kt60580.kt"); } + @Test + @TestMetadata("kt62197.kt") + public void testKt62197() throws Exception { + runTest("compiler/testData/diagnostics/tests/j+k/kt62197.kt"); + } + @Test @TestMetadata("kt6720_abstractProperty.kt") public void testKt6720_abstractProperty() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java index a5e6db89800..f78a6ffdd08 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java @@ -20954,6 +20954,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/tests/j+k/kt60580.kt"); } + @Test + @TestMetadata("kt62197.kt") + public void testKt62197() throws Exception { + runTest("compiler/testData/diagnostics/tests/j+k/kt62197.kt"); + } + @Test @TestMetadata("kt6720_abstractProperty.kt") public void testKt6720_abstractProperty() throws Exception { diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaClassUseSiteMemberScope.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaClassUseSiteMemberScope.kt index 93ea9463851..c6f6bd035a2 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaClassUseSiteMemberScope.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaClassUseSiteMemberScope.kt @@ -393,12 +393,19 @@ class JavaClassUseSiteMemberScope( destination: MutableCollection ) { val resultsOfIntersectionToSaveInCache = mutableListOf>() + // The special override checker is needed for the case when we're trying to consider e.g. explicitly defined `Long toLong()` + // as an override of `long toLong()` which is an enhanced version of `long longValue()`. K1 in such cases used + // LazyJavaClassMemberScope.doesOverride, that ignores the return type, so we reproduce the behavior here. + // See the test testData/diagnostics/tests/j+k/kt62197.kt and the issue KT-62197 for more details. + // TODO: consider some more transparent approach + val overrideCheckerForSpecialFunctions = + JavaOverrideChecker(session, klass.javaTypeParameterStack, superTypeScopes, considerReturnTypeKinds = false) val intersectionResults = supertypeScopeContext.convertGroupedCallablesToIntersectionResults(functionsFromSupertypesWithRequestedName) for (resultOfIntersectionWithNaturalName in intersectionResults) { val someSymbolWithNaturalNameFromSuperType = resultOfIntersectionWithNaturalName.extractSomeSymbolFromSuperType() val explicitlyDeclaredFunctionWithNaturalName = explicitlyDeclaredFunctionsWithNaturalName.firstOrNull { - overrideChecker.isOverriddenFunction(it, someSymbolWithNaturalNameFromSuperType) + overrideCheckerForSpecialFunctions.isOverriddenFunction(it, someSymbolWithNaturalNameFromSuperType) } val jvmName = resultOfIntersectionWithNaturalName.overriddenMembers.firstNotNullOfOrNull { it.member.getJvmMethodNameIfSpecial(it.baseScope, session) diff --git a/compiler/testData/diagnostics/tests/j+k/kt62197.kt b/compiler/testData/diagnostics/tests/j+k/kt62197.kt new file mode 100644 index 00000000000..1a9a74b8ea2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/kt62197.kt @@ -0,0 +1,35 @@ +// FIR_IDENTICAL +// FILE: main.kt + +fun main() { + MutableLong().toLong() +} + +// FILE: MutableLong.java +public class MutableLong extends Number { + + private long value; + + public MutableLong() { + } + + public int intValue() { + return (int)this.value; + } + + public long longValue() { + return this.value; + } + + public float floatValue() { + return (float)this.value; + } + + public double doubleValue() { + return (double)this.value; + } + + public Long toLong() { + return this.longValue(); + } +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index 7d1856f53b4..c874ea135ef 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -20954,6 +20954,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/j+k/kt60580.kt"); } + @Test + @TestMetadata("kt62197.kt") + public void testKt62197() throws Exception { + runTest("compiler/testData/diagnostics/tests/j+k/kt62197.kt"); + } + @Test @TestMetadata("kt6720_abstractProperty.kt") public void testKt6720_abstractProperty() throws Exception {