[FIR] Fix exception in Java scope caused by inherited member with implicit return type

It's caused by checking the return type of an inherited property.
toConeKotlinTypeProbablyFlexible() returns an error type when the
type ref is unresolved instead of throwing.
This "breaks" some override checks and in the added test, it leads
to an additional candidate being created for a synthetic property.
However, the candidate has applicability K2_SYNTHETIC_RESOLVED
and gets filtered out because the real property has a higher
applicability.

#KT-66392 Fixed
This commit is contained in:
Kirill Rakhman
2024-03-14 15:23:19 +01:00
committed by Space Team
parent 8f420eb3e1
commit 2095f90e69
9 changed files with 69 additions and 6 deletions
@@ -21984,6 +21984,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
runTest("compiler/testData/diagnostics/tests/j+k/kjkRawTypeWithKotlinUpperBound.kt"); runTest("compiler/testData/diagnostics/tests/j+k/kjkRawTypeWithKotlinUpperBound.kt");
} }
@Test
@TestMetadata("kjkimplicitTypesCrash.kt")
public void testKjkimplicitTypesCrash() {
runTest("compiler/testData/diagnostics/tests/j+k/kjkimplicitTypesCrash.kt");
}
@Test @Test
@TestMetadata("kt1402.kt") @TestMetadata("kt1402.kt")
public void testKt1402() { public void testKt1402() {
@@ -21984,6 +21984,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
runTest("compiler/testData/diagnostics/tests/j+k/kjkRawTypeWithKotlinUpperBound.kt"); runTest("compiler/testData/diagnostics/tests/j+k/kjkRawTypeWithKotlinUpperBound.kt");
} }
@Test
@TestMetadata("kjkimplicitTypesCrash.kt")
public void testKjkimplicitTypesCrash() {
runTest("compiler/testData/diagnostics/tests/j+k/kjkimplicitTypesCrash.kt");
}
@Test @Test
@TestMetadata("kt1402.kt") @TestMetadata("kt1402.kt")
public void testKt1402() { public void testKt1402() {
@@ -21978,6 +21978,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
runTest("compiler/testData/diagnostics/tests/j+k/kjkRawTypeWithKotlinUpperBound.kt"); runTest("compiler/testData/diagnostics/tests/j+k/kjkRawTypeWithKotlinUpperBound.kt");
} }
@Test
@TestMetadata("kjkimplicitTypesCrash.kt")
public void testKjkimplicitTypesCrash() {
runTest("compiler/testData/diagnostics/tests/j+k/kjkimplicitTypesCrash.kt");
}
@Test @Test
@TestMetadata("kt1402.kt") @TestMetadata("kt1402.kt")
public void testKt1402() { public void testKt1402() {
@@ -21984,6 +21984,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
runTest("compiler/testData/diagnostics/tests/j+k/kjkRawTypeWithKotlinUpperBound.kt"); runTest("compiler/testData/diagnostics/tests/j+k/kjkRawTypeWithKotlinUpperBound.kt");
} }
@Test
@TestMetadata("kjkimplicitTypesCrash.kt")
public void testKjkimplicitTypesCrash() {
runTest("compiler/testData/diagnostics/tests/j+k/kjkimplicitTypesCrash.kt");
}
@Test @Test
@TestMetadata("kt1402.kt") @TestMetadata("kt1402.kt")
public void testKt1402() { public void testKt1402() {
@@ -18,6 +18,8 @@ import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertySetter
import org.jetbrains.kotlin.fir.declarations.synthetic.FirSyntheticProperty import org.jetbrains.kotlin.fir.declarations.synthetic.FirSyntheticProperty
import org.jetbrains.kotlin.fir.declarations.synthetic.buildSyntheticProperty import org.jetbrains.kotlin.fir.declarations.synthetic.buildSyntheticProperty
import org.jetbrains.kotlin.fir.declarations.utils.* import org.jetbrains.kotlin.fir.declarations.utils.*
import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic
import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind
import org.jetbrains.kotlin.fir.java.SyntheticPropertiesCacheKey import org.jetbrains.kotlin.fir.java.SyntheticPropertiesCacheKey
import org.jetbrains.kotlin.fir.java.declarations.FirJavaClass import org.jetbrains.kotlin.fir.java.declarations.FirJavaClass
import org.jetbrains.kotlin.fir.java.declarations.FirJavaMethod import org.jetbrains.kotlin.fir.java.declarations.FirJavaMethod
@@ -890,10 +892,7 @@ class JavaClassUseSiteMemberScope(
} }
private fun FirTypeRef.probablyJavaTypeRefToConeType(): ConeKotlinType { private fun FirTypeRef.probablyJavaTypeRefToConeType(): ConeKotlinType {
return when (this) { return toConeKotlinTypeProbablyFlexible(session, typeParameterStack)
is FirJavaTypeRef -> toConeKotlinTypeProbablyFlexible(session, typeParameterStack)
else -> coneType
}
} }
// It's either overrides Collection.contains(Object) or Collection.containsAll(Collection<?>) or similar methods // It's either overrides Collection.contains(Object) or Collection.containsAll(Collection<?>) or similar methods
@@ -1,7 +1,5 @@
// FIR_IDENTICAL // FIR_IDENTICAL
// ISSUE: KT-66048 // ISSUE: KT-66048
// IGNORE_REVERSED_RESOLVE
// ^KT-66392
// FILE: Java1.java // FILE: Java1.java
public class Java1 extends KotlinClass { public class Java1 extends KotlinClass {
@@ -0,0 +1,18 @@
// ISSUE: KT-66392
// FILE: Java1.java
public class Java1 extends KotlinClass {
@Override
public String getE() {
return "2";
}
}
// FILE: test.kt
// The order of Kotlin classes is important
class B : Java1() {
override var e = super.e
}
open class KotlinClass {
open var e = "1"
}
@@ -0,0 +1,18 @@
// ISSUE: KT-66392
// FILE: Java1.java
public class Java1 extends KotlinClass {
@Override
public String getE() {
return "2";
}
}
// FILE: test.kt
// The order of Kotlin classes is important
class B : Java1() {
<!ACCIDENTAL_OVERRIDE!>override var e<!> = super.e
}
open class KotlinClass {
open var e = "1"
}
@@ -21984,6 +21984,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/j+k/kjkRawTypeWithKotlinUpperBound.kt"); runTest("compiler/testData/diagnostics/tests/j+k/kjkRawTypeWithKotlinUpperBound.kt");
} }
@Test
@TestMetadata("kjkimplicitTypesCrash.kt")
public void testKjkimplicitTypesCrash() {
runTest("compiler/testData/diagnostics/tests/j+k/kjkimplicitTypesCrash.kt");
}
@Test @Test
@TestMetadata("kt1402.kt") @TestMetadata("kt1402.kt")
public void testKt1402() { public void testKt1402() {