K2: generate Java synthetics for Kotlin get/sets w/out type parameters

This commit is a follow-up to d8a20f19 and
provides additional K1 compatibility.
#KT-59550 Fixed
This commit is contained in:
Mikhail Glukhikh
2023-06-21 16:55:29 +02:00
parent 08a355756a
commit 0d8f3a6026
7 changed files with 61 additions and 3 deletions
@@ -18671,6 +18671,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
runTest("compiler/testData/codegen/box/fir/syntheticPropertyThroughJavaMultiModule.kt");
}
@Test
@TestMetadata("syntheticPropertyThroughJavaWithSetter.kt")
public void testSyntheticPropertyThroughJavaWithSetter() throws Exception {
runTest("compiler/testData/codegen/box/fir/syntheticPropertyThroughJavaWithSetter.kt");
}
@Test
@TestMetadata("toLong.kt")
public void testToLong() throws Exception {
@@ -18671,6 +18671,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
runTest("compiler/testData/codegen/box/fir/syntheticPropertyThroughJavaMultiModule.kt");
}
@Test
@TestMetadata("syntheticPropertyThroughJavaWithSetter.kt")
public void testSyntheticPropertyThroughJavaWithSetter() throws Exception {
runTest("compiler/testData/codegen/box/fir/syntheticPropertyThroughJavaWithSetter.kt");
}
@Test
@TestMetadata("toLong.kt")
public void testToLong() throws Exception {
@@ -196,7 +196,7 @@ class JavaClassUseSiteMemberScope(
candidateSymbol.takeIf {
when {
candidate.isJavaOrEnhancement ->
candidate.isAcceptableAsAccessorOverride() ->
// TODO: Decide something for the case when property type is not computed yet
expectedReturnType == null ||
AbstractTypeChecker.isSubtypeOf(session.typeContext, candidateReturnType, expectedReturnType)
@@ -220,11 +220,20 @@ class JavaClassUseSiteMemberScope(
candidate.valueParameters.single().returnTypeRef.toConeKotlinTypeProbablyFlexible(session, typeParameterStack)
candidateSymbol.takeIf {
candidate.isJavaOrEnhancement && AbstractTypeChecker.equalTypes(session.typeContext, parameterType, propertyType)
candidate.isAcceptableAsAccessorOverride() && AbstractTypeChecker.equalTypes(
session.typeContext, parameterType, propertyType
)
}
}
}
private fun FirSimpleFunction.isAcceptableAsAccessorOverride(): Boolean {
// We don't accept here accessors with type parameters from Kotlin to avoid strange cases like KT-59038
// However, we (temporarily, see below) accept accessors from Kotlin in general to keep K1 compatibility in cases like KT-59550
// KT-59601: we are going to forbid accessors from Kotlin in general after some investigation and/or deprecation period
return isJavaOrEnhancement || typeParameters.isEmpty()
}
private fun FirPropertySymbol.getBuiltinSpecialPropertyGetterName(): Name? {
var result: Name? = null
superTypeScopes.processOverriddenPropertiesAndSelf(this) { overridden ->
@@ -1,5 +1,4 @@
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K2: JVM_IR
// ISSUE: KT-59550
// FILE: Intermediate.java
@@ -0,0 +1,26 @@
// TARGET_BACKEND: JVM_IR
// ISSUE: KT-59550
// FILE: Intermediate.java
public class Intermediate extends Base {
public Intermediate(String foo) {
super(foo);
}
}
// FILE: FinalAndBase.kt
abstract class Base(private var foo: String) {
fun getFoo() = foo
fun setFoo(newFoo: String) {
foo = newFoo
}
}
class Final(val i: Intermediate) : Intermediate(i.foo)
fun box(): String {
val f = Final(Intermediate(""))
f.foo = "OK"
return f.foo
}
@@ -18671,6 +18671,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/fir/syntheticPropertyThroughJavaMultiModule.kt");
}
@Test
@TestMetadata("syntheticPropertyThroughJavaWithSetter.kt")
public void testSyntheticPropertyThroughJavaWithSetter() throws Exception {
runTest("compiler/testData/codegen/box/fir/syntheticPropertyThroughJavaWithSetter.kt");
}
@Test
@TestMetadata("toLong.kt")
public void testToLong() throws Exception {
@@ -18671,6 +18671,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack
runTest("compiler/testData/codegen/box/fir/syntheticPropertyThroughJavaMultiModule.kt");
}
@Test
@TestMetadata("syntheticPropertyThroughJavaWithSetter.kt")
public void testSyntheticPropertyThroughJavaWithSetter() throws Exception {
runTest("compiler/testData/codegen/box/fir/syntheticPropertyThroughJavaWithSetter.kt");
}
@Test
@TestMetadata("toLong.kt")
public void testToLong() throws Exception {