[FIR] Don't create generated nested classifier scope for non-source classes

^KT-57626 Fixed
This commit is contained in:
Dmitriy Novozhilov
2023-03-28 14:10:05 +03:00
committed by Space Team
parent ea6651445c
commit fb97f4db87
4 changed files with 42 additions and 2 deletions
@@ -91,11 +91,14 @@ class FirDeclaredMemberScopeProvider(val useSiteSession: FirSession) : FirSessio
}
private fun createNestedClassifierScope(klass: FirClass): FirNestedClassifierScope? {
return if (klass.origin.generated) {
val origin = klass.origin
return if (origin.generated) {
FirGeneratedClassNestedClassifierScope.create(useSiteSession, klass, baseScope = null)
} else {
val baseScope = FirNestedClassifierScopeImpl(klass, useSiteSession)
val generatedScope = FirGeneratedClassNestedClassifierScope.create(useSiteSession, klass, baseScope)
val generatedScope = runIf(origin.fromSource) {
FirGeneratedClassNestedClassifierScope.create(useSiteSession, klass, baseScope)
}
if (generatedScope != null) {
FirCompositeNestedClassifierScope(
listOf(baseScope, generatedScope),
@@ -0,0 +1,25 @@
// TARGET_BACKEND: JVM_IR
// WITH_STDLIB
// ISSUE: KT-57626
// MODULE: lib
import kotlinx.serialization.*
@Serializable
data class A(val s: String = "")
// MODULE: main(lib)
import kotlinx.serialization.*
import kotlinx.serialization.json.*
@Serializable
data class B(val a: A? = null)
fun box(): String {
val expectedB = B(A("OK"))
val json = Json.encodeToString(B.serializer(), expectedB)
if (json != """{"a":{"s":"OK"}}""") return "Fail: $json"
val actualB = Json.decodeFromString(B.serializer(), json)
if (expectedB != actualB) return "Fail: $actualB"
return "OK"
}
@@ -177,6 +177,12 @@ public class SerializationFirLightTreeBlackBoxTestGenerated extends AbstractSeri
runTest("plugins/kotlinx-serialization/testData/boxIr/serialInfo.kt");
}
@Test
@TestMetadata("serializableFromAnotherModule.kt")
public void testSerializableFromAnotherModule() throws Exception {
runTest("plugins/kotlinx-serialization/testData/boxIr/serializableFromAnotherModule.kt");
}
@Test
@TestMetadata("serializableOnPropertyType.kt")
public void testSerializableOnPropertyType() throws Exception {
@@ -175,6 +175,12 @@ public class SerializationIrBoxTestGenerated extends AbstractSerializationIrBoxT
runTest("plugins/kotlinx-serialization/testData/boxIr/serialInfo.kt");
}
@Test
@TestMetadata("serializableFromAnotherModule.kt")
public void testSerializableFromAnotherModule() throws Exception {
runTest("plugins/kotlinx-serialization/testData/boxIr/serializableFromAnotherModule.kt");
}
@Test
@TestMetadata("serializableOnPropertyType.kt")
public void testSerializableOnPropertyType() throws Exception {