Fixes and refactors

This commit is contained in:
Irene Dea
2021-10-21 13:22:51 -07:00
committed by Dmitriy Novozhilov
parent 2e2e70fede
commit 19bfc43bee
70 changed files with 263 additions and 327 deletions
@@ -49,6 +49,7 @@ import org.jetbrains.kotlin.types.expressions.DeclarationScopeProviderForLocalCl
import org.jetbrains.kotlin.types.expressions.LocalClassDescriptorHolder
import org.jetbrains.kotlin.types.expressions.LocalLazyDeclarationResolver
import org.jetbrains.kotlin.types.extensions.TypeAttributeTranslators
import org.jetbrains.kotlin.types.extensions.TypeAttributeTranslatorsForInjection
import org.jetbrains.kotlin.util.ProgressManagerBasedCancellationChecker
fun StorageComponentContainer.configureModule(
@@ -80,7 +81,7 @@ fun StorageComponentContainer.configureModule(
analyzerServices.platformConfigurator.configureModuleComponents(this)
analyzerServices.platformConfigurator.configureModuleDependentCheckers(this)
useInstance(TypeAttributeTranslators(moduleContext.project).translators)
useImpl<TypeAttributeTranslatorsForInjection>()
for (extension in StorageComponentContainerContributor.getInstances(moduleContext.project)) {
extension.registerModuleComponents(this, platform, moduleContext.module)
@@ -242,7 +242,7 @@ class DeclarationsChecker(
private fun checkTypeAliasExpansion(declaration: KtTypeAlias, typeAliasDescriptor: TypeAliasDescriptor) {
val typeAliasExpansion = TypeAliasExpansion.createWithFormalArguments(typeAliasDescriptor)
val reportStrategy = TypeAliasDeclarationCheckingReportStrategy(trace, typeAliasDescriptor, declaration, upperBoundChecker)
TypeAliasExpander(reportStrategy, true).expandWithoutAbbreviation(typeAliasExpansion, Annotations.EMPTY)
TypeAliasExpander(reportStrategy, true).expandWithoutAbbreviation(typeAliasExpansion, TypeAttributes.Empty)
}
private fun checkConstructorDeclaration(constructorDescriptor: ClassConstructorDescriptor, declaration: KtConstructor<*>) {
@@ -105,7 +105,7 @@ class TypeResolver(
fun resolveExpandedTypeForTypeAlias(typeAliasDescriptor: TypeAliasDescriptor): SimpleType {
val typeAliasExpansion = TypeAliasExpansion.createWithFormalArguments(typeAliasDescriptor)
val expandedType = TypeAliasExpander.NON_REPORTING.expandWithoutAbbreviation(typeAliasExpansion, Annotations.EMPTY)
val expandedType = TypeAliasExpander.NON_REPORTING.expandWithoutAbbreviation(typeAliasExpansion, TypeAttributes.Empty)
return expandedType
}
@@ -523,7 +523,7 @@ class TypeResolver(
ErrorUtils.createErrorType("?")
else
KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
typeAttributeTranslators.toAttributes(annotations),
typeAttributeTranslators.toAttributes(annotations, typeParameter.typeConstructor, containing),
typeParameter.typeConstructor,
listOf(),
false,
@@ -605,7 +605,11 @@ class TypeResolver(
}
val resultingType =
KotlinTypeFactory.simpleNotNullType(typeAttributeTranslators.toAttributes(annotations), classDescriptor, arguments)
KotlinTypeFactory.simpleNotNullType(
typeAttributeTranslators.toAttributes(annotations, classDescriptor.typeConstructor, c.scope.ownerDescriptor),
classDescriptor,
arguments
)
// We create flexible types by convention here
// This is not intended to be used in normal users' environments, only for tests and debugger etc
@@ -701,9 +705,11 @@ class TypeResolver(
return createErrorTypeForTypeConstructor(c, projectionFromAllQualifierParts, typeConstructor)
}
val attributes = typeAttributeTranslators.toAttributes(annotations, descriptor.typeConstructor, c.scope.ownerDescriptor)
return if (c.abbreviated) {
val abbreviatedType = KotlinTypeFactory.simpleType(
typeAttributeTranslators.toAttributes(annotations),
attributes,
descriptor.typeConstructor,
arguments,
false
@@ -711,7 +717,7 @@ class TypeResolver(
type(abbreviatedType)
} else {
val typeAliasExpansion = TypeAliasExpansion.create(null, descriptor, arguments)
val expandedType = TypeAliasExpander(reportStrategy, c.checkBounds).expand(typeAliasExpansion, annotations)
val expandedType = TypeAliasExpander(reportStrategy, c.checkBounds).expand(typeAliasExpansion, attributes)
type(expandedType)
}
}
@@ -331,7 +331,7 @@ class CallCompleter(
val value = constant.getValue(TypeUtils.NO_EXPECTED_TYPE).safeAs<Number>()?.toLong() ?: return null
val typeConstructor = IntegerValueTypeConstructor(value, moduleDescriptor, constant.parameters)
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
Annotations.EMPTY, typeConstructor, emptyList(), false,
TypeAttributes.Empty, typeConstructor, emptyList(), false,
ErrorUtils.createErrorScope("Scope for number value type ($typeConstructor)", true)
)
}
@@ -54,8 +54,6 @@ class TypeTemplate(
typeVariable.originalTypeParameter.builtIns.nothingType,
typeVariable.originalTypeParameter.builtIns.anyType.makeNullableAsSpecified(nullable)
) {
override fun replaceAnnotations(newAnnotations: Annotations) = this
override fun replaceAttributes(newAttributes: TypeAttributes) = this
override fun makeNullableAsSpecified(newNullability: Boolean) = TypeTemplate(typeVariable, builderInferenceData, newNullability)
@@ -394,7 +394,7 @@ class KotlinToResolvedCallTransformer(
val value = constant.getValue(TypeUtils.NO_EXPECTED_TYPE).safeAs<Number>()?.toLong() ?: return null
val typeConstructor = IntegerLiteralTypeConstructor(value, moduleDescriptor, constant.parameters)
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
Annotations.EMPTY, typeConstructor, emptyList(), false,
TypeAttributes.Empty, typeConstructor, emptyList(), false,
ErrorUtils.createErrorScope("Scope for number value type ($typeConstructor)", true),
)
}
@@ -70,7 +70,7 @@ fun replaceReturnTypeForCallable(type: KotlinType, given: KotlinType): KotlinTyp
fun replaceReturnTypeByUnknown(type: KotlinType) = replaceReturnTypeForCallable(type, DONT_CARE)
private fun replaceTypeArguments(type: KotlinType, newArguments: List<TypeProjection>) =
KotlinTypeFactory.simpleType(type.annotations, type.constructor, newArguments, type.isMarkedNullable)
KotlinTypeFactory.simpleType(type.attributes, type.constructor, newArguments, type.isMarkedNullable)
private fun getParameterArgumentsOfCallableType(type: KotlinType) =
type.arguments.dropLast(1)
@@ -126,7 +126,7 @@ fun getErasedReceiverType(receiverParameterDescriptor: ReceiverParameterDescript
}
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
receiverType.annotations, receiverTypeConstructor, fakeTypeArguments,
receiverType.attributes, receiverTypeConstructor, fakeTypeArguments,
receiverType.isMarkedNullable, ErrorUtils.createErrorScope("Error scope for erased receiver type", /*throwExceptions=*/true)
)
}
@@ -36,6 +36,7 @@ import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.storage.getValue
import org.jetbrains.kotlin.types.AbbreviatedType
import org.jetbrains.kotlin.types.ErrorUtils
import org.jetbrains.kotlin.types.typeUtil.replaceAnnotations
abstract class LazyAnnotationsContext(
val annotationResolver: AnnotationResolver,
@@ -272,7 +272,7 @@ public class CommonSupertypes {
else {
newScope = ErrorUtils.createErrorScope("A scope for common supertype which is not a normal classifier", true);
}
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(Annotations.Companion.getEMPTY(), constructor, newProjections, nullable, newScope);
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(TypeAttributes.Companion.getEmpty(), constructor, newProjections, nullable, newScope);
}
@NotNull
@@ -498,7 +498,7 @@ class DoubleColonExpressionResolver(
val arguments = descriptor.typeConstructor.parameters.map(TypeUtils::makeStarProjection)
KotlinTypeFactory.simpleType(
Annotations.EMPTY, descriptor.typeConstructor, arguments,
TypeAttributes.Empty, descriptor.typeConstructor, arguments,
possiblyBareType.isNullable || doubleColonExpression.hasQuestionMarks
)
} else {