[MPP] Fix false positive expect-actual mismatch

Use type refiner to correctly expand actual type alias - expect
class chains, produced by the commonizer. In a case when type
refiner doesn't exist for module create a one-shot thread local
instance. This might happen with modules without source code
in project (coming from build system model).

^KT-46691 Fixed
This commit is contained in:
Pavel Kirpichenkov
2021-07-16 16:36:49 +03:00
committed by teamcityserver
parent 2d91917ac7
commit 19467861c9
2 changed files with 81 additions and 22 deletions
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.resolve.descriptorUtil.classId
import org.jetbrains.kotlin.resolve.descriptorUtil.module
import org.jetbrains.kotlin.resolve.scopes.MemberScope
import org.jetbrains.kotlin.storage.LockBasedStorageManager
import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner
import org.jetbrains.kotlin.types.checker.NewCapturedTypeConstructor
@@ -24,8 +25,20 @@ class KotlinTypeRefinerImpl(
private val moduleDescriptor: ModuleDescriptor,
storageManager: StorageManager
) : KotlinTypeRefiner() {
private var isStandalone: Boolean = false
private constructor(
moduleDescriptor: ModuleDescriptor,
storageManager: StorageManager,
isStandalone: Boolean
) : this(moduleDescriptor, storageManager) {
this.isStandalone = isStandalone
}
init {
moduleDescriptor.getCapability(REFINER_CAPABILITY)?.value = TypeRefinementSupport.Enabled(this)
if (!isStandalone) {
moduleDescriptor.getCapability(REFINER_CAPABILITY)?.value = TypeRefinementSupport.Enabled(this)
}
}
private val refinedTypeCache = storageManager.createCacheWithNotNullValues<TypeConstructor, KotlinType>()
@@ -148,6 +161,15 @@ class KotlinTypeRefinerImpl(
return result
}
companion object {
/**
* Create a new *thread unsafe* type refiner instance for the specified module.
* Note, that module's type refiner capability won't be changed.
*/
fun createStandaloneInstanceFor(moduleDescriptor: ModuleDescriptor): KotlinTypeRefinerImpl =
KotlinTypeRefinerImpl(moduleDescriptor, LockBasedStorageManager.NO_LOCKS, isStandalone = true)
}
}
private val TypeConstructor.allDependentTypeConstructors: Collection<TypeConstructor>