FIR: use default getter in serializer if fir contains none
since we generate the default getter in this case in Fir2IrDeclarationStorage.createIrProperty, so the serialized metadata should follow the same behavior. #KT-57373 fixed
This commit is contained in:
committed by
Space Team
parent
913b55174d
commit
a045a0a81c
+18
-2
@@ -18,6 +18,8 @@ import org.jetbrains.kotlin.fir.*
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.comparators.FirCallableDeclarationComparator
|
||||
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyAccessor
|
||||
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyGetter
|
||||
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertySetter
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.*
|
||||
import org.jetbrains.kotlin.fir.deserialization.projection
|
||||
import org.jetbrains.kotlin.fir.expressions.*
|
||||
@@ -341,7 +343,14 @@ class FirElementSerializer private constructor(
|
||||
false, false, false
|
||||
)
|
||||
|
||||
val getter = property.getter
|
||||
val getter = property.getter ?: with(property) {
|
||||
if (origin == FirDeclarationOrigin.Delegated) {
|
||||
// since we generate the default accessor on fir2ir anyway (Fir2IrDeclarationStorage.createIrProperty), we have to
|
||||
// serialize it accordingly at least for delegates to fix issues like #KT-57373
|
||||
// TODO: rewrite accordingly after fixing #KT-58233
|
||||
FirDefaultPropertyGetter(source = null, moduleData, origin, returnTypeRef, visibility, symbol)
|
||||
} else null
|
||||
}
|
||||
if (getter != null) {
|
||||
hasGetter = true
|
||||
val accessorFlags = getAccessorFlags(getter, property)
|
||||
@@ -350,7 +359,14 @@ class FirElementSerializer private constructor(
|
||||
}
|
||||
}
|
||||
|
||||
val setter = property.setter
|
||||
val setter = property.setter ?: with(property) {
|
||||
if (origin == FirDeclarationOrigin.Delegated && isVar) {
|
||||
// since we generate the default accessor on fir2ir anyway (Fir2IrDeclarationStorage.createIrProperty), we have to
|
||||
// serialize it accordingly at least for delegates to fix issues like #KT-57373
|
||||
// TODO: rewrite accordingly after fixing #KT-58233
|
||||
FirDefaultPropertySetter(source = null, moduleData, origin, returnTypeRef, visibility, symbol)
|
||||
} else null
|
||||
}
|
||||
if (setter != null) {
|
||||
hasSetter = true
|
||||
val accessorFlags = getAccessorFlags(setter, property)
|
||||
|
||||
+6
@@ -15709,6 +15709,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
|
||||
runTest("compiler/testData/codegen/box/delegation/delegationDifferentModule.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("delegationDifferentModule2.kt")
|
||||
public void testDelegationDifferentModule2() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegation/delegationDifferentModule2.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("delegationToIntersectionType.kt")
|
||||
public void testDelegationToIntersectionType() throws Exception {
|
||||
|
||||
+6
@@ -15709,6 +15709,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
|
||||
runTest("compiler/testData/codegen/box/delegation/delegationDifferentModule.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("delegationDifferentModule2.kt")
|
||||
public void testDelegationDifferentModule2() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegation/delegationDifferentModule2.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("delegationToIntersectionType.kt")
|
||||
public void testDelegationToIntersectionType() throws Exception {
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
// MODULE: lib
|
||||
// FILE: lib.kt
|
||||
|
||||
interface I {
|
||||
val bar: Int
|
||||
}
|
||||
|
||||
class Impl : I {
|
||||
override val bar: Int = 42
|
||||
}
|
||||
|
||||
class D1(foo: I) : I by foo
|
||||
|
||||
// MODULE: main(lib)
|
||||
// FILE: main.kt
|
||||
|
||||
class D2(foo: I) : I by foo
|
||||
|
||||
fun box() : String {
|
||||
val c = Impl()
|
||||
if (D1(c).bar != 42) return "FAIL 1"
|
||||
if (D2(c).bar != 42) return "FAIL 2"
|
||||
return "OK"
|
||||
}
|
||||
+6
@@ -15373,6 +15373,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/delegation/delegationDifferentModule.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("delegationDifferentModule2.kt")
|
||||
public void testDelegationDifferentModule2() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegation/delegationDifferentModule2.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("delegationToIntersectionType.kt")
|
||||
public void testDelegationToIntersectionType() throws Exception {
|
||||
|
||||
+6
@@ -15709,6 +15709,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/delegation/delegationDifferentModule.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("delegationDifferentModule2.kt")
|
||||
public void testDelegationDifferentModule2() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegation/delegationDifferentModule2.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("delegationToIntersectionType.kt")
|
||||
public void testDelegationToIntersectionType() throws Exception {
|
||||
|
||||
+6
@@ -15709,6 +15709,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack
|
||||
runTest("compiler/testData/codegen/box/delegation/delegationDifferentModule.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("delegationDifferentModule2.kt")
|
||||
public void testDelegationDifferentModule2() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegation/delegationDifferentModule2.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("delegationToIntersectionType.kt")
|
||||
public void testDelegationToIntersectionType() throws Exception {
|
||||
|
||||
+5
@@ -12630,6 +12630,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/delegation/delegationDifferentModule.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("delegationDifferentModule2.kt")
|
||||
public void testDelegationDifferentModule2() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegation/delegationDifferentModule2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("delegationToIntersectionType.kt")
|
||||
public void testDelegationToIntersectionType() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegation/delegationToIntersectionType.kt");
|
||||
|
||||
Reference in New Issue
Block a user