[serialization] permit multiple occurrences of lazy function in sources

IDEA projects may have duplicate dependencies on kotlin stdlib. In that case, `IrPluginContext.referenceFunctions` may return more than one copy of each standard function, including three overloads of `kotlin.lazy`. And here's when serialization plugin may fail with an exception.

 It affects Kotlin debugger -- if such a project or module also has serialization plugin enabled, then it completely breaks new evaluation, meaning it's impossible to compute any expression.

Fixes IDEA-314785

Merge-request: KT-MR-10262
Merged-by: Alexander Kuznetsov <Aleksander.Kuznetsov@jetbrains.com>
This commit is contained in:
Aleksander Kuznetsov
2023-06-06 12:43:25 +00:00
committed by Space Team
parent 65aa5fc02e
commit 53c488079f
@@ -71,8 +71,11 @@ class SerializationPluginContext(baseContext: IrPluginContext, val metadataPlugi
internal val lazyModeClass = referenceClass(ClassId.topLevel(SerializationDependencies.LAZY_MODE_FQ))!!.owner
internal val lazyModePublicationEnumEntry =
lazyModeClass.enumEntries().single { it.name == SerializationDependencies.LAZY_PUBLICATION_MODE_NAME }
// There can be several transitive dependencies on kotlin-stdlib in IDE sources,
// as well as several definitions of stdlib functions, including `kotlin.lazy`;
// in that case `referenceFunctions` might return more than one valid definition of the same function.
internal val lazyFunctionSymbol =
referenceFunctions(CallableId(StandardNames.BUILT_INS_PACKAGE_FQ_NAME, Name.identifier("lazy"))).single {
referenceFunctions(CallableId(StandardNames.BUILT_INS_PACKAGE_FQ_NAME, Name.identifier("lazy"))).first {
it.owner.valueParameters.size == 2 && it.owner.valueParameters[0].type == lazyModeClass.defaultType
}
internal val lazyClass = referenceClass(ClassId.topLevel(SerializationDependencies.LAZY_FQ))!!.owner