Fix failed tests
This commit is contained in:
committed by
Dmitriy Novozhilov
parent
3c4989b672
commit
a98e2c4e03
@@ -58,10 +58,10 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo
|
|||||||
arguments: List<TypeArgumentMarker>,
|
arguments: List<TypeArgumentMarker>,
|
||||||
nullable: Boolean,
|
nullable: Boolean,
|
||||||
isExtensionFunction: Boolean,
|
isExtensionFunction: Boolean,
|
||||||
annotations: List<AnnotationMarker>?
|
attributes: List<AnnotationMarker>?
|
||||||
): SimpleTypeMarker {
|
): SimpleTypeMarker {
|
||||||
val attributesList = annotations?.filterIsInstanceTo<ConeAttribute<*>, MutableList<ConeAttribute<*>>>(mutableListOf())
|
val attributesList = attributes?.filterIsInstanceTo<ConeAttribute<*>, MutableList<ConeAttribute<*>>>(mutableListOf())
|
||||||
val attributes: ConeAttributes = if (isExtensionFunction) {
|
val coneAttributes: ConeAttributes = if (isExtensionFunction) {
|
||||||
require(constructor is ConeClassLikeLookupTag && constructor.isBuiltinFunctionalType())
|
require(constructor is ConeClassLikeLookupTag && constructor.isBuiltinFunctionalType())
|
||||||
// We don't want to create new instance of ConeAttributes which
|
// We don't want to create new instance of ConeAttributes which
|
||||||
// contains only CompilerConeAttributes.ExtensionFunctionType
|
// contains only CompilerConeAttributes.ExtensionFunctionType
|
||||||
@@ -81,12 +81,12 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo
|
|||||||
constructor,
|
constructor,
|
||||||
(arguments as List<ConeTypeProjection>).toTypedArray(),
|
(arguments as List<ConeTypeProjection>).toTypedArray(),
|
||||||
nullable,
|
nullable,
|
||||||
attributes,
|
coneAttributes,
|
||||||
)
|
)
|
||||||
is ConeTypeParameterLookupTag -> ConeTypeParameterTypeImpl(
|
is ConeTypeParameterLookupTag -> ConeTypeParameterTypeImpl(
|
||||||
constructor,
|
constructor,
|
||||||
nullable,
|
nullable,
|
||||||
attributes
|
coneAttributes
|
||||||
)
|
)
|
||||||
else -> error("!")
|
else -> error("!")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -420,6 +420,12 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext, Ty
|
|||||||
return attributes.toList()
|
return attributes.toList()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun KotlinTypeMarker.hasCustomAttributes(): Boolean {
|
||||||
|
require(this is ConeKotlinType)
|
||||||
|
val compilerAttributes = CompilerConeAttributes.classIdByCompilerAttribute
|
||||||
|
return this.attributes.any { it !in compilerAttributes && it !is CustomAnnotationTypeAttribute }
|
||||||
|
}
|
||||||
|
|
||||||
override fun KotlinTypeMarker.getCustomAttributes(): List<AnnotationMarker> {
|
override fun KotlinTypeMarker.getCustomAttributes(): List<AnnotationMarker> {
|
||||||
require(this is ConeKotlinType)
|
require(this is ConeKotlinType)
|
||||||
val compilerAttributes = CompilerConeAttributes.classIdByCompilerAttribute
|
val compilerAttributes = CompilerConeAttributes.classIdByCompilerAttribute
|
||||||
|
|||||||
+2
-2
@@ -145,7 +145,7 @@ class PassingProgressionAsCollectionCallChecker(private val kotlinCallResolver:
|
|||||||
|
|
||||||
private fun makeCollectionOfAnyType(builtIns: KotlinBuiltIns): KotlinType =
|
private fun makeCollectionOfAnyType(builtIns: KotlinBuiltIns): KotlinType =
|
||||||
KotlinTypeFactory.simpleNotNullType(
|
KotlinTypeFactory.simpleNotNullType(
|
||||||
Annotations.EMPTY,
|
TypeAttributes.Empty,
|
||||||
builtIns.collection,
|
builtIns.collection,
|
||||||
listOf(TypeProjectionImpl(builtIns.nullableAnyType))
|
listOf(TypeProjectionImpl(builtIns.nullableAnyType))
|
||||||
)
|
)
|
||||||
@@ -162,7 +162,7 @@ class PassingProgressionAsCollectionCallChecker(private val kotlinCallResolver:
|
|||||||
val newType = intersectTypes(
|
val newType = intersectTypes(
|
||||||
listOf(
|
listOf(
|
||||||
KotlinTypeFactory.simpleNotNullType(
|
KotlinTypeFactory.simpleNotNullType(
|
||||||
Annotations.EMPTY,
|
TypeAttributes.Empty,
|
||||||
builtIns.collection,
|
builtIns.collection,
|
||||||
listOf(TypeProjectionImpl(progressionOrRangeElementType))
|
listOf(TypeProjectionImpl(progressionOrRangeElementType))
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -332,10 +332,10 @@ interface IrTypeSystemContext : TypeSystemContext, TypeSystemCommonSuperTypesCon
|
|||||||
arguments: List<TypeArgumentMarker>,
|
arguments: List<TypeArgumentMarker>,
|
||||||
nullable: Boolean,
|
nullable: Boolean,
|
||||||
isExtensionFunction: Boolean,
|
isExtensionFunction: Boolean,
|
||||||
annotations: List<AnnotationMarker>?
|
attributes: List<AnnotationMarker>?
|
||||||
): SimpleTypeMarker {
|
): SimpleTypeMarker {
|
||||||
val ourAnnotations = annotations?.filterIsInstance<IrConstructorCall>()
|
val ourAnnotations = attributes?.filterIsInstance<IrConstructorCall>()
|
||||||
require(ourAnnotations?.size == annotations?.size)
|
require(ourAnnotations?.size == attributes?.size)
|
||||||
return IrSimpleTypeImpl(
|
return IrSimpleTypeImpl(
|
||||||
constructor as IrClassifierSymbol,
|
constructor as IrClassifierSymbol,
|
||||||
nullable,
|
nullable,
|
||||||
@@ -406,6 +406,10 @@ interface IrTypeSystemContext : TypeSystemContext, TypeSystemCommonSuperTypesCon
|
|||||||
return this.annotations.map { object : AnnotationMarker, IrElement by it {} }
|
return this.annotations.map { object : AnnotationMarker, IrElement by it {} }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun KotlinTypeMarker.hasCustomAttributes(): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
override fun KotlinTypeMarker.getCustomAttributes(): List<AnnotationMarker> {
|
override fun KotlinTypeMarker.getCustomAttributes(): List<AnnotationMarker> {
|
||||||
require(this is IrType)
|
require(this is IrType)
|
||||||
return emptyList()
|
return emptyList()
|
||||||
|
|||||||
+1
-1
@@ -15,7 +15,7 @@ import org.jetbrains.kotlin.types.model.*
|
|||||||
object NewCommonSuperTypeCalculator {
|
object NewCommonSuperTypeCalculator {
|
||||||
fun TypeSystemCommonSuperTypesContext.commonSuperType(types: List<KotlinTypeMarker>): KotlinTypeMarker {
|
fun TypeSystemCommonSuperTypesContext.commonSuperType(types: List<KotlinTypeMarker>): KotlinTypeMarker {
|
||||||
val maxDepth = types.maxOfOrNull { it.typeDepth() } ?: 0
|
val maxDepth = types.maxOfOrNull { it.typeDepth() } ?: 0
|
||||||
return commonSuperType(types, -maxDepth, true).replaceTypeAttributes(unionTypeAttributes(types))
|
return commonSuperType(types, -maxDepth, true).let { it.replaceTypeAttributes(unionTypeAttributes(listOf(it) + types)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun TypeSystemCommonSuperTypesContext.commonSuperType(
|
private fun TypeSystemCommonSuperTypesContext.commonSuperType(
|
||||||
|
|||||||
+1
-1
@@ -411,7 +411,7 @@ class PostponedArgumentInputTypesResolver(
|
|||||||
argument.isFunctionExpressionWithReceiver() -> true
|
argument.isFunctionExpressionWithReceiver() -> true
|
||||||
else -> parameterTypesInfo.isExtensionFunction
|
else -> parameterTypesInfo.isExtensionFunction
|
||||||
},
|
},
|
||||||
annotations = parameterTypesInfo.annotations
|
attributes = parameterTypesInfo.annotations
|
||||||
)
|
)
|
||||||
|
|
||||||
getBuilder().addSubtypeConstraint(
|
getBuilder().addSubtypeConstraint(
|
||||||
|
|||||||
+10
-6
@@ -59,14 +59,18 @@ class MutableVariableWithConstraints private constructor(
|
|||||||
&& previousConstraint.type == constraint.type
|
&& previousConstraint.type == constraint.type
|
||||||
&& previousConstraint.isNullabilityConstraint == constraint.isNullabilityConstraint
|
&& previousConstraint.isNullabilityConstraint == constraint.isNullabilityConstraint
|
||||||
) {
|
) {
|
||||||
|
val noNewCustomAttributes = with(context) {
|
||||||
|
val previousType = previousConstraint.type
|
||||||
|
val type = constraint.type
|
||||||
|
(!previousType.hasCustomAttributes() && !type.hasCustomAttributes()) ||
|
||||||
|
(previousType.getCustomAttributes() == type.getCustomAttributes())
|
||||||
|
}
|
||||||
|
|
||||||
if (newConstraintIsUseless(previousConstraint, constraint)) {
|
if (newConstraintIsUseless(previousConstraint, constraint)) {
|
||||||
// Preserve constraints with different custom type attributes.
|
// Preserve constraints with different custom type attributes.
|
||||||
// This allows us to union type attributes in NewCommonSuperTypeCalculator.kt
|
// This allows us to union type attributes in NewCommonSuperTypeCalculator.kt
|
||||||
with(context) {
|
if (noNewCustomAttributes) {
|
||||||
val prevAttributes = previousConstraint.type.getCustomAttributes()
|
return previousConstraint to false
|
||||||
if (prevAttributes.isEmpty() || prevAttributes == constraint.type.getCustomAttributes()) {
|
|
||||||
return previousConstraint to false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,7 +79,7 @@ class MutableVariableWithConstraints private constructor(
|
|||||||
ConstraintKind.UPPER -> constraint.kind.isLower()
|
ConstraintKind.UPPER -> constraint.kind.isLower()
|
||||||
ConstraintKind.EQUALITY -> true
|
ConstraintKind.EQUALITY -> true
|
||||||
}
|
}
|
||||||
if (isMatchingForSimplification) {
|
if (isMatchingForSimplification && noNewCustomAttributes) {
|
||||||
val actualConstraint = if (constraint.kind != ConstraintKind.EQUALITY) {
|
val actualConstraint = if (constraint.kind != ConstraintKind.EQUALITY) {
|
||||||
Constraint(
|
Constraint(
|
||||||
ConstraintKind.EQUALITY,
|
ConstraintKind.EQUALITY,
|
||||||
|
|||||||
-1
@@ -6,7 +6,6 @@
|
|||||||
package org.jetbrains.kotlin.resolve.calls.inference.components
|
package org.jetbrains.kotlin.resolve.calls.inference.components
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.CompositeAnnotations
|
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.isCaptured
|
import org.jetbrains.kotlin.resolve.calls.inference.isCaptured
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.TypeVariableFromCallableDescriptor
|
import org.jetbrains.kotlin.resolve.calls.inference.model.TypeVariableFromCallableDescriptor
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.substitute
|
import org.jetbrains.kotlin.resolve.calls.inference.substitute
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ interface TypeSystemTypeFactoryContext: TypeSystemBuiltInsContext {
|
|||||||
arguments: List<TypeArgumentMarker>,
|
arguments: List<TypeArgumentMarker>,
|
||||||
nullable: Boolean,
|
nullable: Boolean,
|
||||||
isExtensionFunction: Boolean = false,
|
isExtensionFunction: Boolean = false,
|
||||||
annotations: List<AnnotationMarker>? = null
|
attributes: List<AnnotationMarker>? = null
|
||||||
): SimpleTypeMarker
|
): SimpleTypeMarker
|
||||||
|
|
||||||
fun createTypeArgument(type: KotlinTypeMarker, variance: TypeVariance): TypeArgumentMarker
|
fun createTypeArgument(type: KotlinTypeMarker, variance: TypeVariance): TypeArgumentMarker
|
||||||
@@ -500,6 +500,8 @@ interface TypeSystemContext : TypeSystemOptimizationContext {
|
|||||||
|
|
||||||
fun KotlinTypeMarker.getAttributes(): List<AnnotationMarker>
|
fun KotlinTypeMarker.getAttributes(): List<AnnotationMarker>
|
||||||
|
|
||||||
|
fun KotlinTypeMarker.hasCustomAttributes(): Boolean
|
||||||
|
|
||||||
fun KotlinTypeMarker.getCustomAttributes(): List<AnnotationMarker>
|
fun KotlinTypeMarker.getCustomAttributes(): List<AnnotationMarker>
|
||||||
|
|
||||||
fun substitutionSupertypePolicy(type: SimpleTypeMarker): TypeCheckerState.SupertypesPolicy
|
fun substitutionSupertypePolicy(type: SimpleTypeMarker): TypeCheckerState.SupertypesPolicy
|
||||||
|
|||||||
-3
@@ -78,9 +78,6 @@ class CapturedType(
|
|||||||
override val attributes: TypeAttributes = TypeAttributes.Empty
|
override val attributes: TypeAttributes = TypeAttributes.Empty
|
||||||
) : SimpleType(), SubtypingRepresentatives, CapturedTypeMarker {
|
) : SimpleType(), SubtypingRepresentatives, CapturedTypeMarker {
|
||||||
|
|
||||||
override val annotations: Annotations
|
|
||||||
get() = attributes.toDefaultAnnotations()
|
|
||||||
|
|
||||||
override val arguments: List<TypeProjection>
|
override val arguments: List<TypeProjection>
|
||||||
get() = listOf()
|
get() = listOf()
|
||||||
|
|
||||||
|
|||||||
@@ -5,31 +5,24 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.types
|
package org.jetbrains.kotlin.types
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||||
|
import org.jetbrains.kotlin.descriptors.annotations.composeAnnotations
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
class AnnotationsTypeAttribute(val annotations: Annotations) : TypeAttribute<AnnotationsTypeAttribute>() {
|
class AnnotationsTypeAttribute(val annotations: Annotations) : TypeAttribute<AnnotationsTypeAttribute>() {
|
||||||
constructor(annotations: List<AnnotationDescriptor>) : this(Annotations.create(annotations))
|
override fun union(other: AnnotationsTypeAttribute?): AnnotationsTypeAttribute = this
|
||||||
|
|
||||||
override fun union(other: AnnotationsTypeAttribute?): AnnotationsTypeAttribute? = null
|
override fun intersect(other: AnnotationsTypeAttribute?): AnnotationsTypeAttribute = this
|
||||||
|
|
||||||
override fun intersect(other: AnnotationsTypeAttribute?): AnnotationsTypeAttribute? = null
|
|
||||||
|
|
||||||
override fun add(other: AnnotationsTypeAttribute?): AnnotationsTypeAttribute {
|
override fun add(other: AnnotationsTypeAttribute?): AnnotationsTypeAttribute {
|
||||||
if (other == null) return this
|
if (other == null) return this
|
||||||
return AnnotationsTypeAttribute(Annotations.create(annotations + other.annotations))
|
return AnnotationsTypeAttribute(composeAnnotations(annotations, other.annotations))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun isSubtypeOf(other: AnnotationsTypeAttribute?): Boolean = true
|
override fun isSubtypeOf(other: AnnotationsTypeAttribute?): Boolean = true
|
||||||
|
|
||||||
override val key: KClass<out AnnotationsTypeAttribute>
|
override val key: KClass<out AnnotationsTypeAttribute>
|
||||||
get() = AnnotationsTypeAttribute::class
|
get() = AnnotationsTypeAttribute::class
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
if (other !is AnnotationsTypeAttribute) return false
|
|
||||||
return annotations == other.annotations
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val TypeAttributes.annotationsAttribute: AnnotationsTypeAttribute? by TypeAttributes.attributeAccessor<AnnotationsTypeAttribute>()
|
val TypeAttributes.annotationsAttribute: AnnotationsTypeAttribute? by TypeAttributes.attributeAccessor<AnnotationsTypeAttribute>()
|
||||||
|
|||||||
@@ -27,9 +27,6 @@ open class ErrorType @JvmOverloads internal constructor(
|
|||||||
override val isMarkedNullable: Boolean = false,
|
override val isMarkedNullable: Boolean = false,
|
||||||
open val presentableName: String = "???"
|
open val presentableName: String = "???"
|
||||||
) : SimpleType() {
|
) : SimpleType() {
|
||||||
override val annotations: Annotations
|
|
||||||
get() = Annotations.EMPTY
|
|
||||||
|
|
||||||
override val attributes: TypeAttributes
|
override val attributes: TypeAttributes
|
||||||
get() = TypeAttributes.Empty
|
get() = TypeAttributes.Empty
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,8 @@ sealed class KotlinType : Annotated, KotlinTypeMarker {
|
|||||||
abstract val isMarkedNullable: Boolean
|
abstract val isMarkedNullable: Boolean
|
||||||
abstract val memberScope: MemberScope
|
abstract val memberScope: MemberScope
|
||||||
abstract val attributes: TypeAttributes
|
abstract val attributes: TypeAttributes
|
||||||
|
override val annotations: Annotations
|
||||||
|
get() = attributes.annotations
|
||||||
|
|
||||||
abstract fun unwrap(): UnwrappedType
|
abstract fun unwrap(): UnwrappedType
|
||||||
|
|
||||||
@@ -125,7 +127,6 @@ abstract class WrappedType : KotlinType() {
|
|||||||
open fun isComputed(): Boolean = true
|
open fun isComputed(): Boolean = true
|
||||||
protected abstract val delegate: KotlinType
|
protected abstract val delegate: KotlinType
|
||||||
|
|
||||||
override val annotations: Annotations get() = delegate.annotations
|
|
||||||
override val constructor: TypeConstructor get() = delegate.constructor
|
override val constructor: TypeConstructor get() = delegate.constructor
|
||||||
override val arguments: List<TypeProjection> get() = delegate.arguments
|
override val arguments: List<TypeProjection> get() = delegate.arguments
|
||||||
override val isMarkedNullable: Boolean get() = delegate.isMarkedNullable
|
override val isMarkedNullable: Boolean get() = delegate.isMarkedNullable
|
||||||
@@ -210,12 +211,11 @@ abstract class FlexibleType(val lowerBound: SimpleType, val upperBound: SimpleTy
|
|||||||
|
|
||||||
abstract fun render(renderer: DescriptorRenderer, options: DescriptorRendererOptions): String
|
abstract fun render(renderer: DescriptorRenderer, options: DescriptorRendererOptions): String
|
||||||
|
|
||||||
override val annotations: Annotations get() = delegate.annotations
|
override val attributes: TypeAttributes get() = delegate.attributes
|
||||||
override val constructor: TypeConstructor get() = delegate.constructor
|
override val constructor: TypeConstructor get() = delegate.constructor
|
||||||
override val arguments: List<TypeProjection> get() = delegate.arguments
|
override val arguments: List<TypeProjection> get() = delegate.arguments
|
||||||
override val isMarkedNullable: Boolean get() = delegate.isMarkedNullable
|
override val isMarkedNullable: Boolean get() = delegate.isMarkedNullable
|
||||||
override val memberScope: MemberScope get() = delegate.memberScope
|
override val memberScope: MemberScope get() = delegate.memberScope
|
||||||
override val attributes: TypeAttributes get() = delegate.attributes
|
|
||||||
|
|
||||||
override fun toString(): String = DescriptorRenderer.DEBUG_TEXT.renderType(this)
|
override fun toString(): String = DescriptorRenderer.DEBUG_TEXT.renderType(this)
|
||||||
|
|
||||||
|
|||||||
@@ -206,7 +206,6 @@ private class SimpleTypeImpl(
|
|||||||
@TypeRefinement
|
@TypeRefinement
|
||||||
override val hasNotTrivialRefinementFactory: Boolean get() = true
|
override val hasNotTrivialRefinementFactory: Boolean get() = true
|
||||||
|
|
||||||
override val annotations: Annotations get() = Annotations.EMPTY
|
|
||||||
override val attributes: TypeAttributes get() = TypeAttributes.Empty
|
override val attributes: TypeAttributes get() = TypeAttributes.Empty
|
||||||
|
|
||||||
override fun replaceAttributes(newAttributes: TypeAttributes) =
|
override fun replaceAttributes(newAttributes: TypeAttributes) =
|
||||||
@@ -254,7 +253,6 @@ class SupposititiousSimpleType(private val realType: SimpleType, val overwritten
|
|||||||
override val arguments: List<TypeProjection> = realType.arguments
|
override val arguments: List<TypeProjection> = realType.arguments
|
||||||
override val isMarkedNullable: Boolean = realType.isMarkedNullable
|
override val isMarkedNullable: Boolean = realType.isMarkedNullable
|
||||||
override val memberScope: MemberScope = realType.memberScope
|
override val memberScope: MemberScope = realType.memberScope
|
||||||
override val annotations: Annotations = realType.annotations
|
|
||||||
override val attributes: TypeAttributes get() = realType.attributes
|
override val attributes: TypeAttributes get() = realType.attributes
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,8 +273,6 @@ private class SimpleTypeWithAttributes(
|
|||||||
delegate: SimpleType,
|
delegate: SimpleType,
|
||||||
override val attributes: TypeAttributes
|
override val attributes: TypeAttributes
|
||||||
) : DelegatingSimpleTypeImpl(delegate) {
|
) : DelegatingSimpleTypeImpl(delegate) {
|
||||||
override val annotations: Annotations
|
|
||||||
get() = attributes.toDefaultAnnotations()
|
|
||||||
@TypeRefinement
|
@TypeRefinement
|
||||||
override fun replaceDelegate(delegate: SimpleType) = SimpleTypeWithAttributes(delegate, attributes)
|
override fun replaceDelegate(delegate: SimpleType) = SimpleTypeWithAttributes(delegate, attributes)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ import org.jetbrains.kotlin.types.model.DefinitelyNotNullTypeMarker
|
|||||||
abstract class DelegatingSimpleType : SimpleType() {
|
abstract class DelegatingSimpleType : SimpleType() {
|
||||||
protected abstract val delegate: SimpleType
|
protected abstract val delegate: SimpleType
|
||||||
|
|
||||||
override val annotations: Annotations get() = delegate.annotations
|
|
||||||
override val constructor: TypeConstructor get() = delegate.constructor
|
override val constructor: TypeConstructor get() = delegate.constructor
|
||||||
override val arguments: List<TypeProjection> get() = delegate.arguments
|
override val arguments: List<TypeProjection> get() = delegate.arguments
|
||||||
override val isMarkedNullable: Boolean get() = delegate.isMarkedNullable
|
override val isMarkedNullable: Boolean get() = delegate.isMarkedNullable
|
||||||
|
|||||||
@@ -58,9 +58,6 @@ abstract class AbstractStubType(val originalTypeVariable: TypeConstructor, overr
|
|||||||
override val arguments: List<TypeProjection>
|
override val arguments: List<TypeProjection>
|
||||||
get() = emptyList()
|
get() = emptyList()
|
||||||
|
|
||||||
override val annotations: Annotations
|
|
||||||
get() = Annotations.EMPTY
|
|
||||||
|
|
||||||
override val attributes: TypeAttributes
|
override val attributes: TypeAttributes
|
||||||
get() = TypeAttributes.Empty
|
get() = TypeAttributes.Empty
|
||||||
|
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ class TypeAliasExpander(
|
|||||||
replaceAttributes(createdCombinedAttributes(newAttributes))
|
replaceAttributes(createdCombinedAttributes(newAttributes))
|
||||||
|
|
||||||
private fun SimpleType.combineAttributes(newAttributes: TypeAttributes): SimpleType =
|
private fun SimpleType.combineAttributes(newAttributes: TypeAttributes): SimpleType =
|
||||||
if (isError) this else replaceAttributes(newAttributes = createdCombinedAttributes(newAttributes))
|
if (isError) this else replace(newAttributes = createdCombinedAttributes(newAttributes))
|
||||||
|
|
||||||
private fun KotlinType.createdCombinedAttributes(newAttributes: TypeAttributes): TypeAttributes {
|
private fun KotlinType.createdCombinedAttributes(newAttributes: TypeAttributes): TypeAttributes {
|
||||||
if (isError) return attributes
|
if (isError) return attributes
|
||||||
|
|||||||
@@ -25,7 +25,9 @@ object DefaultTypeAttributeTranslator : TypeAttributeTranslator {
|
|||||||
typeConstructor: TypeConstructor?,
|
typeConstructor: TypeConstructor?,
|
||||||
containingDeclaration: DeclarationDescriptor?
|
containingDeclaration: DeclarationDescriptor?
|
||||||
): TypeAttributes {
|
): TypeAttributes {
|
||||||
return TypeAttributes.create(listOf(AnnotationsTypeAttribute(annotations)))
|
return if (annotations.isEmpty())
|
||||||
|
TypeAttributes.Empty else
|
||||||
|
TypeAttributes.create(listOf(AnnotationsTypeAttribute(annotations)))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toAnnotations(attributes: TypeAttributes): Annotations {
|
override fun toAnnotations(attributes: TypeAttributes): Annotations {
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ class TypeAttributes private constructor(attributes: List<TypeAttribute<*>>) : A
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val Empty: TypeAttributes = TypeAttributes(listOf(AnnotationsTypeAttribute(Annotations.EMPTY)))
|
val Empty: TypeAttributes = TypeAttributes(emptyList())
|
||||||
|
|
||||||
fun create(attributes: List<TypeAttribute<*>>): TypeAttributes {
|
fun create(attributes: List<TypeAttribute<*>>): TypeAttributes {
|
||||||
return if (attributes.isEmpty()) {
|
return if (attributes.isEmpty()) {
|
||||||
@@ -70,6 +70,8 @@ class TypeAttributes private constructor(attributes: List<TypeAttribute<*>>) : A
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val size: Int get() = arrayMap.size
|
||||||
|
|
||||||
fun union(other: TypeAttributes): TypeAttributes {
|
fun union(other: TypeAttributes): TypeAttributes {
|
||||||
return perform(other) { this.union(it) }
|
return perform(other) { this.union(it) }
|
||||||
}
|
}
|
||||||
@@ -87,15 +89,11 @@ class TypeAttributes private constructor(attributes: List<TypeAttribute<*>>) : A
|
|||||||
return arrayMap[index] != null
|
return arrayMap[index] != null
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalStdlibApi::class)
|
|
||||||
operator fun plus(attribute: TypeAttribute<*>): TypeAttributes {
|
operator fun plus(attribute: TypeAttribute<*>): TypeAttributes {
|
||||||
if (attribute in this) return this
|
if (attribute in this) return this
|
||||||
if (isEmpty()) return TypeAttributes(attribute)
|
if (isEmpty()) return TypeAttributes(attribute)
|
||||||
val newAttributes = buildList {
|
val newAttributes = this.toList() + attribute
|
||||||
addAll(this)
|
return create(newAttributes)
|
||||||
add(attribute)
|
|
||||||
}
|
|
||||||
return TypeAttributes(newAttributes)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun remove(attribute: TypeAttribute<*>): TypeAttributes {
|
fun remove(attribute: TypeAttribute<*>): TypeAttributes {
|
||||||
@@ -119,6 +117,7 @@ class TypeAttributes private constructor(attributes: List<TypeAttribute<*>>) : A
|
|||||||
|
|
||||||
override val typeRegistry: TypeRegistry<TypeAttribute<*>, TypeAttribute<*>>
|
override val typeRegistry: TypeRegistry<TypeAttribute<*>, TypeAttribute<*>>
|
||||||
get() = Companion
|
get() = Companion
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun TypeAttributes.toDefaultAnnotations(): Annotations =
|
fun TypeAttributes.toDefaultAnnotations(): Annotations =
|
||||||
@@ -127,6 +126,9 @@ fun TypeAttributes.toDefaultAnnotations(): Annotations =
|
|||||||
fun Annotations.toDefaultAttributes(): TypeAttributes = DefaultTypeAttributeTranslator.toAttributes(this)
|
fun Annotations.toDefaultAttributes(): TypeAttributes = DefaultTypeAttributeTranslator.toAttributes(this)
|
||||||
|
|
||||||
fun TypeAttributes.replaceAnnotations(newAnnotations: Annotations): TypeAttributes {
|
fun TypeAttributes.replaceAnnotations(newAnnotations: Annotations): TypeAttributes {
|
||||||
val withoutCustom = (annotationsAttribute?.let { this.remove(it) } ?: this)
|
if (annotations === newAnnotations) return this
|
||||||
return withoutCustom.add(newAnnotations.toDefaultAttributes())
|
val withoutAnnotations = annotationsAttribute?.let { this.remove(it) } ?: this
|
||||||
|
// Check if iterator hasNext to handle FilteredAnnotations.isEmpty() with OldInference
|
||||||
|
if (!newAnnotations.iterator().hasNext() && newAnnotations.isEmpty()) return withoutAnnotations
|
||||||
|
return withoutAnnotations.plus(AnnotationsTypeAttribute(newAnnotations))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.types
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||||
|
import org.jetbrains.kotlin.descriptors.annotations.FilteredAnnotations
|
||||||
|
|
||||||
abstract class TypeSubstitution {
|
abstract class TypeSubstitution {
|
||||||
companion object {
|
companion object {
|
||||||
@@ -50,6 +51,7 @@ abstract class TypeSubstitution {
|
|||||||
override fun filterAnnotations(annotations: Annotations) = this@TypeSubstitution.filterAnnotations(annotations)
|
override fun filterAnnotations(annotations: Annotations) = this@TypeSubstitution.filterAnnotations(annotations)
|
||||||
override fun prepareTopLevelType(topLevelType: KotlinType, position: Variance) =
|
override fun prepareTopLevelType(topLevelType: KotlinType, position: Variance) =
|
||||||
this@TypeSubstitution.prepareTopLevelType(topLevelType, position)
|
this@TypeSubstitution.prepareTopLevelType(topLevelType, position)
|
||||||
|
|
||||||
override fun isEmpty() = this@TypeSubstitution.isEmpty()
|
override fun isEmpty() = this@TypeSubstitution.isEmpty()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -144,23 +146,26 @@ fun KotlinType.replace(
|
|||||||
): KotlinType {
|
): KotlinType {
|
||||||
if ((newArguments.isEmpty() || newArguments === arguments) && newAnnotations === annotations) return this
|
if ((newArguments.isEmpty() || newArguments === arguments) && newAnnotations === annotations) return this
|
||||||
|
|
||||||
|
val newAttributes = attributes.replaceAnnotations(
|
||||||
|
// Specially handle FilteredAnnotations here due to FilteredAnnotations.isEmpty()
|
||||||
|
if (newAnnotations is FilteredAnnotations && newAnnotations.isEmpty()) Annotations.EMPTY else newAnnotations
|
||||||
|
)
|
||||||
|
|
||||||
return when (val unwrapped = unwrap()) {
|
return when (val unwrapped = unwrap()) {
|
||||||
is FlexibleType -> KotlinTypeFactory.flexibleType(
|
is FlexibleType -> KotlinTypeFactory.flexibleType(
|
||||||
unwrapped.lowerBound.replace(newArguments, newAnnotations),
|
unwrapped.lowerBound.replace(newArguments, newAttributes),
|
||||||
unwrapped.upperBound.replace(newArgumentsForUpperBound, newAnnotations)
|
unwrapped.upperBound.replace(newArgumentsForUpperBound, newAttributes)
|
||||||
)
|
)
|
||||||
is SimpleType -> unwrapped.replace(newArguments, newAnnotations)
|
is SimpleType -> unwrapped.replace(newArguments, newAttributes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun SimpleType.replace(
|
fun SimpleType.replace(
|
||||||
newArguments: List<TypeProjection> = arguments,
|
newArguments: List<TypeProjection> = arguments,
|
||||||
newAnnotations: Annotations = annotations
|
newAttributes: TypeAttributes = attributes
|
||||||
): SimpleType {
|
): SimpleType {
|
||||||
if (newArguments.isEmpty() && newAnnotations === annotations) return this
|
if (newArguments.isEmpty() && newAttributes === attributes) return this
|
||||||
|
|
||||||
val newAttributes = attributes.replaceAnnotations(newAnnotations)
|
|
||||||
|
|
||||||
if (newArguments.isEmpty()) {
|
if (newArguments.isEmpty()) {
|
||||||
return replaceAttributes(newAttributes)
|
return replaceAttributes(newAttributes)
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.resolve.unsubstitutedUnderlyingType
|
|||||||
import org.jetbrains.kotlin.types.*
|
import org.jetbrains.kotlin.types.*
|
||||||
import org.jetbrains.kotlin.types.model.*
|
import org.jetbrains.kotlin.types.model.*
|
||||||
import org.jetbrains.kotlin.types.typeUtil.*
|
import org.jetbrains.kotlin.types.typeUtil.*
|
||||||
|
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||||
import org.jetbrains.kotlin.types.typeUtil.isSignedOrUnsignedNumberType as classicIsSignedOrUnsignedNumberType
|
import org.jetbrains.kotlin.types.typeUtil.isSignedOrUnsignedNumberType as classicIsSignedOrUnsignedNumberType
|
||||||
|
|
||||||
@@ -516,12 +517,11 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy
|
|||||||
arguments: List<TypeArgumentMarker>,
|
arguments: List<TypeArgumentMarker>,
|
||||||
nullable: Boolean,
|
nullable: Boolean,
|
||||||
isExtensionFunction: Boolean,
|
isExtensionFunction: Boolean,
|
||||||
annotations: List<AnnotationMarker>?
|
attributes: List<AnnotationMarker>?
|
||||||
): SimpleTypeMarker {
|
): SimpleTypeMarker {
|
||||||
require(constructor is TypeConstructor, constructor::errorMessage)
|
require(constructor is TypeConstructor, constructor::errorMessage)
|
||||||
|
|
||||||
val ourAnnotations = annotations?.filterIsInstance<AnnotationDescriptor>()
|
val ourAnnotations = attributes?.firstIsInstanceOrNull<AnnotationsTypeAttribute>()?.annotations?.toList()
|
||||||
require(ourAnnotations?.size == annotations?.size)
|
|
||||||
|
|
||||||
fun createExtensionFunctionAnnotation() = BuiltInAnnotationDescriptor(builtIns, FqNames.extensionFunctionType, emptyMap())
|
fun createExtensionFunctionAnnotation() = BuiltInAnnotationDescriptor(builtIns, FqNames.extensionFunctionType, emptyMap())
|
||||||
|
|
||||||
@@ -673,6 +673,11 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy
|
|||||||
return this.attributes.toList()
|
return this.attributes.toList()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun KotlinTypeMarker.hasCustomAttributes(): Boolean {
|
||||||
|
require(this is KotlinType, this::errorMessage)
|
||||||
|
return this.attributes.size > 1
|
||||||
|
}
|
||||||
|
|
||||||
override fun KotlinTypeMarker.getCustomAttributes(): List<AnnotationMarker> {
|
override fun KotlinTypeMarker.getCustomAttributes(): List<AnnotationMarker> {
|
||||||
require(this is KotlinType, this::errorMessage)
|
require(this is KotlinType, this::errorMessage)
|
||||||
return this.attributes.filterNot { it is AnnotationsTypeAttribute }
|
return this.attributes.filterNot { it is AnnotationsTypeAttribute }
|
||||||
|
|||||||
@@ -207,16 +207,13 @@ class NewCapturedType(
|
|||||||
captureStatus: CaptureStatus, lowerType: UnwrappedType?, projection: TypeProjection, typeParameter: TypeParameterDescriptor
|
captureStatus: CaptureStatus, lowerType: UnwrappedType?, projection: TypeProjection, typeParameter: TypeParameterDescriptor
|
||||||
) : this(captureStatus, NewCapturedTypeConstructor(projection, typeParameter = typeParameter), lowerType)
|
) : this(captureStatus, NewCapturedTypeConstructor(projection, typeParameter = typeParameter), lowerType)
|
||||||
|
|
||||||
override val annotations: Annotations
|
|
||||||
get() = attributes.toDefaultAnnotations()
|
|
||||||
|
|
||||||
override val arguments: List<TypeProjection> get() = listOf()
|
override val arguments: List<TypeProjection> get() = listOf()
|
||||||
|
|
||||||
override val memberScope: MemberScope // todo what about foo().bar() where foo() return captured type?
|
override val memberScope: MemberScope // todo what about foo().bar() where foo() return captured type?
|
||||||
get() = ErrorUtils.createErrorScope("No member resolution should be done on captured type!", true)
|
get() = ErrorUtils.createErrorScope("No member resolution should be done on captured type!", true)
|
||||||
|
|
||||||
override fun replaceAttributes(newAttributes: TypeAttributes): SimpleType =
|
override fun replaceAttributes(newAttributes: TypeAttributes): SimpleType =
|
||||||
NewCapturedType(captureStatus, constructor, lowerType, newAttributes, isMarkedNullable)
|
NewCapturedType(captureStatus, constructor, lowerType, newAttributes, isMarkedNullable, isProjectionNotNull)
|
||||||
|
|
||||||
override fun makeNullableAsSpecified(newNullability: Boolean) =
|
override fun makeNullableAsSpecified(newNullability: Boolean) =
|
||||||
NewCapturedType(captureStatus, constructor, lowerType, attributes, newNullability)
|
NewCapturedType(captureStatus, constructor, lowerType, attributes, newNullability)
|
||||||
|
|||||||
Reference in New Issue
Block a user