[FIR] Properly handle declarations from other source sessions in FirPredicateBasedProvider

^KT-57083 Fixed
This commit is contained in:
Dmitriy Novozhilov
2023-03-16 14:19:55 +02:00
committed by Space Team
parent 644391a8e0
commit 507ef3e951
4 changed files with 41 additions and 0 deletions
@@ -90,6 +90,14 @@ class FirPredicateBasedProviderImpl(private val session: FirSession) : FirPredic
// ---------------------------------- Matching ----------------------------------
override fun matches(predicate: AbstractPredicate<*>, declaration: FirDeclaration): Boolean {
/*
* If declaration came from the other source session we should delegate to provider from
* that session, because it stores all caches about its own declarations
*/
val declarationSession = declaration.moduleData.session
if (declarationSession.kind == FirSession.Kind.Source && declarationSession !== session) {
return declarationSession.predicateBasedProvider.matches(predicate, declaration)
}
return when (predicate) {
is DeclarationPredicate -> predicate.accept(declarationPredicateMatcher, declaration)
is LookupPredicate -> predicate.accept(lookupPredicateMatcher, declaration)
@@ -0,0 +1,21 @@
// FIR_DISABLE_LAZY_RESOLVE_CHECKS
// FIR_IDENTICAL
// WITH_STDLIB
// ISSUE: KT-57083
// MODULE: lib
// FILE: libtest.kt
import kotlinx.serialization.*
@Serializable
class Access(val message: String)
// MODULE: main(lib)
// FILE: test.kt
import kotlinx.serialization.*
import kotlinx.serialization.json.*
@Serializable
class Usage(val access: Access)
@@ -134,6 +134,12 @@ public class SerializationFirPsiDiagnosticTestGenerated extends AbstractSerializ
runTest("plugins/kotlinx-serialization/testData/diagnostics/SerializableIgnored.kt");
}
@Test
@TestMetadata("serializerFromOtherModule.kt")
public void testSerializerFromOtherModule() throws Exception {
runTest("plugins/kotlinx-serialization/testData/diagnostics/serializerFromOtherModule.kt");
}
@Test
@TestMetadata("SerializerTypeCompatibleForSpecials.kt")
public void testSerializerTypeCompatibleForSpecials() throws Exception {
@@ -132,6 +132,12 @@ public class SerializationPluginDiagnosticTestGenerated extends AbstractSerializ
runTest("plugins/kotlinx-serialization/testData/diagnostics/SerializableIgnored.kt");
}
@Test
@TestMetadata("serializerFromOtherModule.kt")
public void testSerializerFromOtherModule() throws Exception {
runTest("plugins/kotlinx-serialization/testData/diagnostics/serializerFromOtherModule.kt");
}
@Test
@TestMetadata("SerializerTypeCompatibleForSpecials.kt")
public void testSerializerTypeCompatibleForSpecials() throws Exception {