K2 ignore return type on special java funs overrides
#KT-62197 fixed
This commit is contained in:
+6
@@ -20954,6 +20954,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
|||||||
runTest("compiler/testData/diagnostics/tests/j+k/kt60580.kt");
|
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
|
@Test
|
||||||
@TestMetadata("kt6720_abstractProperty.kt")
|
@TestMetadata("kt6720_abstractProperty.kt")
|
||||||
public void testKt6720_abstractProperty() throws Exception {
|
public void testKt6720_abstractProperty() throws Exception {
|
||||||
|
|||||||
+6
@@ -20954,6 +20954,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
|||||||
runTest("compiler/testData/diagnostics/tests/j+k/kt60580.kt");
|
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
|
@Test
|
||||||
@TestMetadata("kt6720_abstractProperty.kt")
|
@TestMetadata("kt6720_abstractProperty.kt")
|
||||||
public void testKt6720_abstractProperty() throws Exception {
|
public void testKt6720_abstractProperty() throws Exception {
|
||||||
|
|||||||
+6
@@ -20948,6 +20948,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
|||||||
runTest("compiler/testData/diagnostics/tests/j+k/kt60580.kt");
|
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
|
@Test
|
||||||
@TestMetadata("kt6720_abstractProperty.kt")
|
@TestMetadata("kt6720_abstractProperty.kt")
|
||||||
public void testKt6720_abstractProperty() throws Exception {
|
public void testKt6720_abstractProperty() throws Exception {
|
||||||
|
|||||||
+6
@@ -20954,6 +20954,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
|||||||
runTest("compiler/testData/diagnostics/tests/j+k/kt60580.kt");
|
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
|
@Test
|
||||||
@TestMetadata("kt6720_abstractProperty.kt")
|
@TestMetadata("kt6720_abstractProperty.kt")
|
||||||
public void testKt6720_abstractProperty() throws Exception {
|
public void testKt6720_abstractProperty() throws Exception {
|
||||||
|
|||||||
+8
-1
@@ -393,12 +393,19 @@ class JavaClassUseSiteMemberScope(
|
|||||||
destination: MutableCollection<FirNamedFunctionSymbol>
|
destination: MutableCollection<FirNamedFunctionSymbol>
|
||||||
) {
|
) {
|
||||||
val resultsOfIntersectionToSaveInCache = mutableListOf<ResultOfIntersection<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 =
|
val intersectionResults =
|
||||||
supertypeScopeContext.convertGroupedCallablesToIntersectionResults(functionsFromSupertypesWithRequestedName)
|
supertypeScopeContext.convertGroupedCallablesToIntersectionResults(functionsFromSupertypesWithRequestedName)
|
||||||
for (resultOfIntersectionWithNaturalName in intersectionResults) {
|
for (resultOfIntersectionWithNaturalName in intersectionResults) {
|
||||||
val someSymbolWithNaturalNameFromSuperType = resultOfIntersectionWithNaturalName.extractSomeSymbolFromSuperType()
|
val someSymbolWithNaturalNameFromSuperType = resultOfIntersectionWithNaturalName.extractSomeSymbolFromSuperType()
|
||||||
val explicitlyDeclaredFunctionWithNaturalName = explicitlyDeclaredFunctionsWithNaturalName.firstOrNull {
|
val explicitlyDeclaredFunctionWithNaturalName = explicitlyDeclaredFunctionsWithNaturalName.firstOrNull {
|
||||||
overrideChecker.isOverriddenFunction(it, someSymbolWithNaturalNameFromSuperType)
|
overrideCheckerForSpecialFunctions.isOverriddenFunction(it, someSymbolWithNaturalNameFromSuperType)
|
||||||
}
|
}
|
||||||
val jvmName = resultOfIntersectionWithNaturalName.overriddenMembers.firstNotNullOfOrNull {
|
val jvmName = resultOfIntersectionWithNaturalName.overriddenMembers.firstNotNullOfOrNull {
|
||||||
it.member.getJvmMethodNameIfSpecial(it.baseScope, session)
|
it.member.getJvmMethodNameIfSpecial(it.baseScope, session)
|
||||||
|
|||||||
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
Generated
+6
@@ -20954,6 +20954,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
|||||||
runTest("compiler/testData/diagnostics/tests/j+k/kt60580.kt");
|
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
|
@Test
|
||||||
@TestMetadata("kt6720_abstractProperty.kt")
|
@TestMetadata("kt6720_abstractProperty.kt")
|
||||||
public void testKt6720_abstractProperty() throws Exception {
|
public void testKt6720_abstractProperty() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user