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:
committed by
TeamCityServer
parent
6a78e0a10c
commit
4aeabb6b0f
+5
-2
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.backend.jvm
|
||||
import org.jetbrains.kotlin.backend.common.ir.createImplicitParameterDeclarationWithWrappedDescriptor
|
||||
import org.jetbrains.kotlin.backend.common.ir.createParameterDeclarations
|
||||
import org.jetbrains.kotlin.codegen.JvmSamTypeFactory
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.FilteredAnnotations
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
@@ -59,8 +60,10 @@ open class JvmGeneratorExtensionsImpl(private val generateFacades: Boolean = tru
|
||||
override fun isPlatformSamType(type: KotlinType): Boolean =
|
||||
JavaSingleAbstractMethodUtils.isSamType(type)
|
||||
|
||||
override fun getSamTypeForValueParameter(valueParameter: ValueParameterDescriptor): KotlinType? =
|
||||
JvmSamTypeFactory.createByValueParameter(valueParameter)?.type
|
||||
override fun getSamTypeForValueParameter(
|
||||
valueParameter: ValueParameterDescriptor,
|
||||
languageVersionSettings: LanguageVersionSettings
|
||||
): KotlinType? = JvmSamTypeFactory.createByValueParameter(valueParameter, languageVersionSettings)?.type
|
||||
|
||||
companion object Instance : JvmSamConversion()
|
||||
}
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
|
||||
+5
-2
@@ -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()
|
||||
}
|
||||
|
||||
@@ -176,6 +176,8 @@ interface IrTypeSystemContext : TypeSystemContext, TypeSystemCommonSuperTypesCon
|
||||
|
||||
override fun TypeParameterMarker.getUpperBound(index: Int) = getSuperTypes(this)[index] as KotlinTypeMarker
|
||||
|
||||
override fun TypeParameterMarker.getUpperBounds() = getSuperTypes(this) as List<KotlinTypeMarker>
|
||||
|
||||
override fun TypeParameterMarker.getTypeConstructor() = this as IrTypeParameterSymbol
|
||||
|
||||
private fun KotlinTypeMarker.containsTypeConstructor(constructor: TypeConstructorMarker): Boolean {
|
||||
|
||||
Reference in New Issue
Block a user