Use upper bound aware type approximator for intersection types inside sam types in contravariant positions to build proper types in terms of subtyping

This commit is contained in:
Victor Petukhov
2021-06-16 18:55:03 +03:00
committed by TeamCityServer
parent 6a78e0a10c
commit 4aeabb6b0f
21 changed files with 424 additions and 18 deletions
@@ -585,7 +585,7 @@ fun StatementGenerator.generateSamConversionForValueArgumentsIfRequired(call: Ca
if (!originalValueParameters[i].type.isFunctionTypeOrSubtype) continue
}
val samKotlinType = samConversion.getSamTypeForValueParameter(underlyingValueParameter)
val samKotlinType = samConversion.getSamTypeForValueParameter(underlyingValueParameter, context.languageVersionSettings)
?: underlyingValueParameter.varargElementType // If we have a vararg, vararg element type will be taken
?: underlyingValueParameter.type
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.psi.KtPureClassOrObject
import org.jetbrains.kotlin.resolve.scopes.MemberScope
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.backend.common.SamTypeFactory
import org.jetbrains.kotlin.config.LanguageVersionSettings
open class GeneratorExtensions : StubGeneratorExtensions() {
open val samConversion: SamConversion
@@ -24,8 +25,10 @@ open class GeneratorExtensions : StubGeneratorExtensions() {
open class SamConversion {
open fun isPlatformSamType(type: KotlinType): Boolean = false
open fun getSamTypeForValueParameter(valueParameter: ValueParameterDescriptor): KotlinType? =
SamTypeFactory.INSTANCE.createByValueParameter(valueParameter)?.type
open fun getSamTypeForValueParameter(
valueParameter: ValueParameterDescriptor,
languageVersionSettings: LanguageVersionSettings
): KotlinType? = SamTypeFactory.INSTANCE.createByValueParameter(valueParameter, languageVersionSettings)?.type
companion object Instance : SamConversion()
}