K2 ignore return type on special java funs overrides

#KT-62197 fixed
This commit is contained in:
Ilya Chernikov
2023-11-03 16:44:16 +01:00
parent 312187dbe6
commit 122f16fc18
7 changed files with 73 additions and 1 deletions
@@ -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 {
@@ -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 {
@@ -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 {
@@ -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 {
@@ -393,12 +393,19 @@ class JavaClassUseSiteMemberScope(
destination: MutableCollection<FirNamedFunctionSymbol>
) {
val resultsOfIntersectionToSaveInCache = mutableListOf<ResultOfIntersection<FirNamedFunctionSymbol>>()
// 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)
+35
View File
@@ -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();
}
}
@@ -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 {