diff --git a/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/components/KtFe10ExpressionTypeProvider.kt b/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/components/KtFe10ExpressionTypeProvider.kt index 86e935516a1..fdc4a14b8f4 100644 --- a/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/components/KtFe10ExpressionTypeProvider.kt +++ b/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/components/KtFe10ExpressionTypeProvider.kt @@ -28,7 +28,8 @@ import org.jetbrains.kotlin.resolve.calls.util.getResolvedCall import org.jetbrains.kotlin.resolve.calls.util.getType import org.jetbrains.kotlin.resolve.sam.SamConstructorDescriptor import org.jetbrains.kotlin.resolve.sam.getFunctionTypeForAbstractMethod -import org.jetbrains.kotlin.types.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorTypeKind +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.TypeUtils import org.jetbrains.kotlin.types.checker.intersectWrappedTypes import org.jetbrains.kotlin.types.typeUtil.makeNullable @@ -73,7 +74,7 @@ class KtFe10ExpressionTypeProvider( if (typeReference != null) { val bindingContext = analysisContext.analyze(typeReference, AnalysisMode.PARTIAL) val kotlinType = bindingContext[BindingContext.TYPE, typeReference] - ?: ErrorUtils.createErrorType("Return type \"${typeReference.text}\" cannot be resolved") + ?: ErrorUtils.createErrorType(ErrorTypeKind.RETURN_TYPE, typeReference.text) return kotlinType.toKtType(analysisContext) } @@ -82,7 +83,7 @@ class KtFe10ExpressionTypeProvider( if (declaration is KtFunction && declaration !is KtConstructor<*> && declaration.equalsToken != null) { val bindingContext = analysisContext.analyze(declaration) val kotlinType = bindingContext[BindingContext.FUNCTION, declaration]?.returnType - ?: ErrorUtils.createErrorType("Implicit return type for function \"${declaration.name}\" cannot be resolved") + ?: ErrorUtils.createErrorType(ErrorTypeKind.IMPLICIT_RETURN_TYPE_FOR_FUNCTION, declaration.name ?: "") return kotlinType.toKtType(analysisContext) } @@ -90,7 +91,7 @@ class KtFe10ExpressionTypeProvider( if (declaration is KtProperty) { val bindingContext = analysisContext.analyze(declaration) val kotlinType = bindingContext[BindingContext.VARIABLE, declaration]?.returnType - ?: ErrorUtils.createErrorType("Implicit return type for property \"${declaration.name}\" cannot be resolved") + ?: ErrorUtils.createErrorType(ErrorTypeKind.IMPLICIT_RETURN_TYPE_FOR_PROPERTY, declaration.name ?: "") return kotlinType.toKtType(analysisContext) } @@ -98,7 +99,9 @@ class KtFe10ExpressionTypeProvider( if (declaration is KtPropertyAccessor) { val bindingContext = analysisContext.analyze(declaration) val kotlinType = bindingContext[BindingContext.PROPERTY_ACCESSOR, declaration]?.returnType - ?: ErrorUtils.createErrorType("Return type for property accessor \"${declaration.property.name}\" cannot be resolved") + ?: ErrorUtils.createErrorType( + ErrorTypeKind.IMPLICIT_RETURN_TYPE_FOR_PROPERTY_ACCESSOR, declaration.property.name ?: "" + ) return kotlinType.toKtType(analysisContext) } @@ -112,7 +115,7 @@ class KtFe10ExpressionTypeProvider( if (property != null && property.setter == propertyAccessor) { val bindingContext = analysisContext.analyze(property) val kotlinType = bindingContext[BindingContext.VARIABLE, property]?.returnType - ?: ErrorUtils.createErrorType("Return type for property \"${declaration.name}\" cannot be resolved") + ?: ErrorUtils.createErrorType(ErrorTypeKind.RETURN_TYPE_FOR_PROPERTY, declaration.name ?: "") return kotlinType.toKtType(analysisContext) } @@ -122,7 +125,9 @@ class KtFe10ExpressionTypeProvider( if (declaration is KtConstructor<*>) { val bindingContext = analysisContext.analyze(declaration) val kotlinType = bindingContext[BindingContext.CONSTRUCTOR, declaration]?.returnType - ?: ErrorUtils.createErrorType("Return type for constructor \"${declaration.containingClass()?.name}\" cannot be resolved") + ?: ErrorUtils.createErrorType( + ErrorTypeKind.RETURN_TYPE_FOR_CONSTRUCTOR, declaration.containingClass()?.name ?: "" + ) return kotlinType.toKtType(analysisContext) } @@ -146,7 +151,8 @@ class KtFe10ExpressionTypeProvider( } val errorMessage = "Descriptor not found for function \"${declaration.name}\"" - return ErrorUtils.createErrorTypeWithCustomConstructor(errorMessage, function.typeConstructor).toKtType(analysisContext) + return ErrorUtils.createErrorType(ErrorTypeKind.NOT_FOUND_DESCRIPTOR_FOR_FUNCTION, function.typeConstructor, errorMessage) + .toKtType(analysisContext) } override fun getExpectedType(expression: PsiElement): KtType? = withValidityAssertion { diff --git a/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/components/KtFe10TypeCreator.kt b/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/components/KtFe10TypeCreator.kt index de70921dbc8..31c3c57f0c5 100644 --- a/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/components/KtFe10TypeCreator.kt +++ b/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/components/KtFe10TypeCreator.kt @@ -26,6 +26,9 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor import org.jetbrains.kotlin.incremental.components.NoLookupLocation import org.jetbrains.kotlin.types.* +import org.jetbrains.kotlin.types.error.ErrorType +import org.jetbrains.kotlin.types.error.ErrorTypeKind +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull internal class KtFe10TypeCreator( @@ -48,8 +51,8 @@ internal class KtFe10TypeCreator( } if (descriptor == null) { - val kotlinType = ErrorUtils.createErrorType("Cannot build class type, descriptor not found for builder $builder") - return KtFe10ClassErrorType(kotlinType as ErrorType, analysisContext) + val kotlinType = ErrorUtils.createErrorType(ErrorTypeKind.NOT_FOUND_DESCRIPTOR_FOR_CLASS, builder.toString()) + return KtFe10ClassErrorType(kotlinType, analysisContext) } val typeParameters = descriptor.typeConstructor.parameters @@ -77,7 +80,7 @@ internal class KtFe10TypeCreator( } } val kotlinType = descriptor?.defaultType - ?: ErrorUtils.createErrorType("Cannot build type parameter type, descriptor not found for builder $builder") + ?: ErrorUtils.createErrorType(ErrorTypeKind.NOT_FOUND_DESCRIPTOR_FOR_TYPE_PARAMETER, builder.toString()) return kotlinType.toKtType(analysisContext) as KtTypeParameterType } } diff --git a/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/components/KtFe10TypeProvider.kt b/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/components/KtFe10TypeProvider.kt index f45dfac3d8f..e76815a12af 100644 --- a/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/components/KtFe10TypeProvider.kt +++ b/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/components/KtFe10TypeProvider.kt @@ -45,6 +45,9 @@ import org.jetbrains.kotlin.resolve.scopes.utils.getImplicitReceiversHierarchy import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.checker.NewCapturedType import org.jetbrains.kotlin.types.checker.NewTypeVariableConstructor +import org.jetbrains.kotlin.types.error.ErrorType +import org.jetbrains.kotlin.types.error.ErrorTypeKind +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.typeUtil.isNothing import org.jetbrains.kotlin.util.containingNonLocalDeclaration @@ -71,7 +74,7 @@ internal class KtFe10TypeProvider( override fun buildSelfClassType(symbol: KtNamedClassOrObjectSymbol): KtType = withValidityAssertion { val kotlinType = (getSymbolDescriptor(symbol) as? ClassDescriptor)?.defaultType - ?: ErrorUtils.createErrorType("Cannot get class type for unresolved class ${symbol.nameOrAnonymous}") + ?: ErrorUtils.createErrorType(ErrorTypeKind.UNRESOLVED_CLASS_TYPE, symbol.nameOrAnonymous.toString()) return kotlinType.toKtType(analysisContext) } @@ -84,7 +87,7 @@ internal class KtFe10TypeProvider( override fun getKtType(ktTypeReference: KtTypeReference): KtType = withValidityAssertion { val bindingContext = analysisContext.analyze(ktTypeReference, AnalysisMode.PARTIAL) val kotlinType = bindingContext[BindingContext.TYPE, ktTypeReference] - ?: ErrorUtils.createErrorType("Cannot resolve type reference ${ktTypeReference.text}") + ?: ErrorUtils.createErrorType(ErrorTypeKind.UNRESOLVED_TYPE, ktTypeReference.text) return kotlinType.toKtType(analysisContext) } diff --git a/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/symbols/descriptorBased/base/Kt1DescUtils.kt b/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/symbols/descriptorBased/base/Kt1DescUtils.kt index 2932254c9d7..a62fdca0181 100644 --- a/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/symbols/descriptorBased/base/Kt1DescUtils.kt +++ b/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/symbols/descriptorBased/base/Kt1DescUtils.kt @@ -50,6 +50,9 @@ import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.checker.NewCapturedType import org.jetbrains.kotlin.types.checker.NewTypeVariableConstructor +import org.jetbrains.kotlin.types.error.ErrorType +import org.jetbrains.kotlin.types.error.ErrorTypeKind +import org.jetbrains.kotlin.types.error.ErrorUtils internal val MemberDescriptor.ktSymbolKind: KtSymbolKind get() { @@ -229,7 +232,7 @@ internal fun KotlinType.toKtType(analysisContext: Fe10AnalysisContext): KtType { return if (newTypeParameterDescriptor != null) { KtFe10TypeParameterType(unwrappedType, newTypeParameterDescriptor, analysisContext) } else { - KtFe10ClassErrorType(ErrorUtils.createErrorType("Unresolved type parameter type") as ErrorType, analysisContext) + KtFe10ClassErrorType(ErrorUtils.createErrorType(ErrorTypeKind.UNRESOLVED_TYPE_PARAMETER_TYPE), analysisContext) } } @@ -241,8 +244,8 @@ internal fun KotlinType.toKtType(analysisContext: Fe10AnalysisContext): KtType { is FunctionClassDescriptor -> KtFe10FunctionalType(unwrappedType, typeDeclaration, analysisContext) is ClassDescriptor -> KtFe10UsualClassType(unwrappedType, typeDeclaration, analysisContext) else -> { - val errorType = ErrorUtils.createErrorTypeWithCustomConstructor("Unresolved class type", typeConstructor) - KtFe10ClassErrorType(errorType as ErrorType, analysisContext) + val errorType = ErrorUtils.createErrorType(ErrorTypeKind.UNRESOLVED_CLASS_TYPE, typeConstructor, typeDeclaration.toString()) + KtFe10ClassErrorType(errorType, analysisContext) } } diff --git a/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/symbols/psiBased/base/KtFe10PsiSymbolUtils.kt b/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/symbols/psiBased/base/KtFe10PsiSymbolUtils.kt index 70305c2b04b..6b0a4ba96e0 100644 --- a/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/symbols/psiBased/base/KtFe10PsiSymbolUtils.kt +++ b/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/symbols/psiBased/base/KtFe10PsiSymbolUtils.kt @@ -26,12 +26,11 @@ import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.getParentOfType import org.jetbrains.kotlin.psi.psiUtil.hasBody -import org.jetbrains.kotlin.psi.psiUtil.isTopLevelInFileOrScript import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.scopes.LexicalScope -import org.jetbrains.kotlin.types.ErrorType -import org.jetbrains.kotlin.types.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorTypeKind +import org.jetbrains.kotlin.types.error.ErrorUtils internal val KtDeclaration.ktVisibility: Visibility? get() = when { @@ -149,6 +148,6 @@ internal fun PsiElement.getResolutionScope(bindingContext: BindingContext): Lexi internal fun KtFe10Symbol.createErrorType(): KtType { - val type = ErrorUtils.createErrorType("Type is unavailable for declaration $psi") as ErrorType + val type = ErrorUtils.createErrorType(ErrorTypeKind.UNAVAILABLE_TYPE_FOR_DECLARATION, psi.toString()) return KtFe10ClassErrorType(type, analysisContext) } \ No newline at end of file diff --git a/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/types/KtFe10ClassErrorType.kt b/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/types/KtFe10ClassErrorType.kt index 1b1378cf0cb..03ba0dcfc26 100644 --- a/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/types/KtFe10ClassErrorType.kt +++ b/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/types/KtFe10ClassErrorType.kt @@ -14,7 +14,7 @@ import org.jetbrains.kotlin.analysis.api.symbols.KtClassLikeSymbol import org.jetbrains.kotlin.analysis.api.types.KtClassErrorType import org.jetbrains.kotlin.analysis.api.types.KtTypeNullability import org.jetbrains.kotlin.analysis.api.withValidityAssertion -import org.jetbrains.kotlin.types.ErrorType +import org.jetbrains.kotlin.types.error.ErrorType internal class KtFe10ClassErrorType( override val type: ErrorType, @@ -23,7 +23,7 @@ internal class KtFe10ClassErrorType( override fun asStringForDebugging(): String = withValidityAssertion { type.asStringForDebugging() } override val error: String - get() = withValidityAssertion { "Type \"${type.presentableName}\" is unresolved" } + get() = withValidityAssertion { "Type \"${type.debugMessage}\" is unresolved" } override val candidateClassSymbols: Collection get() = withValidityAssertion { emptyList() } diff --git a/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/utils/KtFe10JvmTypeMapperContext.kt b/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/utils/KtFe10JvmTypeMapperContext.kt index 4a6f07523f0..90eb745f103 100644 --- a/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/utils/KtFe10JvmTypeMapperContext.kt +++ b/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/utils/KtFe10JvmTypeMapperContext.kt @@ -20,6 +20,7 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe import org.jetbrains.kotlin.resolve.lazy.ResolveSession import org.jetbrains.kotlin.types.* +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.model.KotlinTypeMarker import org.jetbrains.kotlin.types.model.TypeConstructorMarker import org.jetbrains.org.objectweb.asm.Type diff --git a/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/utils/KtFe10TypeRenderer.kt b/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/utils/KtFe10TypeRenderer.kt index 2607d33228f..05a060128a7 100644 --- a/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/utils/KtFe10TypeRenderer.kt +++ b/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/utils/KtFe10TypeRenderer.kt @@ -30,6 +30,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.annotationClass import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.checker.NewCapturedType import org.jetbrains.kotlin.types.checker.NewTypeVariableConstructor +import org.jetbrains.kotlin.types.error.ErrorType import org.jetbrains.kotlin.types.typeUtil.builtIns internal class KtFe10TypeRenderer(private val options: KtTypeRendererOptions, private val isDebugText: Boolean = false) { diff --git a/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/utils/KtFe10TypeSystemCommonBackendContextForTypeMapping.kt b/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/utils/KtFe10TypeSystemCommonBackendContextForTypeMapping.kt index 3e4faaf9b9a..efe80fe43df 100644 --- a/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/utils/KtFe10TypeSystemCommonBackendContextForTypeMapping.kt +++ b/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/utils/KtFe10TypeSystemCommonBackendContextForTypeMapping.kt @@ -14,6 +14,8 @@ import org.jetbrains.kotlin.resolve.lazy.ResolveSession import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.checker.ClassicTypeSystemContext import org.jetbrains.kotlin.types.checker.NewTypeVariableConstructor +import org.jetbrains.kotlin.types.error.ErrorTypeKind +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.model.KotlinTypeMarker import org.jetbrains.kotlin.types.model.SimpleTypeMarker import org.jetbrains.kotlin.types.model.TypeConstructorMarker @@ -43,7 +45,8 @@ internal class KtFe10TypeSystemCommonBackendContextForTypeMapping( override fun TypeConstructorMarker.defaultType(): KotlinTypeMarker { require(this is TypeConstructor) - val declaration = declarationDescriptor ?: return ErrorUtils.createErrorType("Unresolved declaration descriptor ($this)") + val declaration = declarationDescriptor + ?: return ErrorUtils.createErrorType(ErrorTypeKind.UNRESOLVED_DECLARATION, this.toString()) return declaration.defaultType } @@ -78,7 +81,7 @@ internal class KtFe10TypeSystemCommonBackendContextForTypeMapping( val declaration = declarationDescriptor if (declaration == null) { val errorArguments = arguments.map { TypeProjectionImpl(it as KotlinType) } - return ErrorUtils.createErrorTypeWithArguments("Unresolved type constructor $this", errorArguments) + return ErrorUtils.createErrorTypeWithArguments(ErrorTypeKind.UNRESOLVED_TYPE, errorArguments, this.toString()) } val substitutions = LinkedHashMap(parameters.size) @@ -106,7 +109,8 @@ internal class KtFe10TypeSystemCommonBackendContextForTypeMapping( override fun continuationTypeConstructor(): TypeConstructorMarker { val continuationFqName = StandardClassIds.Continuation.asSingleFqName() val foundClasses = resolveSession.getTopLevelClassifierDescriptors(continuationFqName, NoLookupLocation.FROM_IDE) - return foundClasses.firstOrNull()?.typeConstructor ?: ErrorUtils.createErrorTypeConstructor("Cannot find $continuationFqName") + return foundClasses.firstOrNull()?.typeConstructor + ?: ErrorUtils.createErrorTypeConstructor(ErrorTypeKind.NOT_FOUND_FQNAME, continuationFqName.toString()) } override fun functionNTypeConstructor(n: Int): TypeConstructorMarker { diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/MemberCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/MemberCodegen.java index d4d747ef722..6818a93106f 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/MemberCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/MemberCodegen.java @@ -47,7 +47,7 @@ import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature; import org.jetbrains.kotlin.resolve.source.KotlinSourceElementKt; import org.jetbrains.kotlin.storage.LockBasedStorageManager; import org.jetbrains.kotlin.storage.NotNullLazyValue; -import org.jetbrains.kotlin.types.ErrorUtils; +import org.jetbrains.kotlin.types.error.ErrorUtils; import org.jetbrains.kotlin.types.KotlinType; import org.jetbrains.org.objectweb.asm.Label; import org.jetbrains.org.objectweb.asm.MethodVisitor; diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyCodegen.java index cc3c0046a4b..e35cb2fff35 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyCodegen.java @@ -34,7 +34,8 @@ import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKt; import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodGenericSignature; import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature; import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedPropertyDescriptor; -import org.jetbrains.kotlin.types.ErrorUtils; +import org.jetbrains.kotlin.types.error.ErrorTypeKind; +import org.jetbrains.kotlin.types.error.ErrorUtils; import org.jetbrains.kotlin.types.KotlinType; import org.jetbrains.org.objectweb.asm.FieldVisitor; import org.jetbrains.org.objectweb.asm.MethodVisitor; @@ -483,7 +484,7 @@ public class PropertyCodegen { if (delegateType == null) { // Delegation convention is unresolved - delegateType = ErrorUtils.createErrorType("Delegate type"); + delegateType = ErrorUtils.createErrorType(ErrorTypeKind.TYPE_FOR_DELEGATION, delegateExpression.getText()); } return delegateType; } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/codegenUtil.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/codegenUtil.kt index d6c51923564..5d880694ab4 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/codegenUtil.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/codegenUtil.kt @@ -43,7 +43,7 @@ import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin import org.jetbrains.kotlin.resolve.jvm.diagnostics.Synthetic import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodGenericSignature import org.jetbrains.kotlin.resolve.scopes.receivers.TransientReceiver -import org.jetbrains.kotlin.types.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.TypeSystemCommonBackendContext import org.jetbrains.kotlin.types.TypeUtils diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/coroutineCodegenUtil.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/coroutineCodegenUtil.kt index 5e5699b965a..5dccd293063 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/coroutineCodegenUtil.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/coroutineCodegenUtil.kt @@ -38,10 +38,9 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.module import org.jetbrains.kotlin.resolve.descriptorUtil.resolveTopLevelClass import org.jetbrains.kotlin.resolve.jvm.AsmTypes import org.jetbrains.kotlin.resolve.jvm.AsmTypes.OBJECT_TYPE -import org.jetbrains.kotlin.types.ErrorUtils -import org.jetbrains.kotlin.types.KotlinType -import org.jetbrains.kotlin.types.KotlinTypeFactory -import org.jetbrains.kotlin.types.TypeConstructorSubstitution +import org.jetbrains.kotlin.types.* +import org.jetbrains.kotlin.types.error.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorTypeKind import org.jetbrains.kotlin.types.typeUtil.asTypeProjection import org.jetbrains.kotlin.types.typeUtil.makeNotNullable import org.jetbrains.kotlin.util.OperatorNameConventions @@ -277,7 +276,7 @@ fun ModuleDescriptor.getResult(kotlinType: KotlinType) = it, arguments = listOf(kotlinType.asTypeProjection()) ) - } ?: ErrorUtils.createErrorType("For Result") + } ?: ErrorUtils.createErrorType(ErrorTypeKind.TYPE_FOR_RESULT) fun FunctionDescriptor.isBuiltInSuspendCoroutineUninterceptedOrReturnInJvm() = getUserData(INITIAL_DESCRIPTOR_FOR_SUSPEND_FUNCTION)?.isBuiltInSuspendCoroutineUninterceptedOrReturn() == true diff --git a/compiler/builtins-serializer/src/org/jetbrains/kotlin/serialization/builtins/BuiltInsSerializerExtension.kt b/compiler/builtins-serializer/src/org/jetbrains/kotlin/serialization/builtins/BuiltInsSerializerExtension.kt index 9fa74cc3b52..f02d0633402 100644 --- a/compiler/builtins-serializer/src/org/jetbrains/kotlin/serialization/builtins/BuiltInsSerializerExtension.kt +++ b/compiler/builtins-serializer/src/org/jetbrains/kotlin/serialization/builtins/BuiltInsSerializerExtension.kt @@ -23,7 +23,7 @@ import org.jetbrains.kotlin.serialization.AnnotationSerializer import org.jetbrains.kotlin.serialization.KotlinSerializerExtensionBase import org.jetbrains.kotlin.serialization.deserialization.builtins.BuiltInSerializerProtocol import org.jetbrains.kotlin.types.KotlinType -import org.jetbrains.kotlin.types.UnresolvedType +import org.jetbrains.kotlin.types.typeUtil.isUnresolvedType class BuiltInsSerializerExtension : KotlinSerializerExtensionBase(BuiltInSerializerProtocol) { private val shortNameToClassId = mapOf( @@ -52,9 +52,9 @@ class BuiltInsSerializerExtension : KotlinSerializerExtensionBase(BuiltInSeriali private val KotlinType.presentableName: String get() { val unwrapped = unwrap() - if (unwrapped !is UnresolvedType) { - throw UnsupportedOperationException("Error types which are not UnresolvedType instances are not supported here: $unwrapped") + if (!isUnresolvedType(unwrapped)) { + throw UnsupportedOperationException("Error types which are not unresolved type instances are not supported here: $unwrapped") } - return unwrapped.presentableName + return unwrapped.debugMessage.removePrefix("Unresolved type for ") } } diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt index 5e7ce6aa32a..f52703fb480 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt @@ -368,8 +368,8 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo return ConeErrorType(ConeIntermediateDiagnostic(debugName)) } - override fun createErrorTypeWithCustomConstructor(debugName: String, constructor: TypeConstructorMarker): KotlinTypeMarker { - return ConeErrorType(ConeIntermediateDiagnostic("$debugName c: $constructor")) + override fun createUninferredType(constructor: TypeConstructorMarker): KotlinTypeMarker { + return ConeErrorType(ConeIntermediateDiagnostic("Uninferred type c: $constructor")) } override fun CapturedTypeMarker.captureStatus(): CaptureStatus { diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JavaGenericVarianceViolationTypeChecker.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JavaGenericVarianceViolationTypeChecker.kt index 66cbee35cde..790c536c14b 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JavaGenericVarianceViolationTypeChecker.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JavaGenericVarianceViolationTypeChecker.kt @@ -22,6 +22,7 @@ import org.jetbrains.kotlin.resolve.calls.checkers.AdditionalTypeChecker import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm import org.jetbrains.kotlin.types.* +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.checker.KotlinTypeChecker import org.jetbrains.kotlin.types.checker.TypeCheckingProcedure @@ -41,7 +42,7 @@ object JavaGenericVarianceViolationTypeChecker : AdditionalTypeChecker { c: ResolutionContext<*> ) { val expectedType = c.expectedType - if (TypeUtils.noExpectedType(expectedType) || ErrorUtils.containsErrorType(expectedType) || ErrorUtils.containsUninferredParameter(expectedType)) return + if (TypeUtils.noExpectedType(expectedType) || ErrorUtils.containsErrorType(expectedType) || ErrorUtils.containsUninferredTypeVariable(expectedType)) return // optimization: if no arguments or flexibility, everything is OK if (expectedType.arguments.isEmpty() || !expectedType.isFlexible()) return diff --git a/compiler/frontend/src/org/jetbrains/kotlin/analyzer/AnalysisResult.kt b/compiler/frontend/src/org/jetbrains/kotlin/analyzer/AnalysisResult.kt index aabe7d94e43..841f3697973 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/analyzer/AnalysisResult.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/analyzer/AnalysisResult.kt @@ -18,7 +18,7 @@ package org.jetbrains.kotlin.analyzer import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.resolve.BindingContext -import org.jetbrains.kotlin.types.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorUtils import java.io.File open class AnalysisResult protected constructor( @@ -58,12 +58,12 @@ open class AnalysisResult protected constructor( } } - private class CompilationError(bindingContext: BindingContext) : AnalysisResult(bindingContext, ErrorUtils.getErrorModule()) + private class CompilationError(bindingContext: BindingContext) : AnalysisResult(bindingContext, ErrorUtils.errorModule) private class InternalError( bindingContext: BindingContext, val exception: Throwable - ) : AnalysisResult(bindingContext, ErrorUtils.getErrorModule()) + ) : AnalysisResult(bindingContext, ErrorUtils.errorModule) class RetryWithAdditionalRoots( bindingContext: BindingContext, @@ -75,7 +75,7 @@ open class AnalysisResult protected constructor( ) : AnalysisResult(bindingContext, moduleDescriptor) companion object { - val EMPTY: AnalysisResult = success(BindingContext.EMPTY, ErrorUtils.getErrorModule()) + val EMPTY: AnalysisResult = success(BindingContext.EMPTY, ErrorUtils.errorModule) @JvmStatic fun success(bindingContext: BindingContext, module: ModuleDescriptor): AnalysisResult { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/checkers/utils/DebugInfoUtil.kt b/compiler/frontend/src/org/jetbrains/kotlin/checkers/utils/DebugInfoUtil.kt index 2bfc3398592..c54d98ba92e 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/checkers/utils/DebugInfoUtil.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/checkers/utils/DebugInfoUtil.kt @@ -21,7 +21,7 @@ import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.BindingContextUtils import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall import org.jetbrains.kotlin.resolve.calls.tasks.isDynamic -import org.jetbrains.kotlin.types.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.util.slicedMap.WritableSlice import java.util.HashMap diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/AnnotationResolverImpl.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/AnnotationResolverImpl.java index e1c5c3377a0..4c06d1e0494 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/AnnotationResolverImpl.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/AnnotationResolverImpl.java @@ -42,7 +42,8 @@ import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyAnnotationDescriptor; import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyAnnotationsContextImpl; import org.jetbrains.kotlin.resolve.scopes.LexicalScope; import org.jetbrains.kotlin.storage.StorageManager; -import org.jetbrains.kotlin.types.ErrorUtils; +import org.jetbrains.kotlin.types.error.ErrorTypeKind; +import org.jetbrains.kotlin.types.error.ErrorUtils; import org.jetbrains.kotlin.types.KotlinType; import javax.inject.Inject; @@ -119,12 +120,12 @@ public class AnnotationResolverImpl extends AnnotationResolver { ) { KtTypeReference typeReference = entryElement.getTypeReference(); if (typeReference == null) { - return ErrorUtils.createErrorType("No type reference: " + entryElement.getText()); + return ErrorUtils.createErrorType(ErrorTypeKind.UNRESOLVED_TYPE, entryElement.getText()); } KotlinType type = typeResolver.resolveType(scope, typeReference, trace, true); if (!(type.getConstructor().getDeclarationDescriptor() instanceof ClassDescriptor)) { - return ErrorUtils.createErrorType("Not an annotation: " + type); + return ErrorUtils.createErrorType(ErrorTypeKind.NOT_ANNOTATION_TYPE_IN_ANNOTATION_CONTEXT, type.toString()); } return type; } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/BodyResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/BodyResolver.java index f125db46981..6adbd9739f3 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/BodyResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/BodyResolver.java @@ -48,6 +48,7 @@ import org.jetbrains.kotlin.resolve.multiplatform.ExpectedActualResolverKt; import org.jetbrains.kotlin.resolve.scopes.*; import org.jetbrains.kotlin.resolve.source.KotlinSourceElementKt; import org.jetbrains.kotlin.types.*; +import org.jetbrains.kotlin.types.error.ErrorUtils; import org.jetbrains.kotlin.types.expressions.ExpressionTypingContext; import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices; import org.jetbrains.kotlin.types.expressions.PreliminaryDeclarationVisitor; diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegateInferenceSession.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegateInferenceSession.kt index 58f3acba0a8..9de1ba8adc6 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegateInferenceSession.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegateInferenceSession.kt @@ -22,7 +22,7 @@ import org.jetbrains.kotlin.resolve.calls.model.* import org.jetbrains.kotlin.resolve.calls.tower.StubTypesBasedInferenceSession import org.jetbrains.kotlin.resolve.calls.tower.PSICallResolver import org.jetbrains.kotlin.resolve.calls.tower.PSIPartialCallInfo -import org.jetbrains.kotlin.types.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.TypeConstructor import org.jetbrains.kotlin.types.UnwrappedType import org.jetbrains.kotlin.util.OperatorNameConventions diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.kt index 5fdcd2f729d..130cc871ec6 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.kt @@ -52,6 +52,8 @@ import org.jetbrains.kotlin.types.TypeUtils.NO_EXPECTED_TYPE import org.jetbrains.kotlin.types.TypeUtils.noExpectedType import org.jetbrains.kotlin.types.checker.KotlinTypeChecker import org.jetbrains.kotlin.types.checker.NewTypeVariableConstructor +import org.jetbrains.kotlin.types.error.ErrorTypeKind +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.expressions.ExpressionTypingContext import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils.createFakeExpressionOfType @@ -737,7 +739,7 @@ class DelegatedPropertyResolver( val pretendReturnType = call.getResolvedCall(trace.bindingContext)?.resultingDescriptor?.returnType return pretendReturnType?.takeIf { it.isProperType() } ?: delegateType.takeIf { it.isProperType() } - ?: ErrorUtils.createErrorType("Type for ${delegateExpression.text}") + ?: ErrorUtils.createErrorType(ErrorTypeKind.TYPE_FOR_DELEGATION, delegateExpression.text) } private fun KotlinType.isProperType(): Boolean { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java index 5af8257b1f9..ca80d55c886 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java @@ -61,6 +61,8 @@ import org.jetbrains.kotlin.resolve.source.KotlinSourceElementKt; import org.jetbrains.kotlin.storage.StorageManager; import org.jetbrains.kotlin.types.*; import org.jetbrains.kotlin.types.checker.KotlinTypeChecker; +import org.jetbrains.kotlin.types.error.ErrorTypeKind; +import org.jetbrains.kotlin.types.error.ErrorUtils; import org.jetbrains.kotlin.types.expressions.*; import org.jetbrains.kotlin.types.typeUtil.TypeUtilsKt; @@ -222,7 +224,7 @@ public class DescriptorResolver { } } else { - result.add(ErrorUtils.createErrorType("No type reference")); + result.add(ErrorUtils.createErrorType(ErrorTypeKind.UNRESOLVED_TYPE, delegationSpecifier.getText())); } } return result; @@ -691,7 +693,7 @@ public class DescriptorResolver { } else { // Error is reported by the parser - type = ErrorUtils.createErrorType("Annotation is absent"); + type = ErrorUtils.createErrorType(ErrorTypeKind.NO_TYPE_SPECIFIED, parameter.getText()); } if (parameter.hasModifier(VARARG_KEYWORD)) { return getVarargParameterType(type); @@ -765,8 +767,8 @@ public class DescriptorResolver { if (typeReference == null) { typeAliasDescriptor.initialize( typeParameterDescriptors, - ErrorUtils.createErrorType(name.asString()), - ErrorUtils.createErrorType(name.asString())); + ErrorUtils.createErrorType(ErrorTypeKind.UNRESOLVED_TYPE_ALIAS, name.asString()), + ErrorUtils.createErrorType(ErrorTypeKind.UNRESOLVED_TYPE_ALIAS, name.asString())); } else if (!languageVersionSettings.supportsFeature(LanguageFeature.TypeAliases)) { typeResolver.resolveAbbreviatedType(scopeWithTypeParameters, typeReference, trace); @@ -775,19 +777,19 @@ public class DescriptorResolver { TuplesKt.to(LanguageFeature.TypeAliases, languageVersionSettings))); typeAliasDescriptor.initialize( typeParameterDescriptors, - ErrorUtils.createErrorType(name.asString()), - ErrorUtils.createErrorType(name.asString())); + ErrorUtils.createErrorType(ErrorTypeKind.UNRESOLVED_TYPE_ALIAS, name.asString()), + ErrorUtils.createErrorType(ErrorTypeKind.UNRESOLVED_TYPE_ALIAS, name.asString())); } else { typeAliasDescriptor.initialize( typeParameterDescriptors, storageManager.createRecursionTolerantLazyValue( () -> typeResolver.resolveAbbreviatedType(scopeWithTypeParameters, typeReference, trace), - ErrorUtils.createErrorType("Recursive type alias expansion for " + typeAliasDescriptor.getName().asString()) + ErrorUtils.createErrorType(ErrorTypeKind.RECURSIVE_TYPE_ALIAS, typeAliasDescriptor.getName().asString()) ), storageManager.createRecursionTolerantLazyValue( () -> typeResolver.resolveExpandedTypeForTypeAlias(typeAliasDescriptor), - ErrorUtils.createErrorType("Recursive type alias expansion for " + typeAliasDescriptor.getName().asString()) + ErrorUtils.createErrorType(ErrorTypeKind.RECURSIVE_TYPE_ALIAS, typeAliasDescriptor.getName().asString()) ) ); } @@ -1232,7 +1234,7 @@ public class DescriptorResolver { getterType = propertyTypeIfKnown; } - getterDescriptor.initialize(getterType != null ? getterType : VariableTypeAndInitializerResolver.STUB_FOR_PROPERTY_WITHOUT_TYPE); + getterDescriptor.initialize(getterType != null ? getterType : VariableTypeAndInitializerResolver.getTypeForPropertyWithoutReturnType(propertyDescriptor.getName().asString())); return getterDescriptor; } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/FunctionDescriptorResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/FunctionDescriptorResolver.kt index 8acdfabea3d..29bd9a917cf 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/FunctionDescriptorResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/FunctionDescriptorResolver.kt @@ -58,15 +58,14 @@ import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope import org.jetbrains.kotlin.resolve.scopes.TraceBasedLocalRedeclarationChecker import org.jetbrains.kotlin.resolve.source.toSourceElement import org.jetbrains.kotlin.storage.StorageManager -import org.jetbrains.kotlin.types.ErrorUtils -import org.jetbrains.kotlin.types.KotlinType -import org.jetbrains.kotlin.types.TypeUtils +import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.checker.KotlinTypeChecker +import org.jetbrains.kotlin.types.error.ErrorTypeKind +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils.isFunctionExpression import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils.isFunctionLiteral -import org.jetbrains.kotlin.types.isError import org.jetbrains.kotlin.types.typeUtil.replaceAnnotations import java.util.* @@ -166,7 +165,7 @@ class FunctionDescriptorResolver( trace, scope, dataFlowInfo, function, functionDescriptor, inferenceSession ) else -> - ErrorUtils.createErrorType("No type, no body") + ErrorUtils.createErrorType(ErrorTypeKind.RETURN_TYPE, functionDescriptor.name.asString()) } functionDescriptor.setReturnType(inferredReturnType) } @@ -486,10 +485,10 @@ class FunctionDescriptorResolver( trace.report(CANNOT_INFER_PARAMETER_TYPE.on(valueParameter)) } - expectedType ?: TypeUtils.CANT_INFER_FUNCTION_PARAM_TYPE + expectedType ?: TypeUtils.CANNOT_INFER_FUNCTION_PARAM_TYPE } else { trace.report(VALUE_PARAMETER_WITH_NO_TYPE_ANNOTATION.on(valueParameter)) - ErrorUtils.createErrorType("Type annotation was missing for parameter ${valueParameter.nameAsSafeName}") + ErrorUtils.createErrorType(ErrorTypeKind.MISSED_TYPE_FOR_PARAMETER, valueParameter.nameAsSafeName.toString()) } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/OverloadChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/OverloadChecker.kt index 2c758e2ce92..86e59666f40 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/OverloadChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/OverloadChecker.kt @@ -22,7 +22,7 @@ import org.jetbrains.kotlin.resolve.calls.results.* import org.jetbrains.kotlin.resolve.descriptorUtil.hasLowPriorityInOverloadResolution import org.jetbrains.kotlin.resolve.descriptorUtil.isExtensionProperty import org.jetbrains.kotlin.resolve.descriptorUtil.varargParameterPosition -import org.jetbrains.kotlin.types.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.model.KotlinTypeMarker object OverloadabilitySpecificityCallbacks : SpecificityComparisonCallbacks { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeResolver.kt index ead606698b5..2306039d021 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeResolver.kt @@ -56,6 +56,10 @@ import org.jetbrains.kotlin.resolve.source.getPsi import org.jetbrains.kotlin.resolve.source.toSourceElement import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.Variance.* +import org.jetbrains.kotlin.types.error.ErrorTypeKind +import org.jetbrains.kotlin.types.error.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorScope +import org.jetbrains.kotlin.types.error.ThrowingScope import org.jetbrains.kotlin.types.extensions.TypeAttributeTranslators import org.jetbrains.kotlin.types.typeUtil.* import org.jetbrains.kotlin.utils.addToStdlib.safeAs @@ -96,8 +100,8 @@ class TypeResolver( ).unwrap() return when (resolvedType) { is DynamicType -> { - trace.report(Errors.TYPEALIAS_SHOULD_EXPAND_TO_CLASS.on(typeReference, resolvedType)) - ErrorUtils.createErrorType("dynamic type in wrong context") + trace.report(TYPEALIAS_SHOULD_EXPAND_TO_CLASS.on(typeReference, resolvedType)) + ErrorUtils.createErrorType(ErrorTypeKind.PROHIBITED_DYNAMIC_TYPE) } is SimpleType -> resolvedType else -> error("Unexpected type: $resolvedType") @@ -238,7 +242,7 @@ class TypeResolver( val hasSuspendModifier = outerModifierList?.hasModifier(KtTokens.SUSPEND_KEYWORD) ?: false val suspendModifier by lazy { outerModifierList?.getModifier(KtTokens.SUSPEND_KEYWORD) } if (hasSuspendModifier && !typeElement.canHaveFunctionTypeModifiers()) { - c.trace.report(Errors.WRONG_MODIFIER_TARGET.on(suspendModifier!!, KtTokens.SUSPEND_KEYWORD, "non-functional type")) + c.trace.report(WRONG_MODIFIER_TARGET.on(suspendModifier!!, KtTokens.SUSPEND_KEYWORD, "non-functional type")) } else if (hasSuspendModifier) { checkCoroutinesFeature(languageVersionSettings, c.trace, suspendModifier!!) } @@ -250,9 +254,10 @@ class TypeResolver( if (classifier == null) { val arguments = resolveTypeProjections( - c, ErrorUtils.createErrorType("No type").constructor, qualifierResolutionResult.allProjections + c, ErrorUtils.createErrorType(ErrorTypeKind.UNRESOLVED_TYPE, typeElement.text).constructor, qualifierResolutionResult.allProjections ) - result = type(ErrorUtils.createUnresolvedType(type.getDebugText(), arguments)) + val unresolvedType = ErrorUtils.createErrorTypeWithArguments(ErrorTypeKind.UNRESOLVED_TYPE, arguments, type.getDebugText()) + result = type(unresolvedType) return } @@ -504,7 +509,7 @@ class TypeResolver( } }) - return result ?: type(ErrorUtils.createErrorType(typeElement?.getDebugText() ?: "No type element")) + return result ?: type(ErrorUtils.createErrorType(ErrorTypeKind.NO_TYPE_SPECIFIED, typeElement?.getDebugText() ?: "unknown element")) } private fun KtTypeElement?.canHaveFunctionTypeModifiers(): Boolean = @@ -519,7 +524,7 @@ class TypeResolver( val scopeForTypeParameter = getScopeForTypeParameter(c, typeParameter) if (typeArgumentList != null) { - resolveTypeProjections(c, ErrorUtils.createErrorType("No type").constructor, typeArgumentList.arguments) + resolveTypeProjections(c, ErrorUtils.createErrorType(ErrorTypeKind.ERROR_TYPE_PARAMETER).constructor, typeArgumentList.arguments) c.trace.report(TYPE_ARGUMENTS_NOT_ALLOWED.on(typeArgumentList, "for type parameters")) } @@ -528,8 +533,8 @@ class TypeResolver( DescriptorResolver.checkHasOuterClassInstance(c.scope, c.trace, referenceExpression, containing) } - return if (scopeForTypeParameter is ErrorUtils.ErrorScope) - ErrorUtils.createErrorType("?") + return if (scopeForTypeParameter is ErrorScope && scopeForTypeParameter !is ThrowingScope) + ErrorUtils.createErrorType(ErrorTypeKind.ERROR_TYPE_PARAMETER) else KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope( typeAttributeTranslators.toAttributes(annotations, typeParameter.typeConstructor, containing), @@ -831,8 +836,9 @@ class TypeResolver( ): PossiblyBareType = type( ErrorUtils.createErrorTypeWithArguments( - typeConstructor.declarationDescriptor?.name?.asString() ?: typeConstructor.toString(), - resolveTypeProjectionsWithErrorConstructor(c, arguments) + ErrorTypeKind.TYPE_FOR_ERROR_TYPE_CONSTRUCTOR, + resolveTypeProjectionsWithErrorConstructor(c, arguments), + typeConstructor.declarationDescriptor?.name?.asString() ?: typeConstructor.toString() ) ) @@ -960,7 +966,7 @@ class TypeResolver( c: TypeResolutionContext, argumentElements: List, message: String = "Error type for resolving type projections" - ) = resolveTypeProjections(c, ErrorUtils.createErrorTypeConstructor(message), argumentElements) + ) = resolveTypeProjections(c, ErrorUtils.createErrorTypeConstructor(ErrorTypeKind.TYPE_FOR_ERROR_TYPE_CONSTRUCTOR, message), argumentElements) /** * For cases like: @@ -992,7 +998,7 @@ class TypeResolver( val parameterDescriptor = parameters[i] TypeUtils.makeStarProjection(parameterDescriptor) } else { - TypeProjectionImpl(OUT_VARIANCE, ErrorUtils.createErrorType("*")) + TypeProjectionImpl(OUT_VARIANCE, ErrorUtils.createErrorType(ErrorTypeKind.ERROR_TYPE_PROJECTION)) } } else { val type = resolveType(c.noBareTypes(), argumentElement.typeReference!!) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/VariableTypeAndInitializerResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/VariableTypeAndInitializerResolver.kt index 62e4fd8f05b..062dad686c4 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/VariableTypeAndInitializerResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/VariableTypeAndInitializerResolver.kt @@ -21,6 +21,8 @@ import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluat import org.jetbrains.kotlin.resolve.scopes.LexicalScope import org.jetbrains.kotlin.storage.StorageManager import org.jetbrains.kotlin.types.* +import org.jetbrains.kotlin.types.error.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorTypeKind import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices import org.jetbrains.kotlin.types.expressions.PreliminaryDeclarationVisitor @@ -37,8 +39,9 @@ class VariableTypeAndInitializerResolver( private val anonymousTypeTransformers: Iterable ) { companion object { - @JvmField - val STUB_FOR_PROPERTY_WITHOUT_TYPE = ErrorUtils.createErrorType("No type, no body") + @JvmStatic + fun getTypeForPropertyWithoutReturnType(property: String): SimpleType = + ErrorUtils.createErrorType(ErrorTypeKind.RETURN_TYPE_FOR_PROPERTY, property) } fun resolveType( @@ -58,7 +61,7 @@ class VariableTypeAndInitializerResolver( trace.report(VARIABLE_WITH_NO_TYPE_NO_INITIALIZER.on(variable)) } - return STUB_FOR_PROPERTY_WITHOUT_TYPE + return getTypeForPropertyWithoutReturnType(variableDescriptor.name.asString()) } fun resolveTypeNullable( @@ -165,7 +168,7 @@ class VariableTypeAndInitializerResolver( ) val delegatedType = getterReturnType?.let { approximateType(it, local) } - ?: ErrorUtils.createErrorType("Type from delegate") + ?: ErrorUtils.createErrorType(ErrorTypeKind.TYPE_FOR_DELEGATION, delegateExpression.text) transformAnonymousTypeIfNeeded( variableDescriptor, property, delegatedType, trace, anonymousTypeTransformers, languageVersionSettings diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallCompleter.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallCompleter.kt index ee71d5b7bf6..faff52964d0 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallCompleter.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallCompleter.kt @@ -13,7 +13,6 @@ import org.jetbrains.kotlin.contracts.EffectSystem import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor -import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.diagnostics.Errors import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.resolve.* @@ -48,6 +47,8 @@ import org.jetbrains.kotlin.resolve.constants.IntegerValueTypeConstructor import org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue import org.jetbrains.kotlin.types.* +import org.jetbrains.kotlin.types.error.ErrorScopeKind +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.expressions.DataFlowAnalyzer import org.jetbrains.kotlin.utils.addToStdlib.safeAs import java.util.* @@ -332,7 +333,7 @@ class CallCompleter( val typeConstructor = IntegerValueTypeConstructor(value, moduleDescriptor, constant.parameters) return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope( TypeAttributes.Empty, typeConstructor, emptyList(), false, - ErrorUtils.createErrorScope("Scope for number value type ($typeConstructor)", true) + ErrorUtils.createErrorScope(ErrorScopeKind.INTEGER_LITERAL_TYPE_SCOPE, throwExceptions = true, typeConstructor.toString()) ) } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallExpressionResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallExpressionResolver.kt index cbac4d5c8c9..94f3005d160 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallExpressionResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallExpressionResolver.kt @@ -45,19 +45,17 @@ import org.jetbrains.kotlin.resolve.calls.util.CallMaker import org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator import org.jetbrains.kotlin.resolve.scopes.receivers.* -import org.jetbrains.kotlin.types.ErrorUtils -import org.jetbrains.kotlin.types.KotlinType -import org.jetbrains.kotlin.types.TypeUtils +import org.jetbrains.kotlin.types.* +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.TypeUtils.NO_EXPECTED_TYPE import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner +import org.jetbrains.kotlin.types.error.ErrorTypeKind import org.jetbrains.kotlin.types.expressions.DataFlowAnalyzer import org.jetbrains.kotlin.types.expressions.ExpressionTypingContext import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices import org.jetbrains.kotlin.types.expressions.KotlinTypeInfo import org.jetbrains.kotlin.types.expressions.typeInfoFactory.createTypeInfo import org.jetbrains.kotlin.types.expressions.typeInfoFactory.noTypeInfo -import org.jetbrains.kotlin.types.isError -import org.jetbrains.kotlin.types.TypeRefinement import javax.inject.Inject class CallExpressionResolver( @@ -276,7 +274,7 @@ class CallExpressionResolver( context.trace.report( FUNCTION_EXPECTED.on( calleeExpression, calleeExpression, - type ?: ErrorUtils.createErrorType("") + type ?: ErrorUtils.createErrorType(ErrorTypeKind.ERROR_EXPECTED_TYPE) ) ) argumentTypeResolver.analyzeArgumentsAndRecordTypes( @@ -456,7 +454,8 @@ class CallExpressionResolver( for (element in elementChain) { val receiverType = receiverTypeInfo.type ?: ErrorUtils.createErrorType( - "Type for " + when (val receiver = element.receiver) { + ErrorTypeKind.ERROR_RECEIVER_TYPE, + when (val receiver = element.receiver) { is KtNameReferenceExpression -> receiver.getReferencedName() else -> receiver.text } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CandidateResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CandidateResolver.kt index 83266c082fd..0f6fd2336d1 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CandidateResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CandidateResolver.kt @@ -37,6 +37,8 @@ import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.TypeUtils.noExpectedType import org.jetbrains.kotlin.types.checker.ErrorTypesAreEqualToAnything import org.jetbrains.kotlin.types.checker.KotlinTypeChecker +import org.jetbrains.kotlin.types.error.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorTypeKind import org.jetbrains.kotlin.types.expressions.DoubleColonExpressionResolver import org.jetbrains.kotlin.types.typeUtil.containsTypeProjectionsInTopLevelArguments import org.jetbrains.kotlin.types.typeUtil.makeNotNullable @@ -110,15 +112,16 @@ class CandidateResolver( val typeArguments = ArrayList() for (projection in ktTypeArguments) { val type = projection.typeReference?.let { trace.bindingContext.get(BindingContext.TYPE, it) } - ?: ErrorUtils.createErrorType("Star projection in a call") + ?: ErrorUtils.createErrorType(ErrorTypeKind.STAR_PROJECTION_IN_CALL) typeArguments.add(type) } val expectedTypeArgumentCount = candidateDescriptor.typeParameters.size - for (index in ktTypeArguments.size..expectedTypeArgumentCount - 1) { + for (index in ktTypeArguments.size until expectedTypeArgumentCount) { typeArguments.add( ErrorUtils.createErrorType( - "Explicit type argument expected for " + candidateDescriptor.typeParameters[index].name + ErrorTypeKind.MISSED_TYPE_ARGUMENT_FOR_TYPE_PARAMETER, + candidateDescriptor.typeParameters[index].name.toString() ) ) } @@ -370,7 +373,7 @@ class CandidateResolver( } else { resultingType = smartCast } - } else if (ErrorUtils.containsUninferredParameter(expectedType)) { + } else if (ErrorUtils.containsUninferredTypeVariable(expectedType)) { matchStatus = ArgumentMatchStatus.MATCH_MODULO_UNINFERRED_TYPES } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt index 6a487ed9083..ad39d0a017d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt @@ -35,7 +35,7 @@ import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluat import org.jetbrains.kotlin.resolve.descriptorUtil.module import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedCallableMemberDescriptor -import org.jetbrains.kotlin.types.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.TypeUtils import org.jetbrains.kotlin.types.checker.intersectWrappedTypes @@ -656,7 +656,7 @@ class DiagnosticReporterByTrackingStrategy( } private fun KotlinType.containsUninferredTypeParameter(uninferredTypeVariable: TypeVariableMarker) = contains { - ErrorUtils.isUninferredParameter(it) || it == TypeUtils.DONT_CARE + ErrorUtils.isUninferredTypeVariable(it) || it == TypeUtils.DONT_CARE || it.constructor == uninferredTypeVariable.freshTypeConstructor(typeSystemContext) } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/InfixCallChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/InfixCallChecker.kt index e4d08fe983d..8b5b686acbc 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/InfixCallChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/InfixCallChecker.kt @@ -24,7 +24,7 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall import org.jetbrains.kotlin.resolve.calls.tasks.isDynamic import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe -import org.jetbrains.kotlin.types.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorUtils class InfixCallChecker : CallChecker { override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/OperatorCallChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/OperatorCallChecker.kt index 6e8e39b7a3b..b70464499e3 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/OperatorCallChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/OperatorCallChecker.kt @@ -31,7 +31,7 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall import org.jetbrains.kotlin.resolve.calls.tasks.isDynamic import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe -import org.jetbrains.kotlin.types.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.expressions.OperatorConventions class OperatorCallChecker : CallChecker { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/ConstraintSystemBuilderImpl.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/ConstraintSystemBuilderImpl.kt index c960bfcffb1..82cd57c23dc 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/ConstraintSystemBuilderImpl.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/ConstraintSystemBuilderImpl.kt @@ -30,6 +30,7 @@ import org.jetbrains.kotlin.resolve.calls.results.SimpleConstraintSystem import org.jetbrains.kotlin.resolve.descriptorUtil.hasExactAnnotation import org.jetbrains.kotlin.resolve.descriptorUtil.hasNoInferAnnotation import org.jetbrains.kotlin.types.* +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.TypeUtils.DONT_CARE import org.jetbrains.kotlin.types.checker.SimpleClassicTypeSystemContext import org.jetbrains.kotlin.types.checker.TypeCheckingProcedure @@ -186,7 +187,7 @@ open class ConstraintSystemBuilderImpl(private val mode: Mode = ConstraintSystem } private fun isErrorOrSpecialType(type: KotlinType?, constraintPosition: ConstraintPosition): Boolean { - if (TypeUtils.isDontCarePlaceholder(type) || ErrorUtils.isUninferredParameter(type)) { + if (TypeUtils.isDontCarePlaceholder(type) || ErrorUtils.isUninferredTypeVariable(type)) { return true } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/ConstraintSystemImpl.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/ConstraintSystemImpl.kt index 66b667ca1ae..b3ddb44f3ca 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/ConstraintSystemImpl.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/ConstraintSystemImpl.kt @@ -27,8 +27,10 @@ import org.jetbrains.kotlin.resolve.calls.inference.constraintPosition.derivedFr import org.jetbrains.kotlin.resolve.descriptorUtil.hasInternalAnnotationForResolve import org.jetbrains.kotlin.resolve.descriptorUtil.isInternalAnnotationForResolve import org.jetbrains.kotlin.types.* +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.TypeUtils.DONT_CARE import org.jetbrains.kotlin.types.checker.KotlinTypeChecker +import org.jetbrains.kotlin.types.error.ErrorTypeKind import org.jetbrains.kotlin.types.typeUtil.makeNotNullable import java.util.* @@ -135,10 +137,12 @@ internal class ConstraintSystemImpl( } override val resultingSubstitutor: TypeSubstitutor - get() = getSubstitutor(substituteOriginal = true) { ErrorUtils.createUninferredParameterType(it.originalTypeParameter) } + get() = getSubstitutor(substituteOriginal = true) { + ErrorUtils.createErrorType(ErrorTypeKind.UNINFERRED_TYPE_VARIABLE, it.originalTypeParameter.name.asString()) + } override val currentSubstitutor: TypeSubstitutor - get() = getSubstitutor(substituteOriginal = true) { TypeUtils.DONT_CARE } + get() = getSubstitutor(substituteOriginal = true) { DONT_CARE } private fun getSubstitutor(substituteOriginal: Boolean, getDefaultValue: (TypeVariable) -> KotlinType): TypeSubstitutor { val parameterToInferredValueMap = getParameterToInferredValueMap(allTypeParameterBounds, getDefaultValue, substituteOriginal) @@ -152,7 +156,9 @@ internal class ConstraintSystemImpl( } private fun satisfyInitialConstraints(): Boolean { - val substitutor = getSubstitutor(substituteOriginal = false) { ErrorUtils.createUninferredParameterType(it.originalTypeParameter) } + val substitutor = getSubstitutor(substituteOriginal = false) { + ErrorUtils.createErrorType(ErrorTypeKind.UNINFERRED_TYPE_VARIABLE, it.originalTypeParameter.name.asString()) + } fun KotlinType.substitute(): KotlinType? = substitutor.substitute(this, Variance.INVARIANT) return initialConstraints.all { (kind, subtype, superType, position) -> diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/TypeBoundsImpl.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/TypeBoundsImpl.kt index 0919f0d207d..b08d6c58e65 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/TypeBoundsImpl.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/TypeBoundsImpl.kt @@ -22,6 +22,7 @@ import org.jetbrains.kotlin.resolve.calls.inference.TypeBounds.BoundKind.* import org.jetbrains.kotlin.resolve.calls.inference.constraintPosition.ConstraintPosition import org.jetbrains.kotlin.resolve.constants.IntegerValueTypeConstructor import org.jetbrains.kotlin.types.* +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.checker.KotlinTypeChecker import org.jetbrains.kotlin.utils.addIfNotNull import java.util.* diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/model/ArgumentMapping.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/model/ArgumentMapping.kt index 177f55f4e54..2553072fb6d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/model/ArgumentMapping.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/model/ArgumentMapping.kt @@ -17,7 +17,7 @@ package org.jetbrains.kotlin.resolve.calls.model import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor -import org.jetbrains.kotlin.types.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorUtils interface ArgumentMapping { fun isError(): Boolean diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DataFlowValue.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DataFlowValue.kt index adaa9a35c2b..19616215f9a 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DataFlowValue.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DataFlowValue.kt @@ -17,7 +17,8 @@ package org.jetbrains.kotlin.resolve.calls.smartcasts import org.jetbrains.kotlin.builtins.KotlinBuiltIns -import org.jetbrains.kotlin.types.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorTypeKind +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.TypeUtils @@ -122,6 +123,6 @@ class DataFlowValue( fun nullValue(builtIns: KotlinBuiltIns) = DataFlowValue(IdentifierInfo.NULL, builtIns.nullableNothingType, Nullability.NULL) @JvmField - val ERROR = DataFlowValue(IdentifierInfo.ERROR, ErrorUtils.createErrorType("Error type for data flow"), Nullability.IMPOSSIBLE) + val ERROR = DataFlowValue(IdentifierInfo.ERROR, ErrorUtils.createErrorType(ErrorTypeKind.ERROR_DATA_FLOW_TYPE), Nullability.IMPOSSIBLE) } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/TracingStrategyForImplicitConstructorDelegationCall.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/TracingStrategyForImplicitConstructorDelegationCall.kt index 9756c543ed2..80998794a51 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/TracingStrategyForImplicitConstructorDelegationCall.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/TracingStrategyForImplicitConstructorDelegationCall.kt @@ -31,7 +31,7 @@ import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext import org.jetbrains.kotlin.resolve.calls.inference.InferenceErrorData import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue -import org.jetbrains.kotlin.types.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.KotlinType diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/TracingStrategyImpl.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/TracingStrategyImpl.java index fdfb948fe94..e1b2b88abec 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/TracingStrategyImpl.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/TracingStrategyImpl.java @@ -32,7 +32,7 @@ import org.jetbrains.kotlin.resolve.calls.util.CallResolverUtilKt; import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall; import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall; import org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject; -import org.jetbrains.kotlin.types.ErrorUtils; +import org.jetbrains.kotlin.types.error.ErrorUtils; import org.jetbrains.kotlin.types.KotlinType; import java.util.Collection; diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/dynamicCalls.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/dynamicCalls.kt index d2a3c79a6cd..bd1062ee4e3 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/dynamicCalls.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/dynamicCalls.kt @@ -224,7 +224,7 @@ class DynamicCallableDescriptors(private val storageManager: StorageManager, bui for (funLiteralArg in call.functionLiteralArguments) { addParameter( funLiteralArg, - funLiteralArg.getLambdaExpression()?.let { getFunctionType(it) } ?: TypeUtils.CANT_INFER_FUNCTION_PARAM_TYPE, + funLiteralArg.getLambdaExpression()?.let { getFunctionType(it) } ?: TypeUtils.CANNOT_INFER_FUNCTION_PARAM_TYPE, null) } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinToResolvedCallTransformer.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinToResolvedCallTransformer.kt index 1e4d5ea9f7b..47e651048cb 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinToResolvedCallTransformer.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinToResolvedCallTransformer.kt @@ -7,7 +7,6 @@ package org.jetbrains.kotlin.resolve.calls.tower import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.descriptors.* -import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.diagnostics.Errors import org.jetbrains.kotlin.extensions.internal.CandidateInterceptor import org.jetbrains.kotlin.psi.* @@ -37,6 +36,8 @@ import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluat import org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue import org.jetbrains.kotlin.types.* +import org.jetbrains.kotlin.types.error.ErrorScopeKind +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.expressions.DataFlowAnalyzer import org.jetbrains.kotlin.types.expressions.DoubleColonExpressionResolver import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices @@ -396,7 +397,7 @@ class KotlinToResolvedCallTransformer( val typeConstructor = IntegerLiteralTypeConstructor(value, moduleDescriptor, constant.parameters) return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope( TypeAttributes.Empty, typeConstructor, emptyList(), false, - ErrorUtils.createErrorScope("Scope for number value type ($typeConstructor)", true), + ErrorUtils.createErrorScope(ErrorScopeKind.INTEGER_LITERAL_TYPE_SCOPE, throwExceptions = true, typeConstructor.toString()), ) } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewCallArguments.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewCallArguments.kt index 7f233839584..df22f4d94f4 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewCallArguments.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewCallArguments.kt @@ -26,7 +26,8 @@ import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil import org.jetbrains.kotlin.resolve.scopes.receivers.* -import org.jetbrains.kotlin.types.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorTypeKind +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.UnwrappedType import org.jetbrains.kotlin.types.expressions.KotlinTypeInfo import org.jetbrains.kotlin.utils.addToStdlib.safeAs @@ -71,7 +72,7 @@ class ParseErrorKotlinCallArgument( override val dataFlowInfoAfterThisArgument: DataFlowInfo, ) : ExpressionKotlinCallArgument, SimplePSIKotlinCallArgument() { override val receiver = ReceiverValueWithSmartCastInfo( - TransientReceiver(ErrorUtils.createErrorType("Error type for ParseError-argument $valueArgument")), + TransientReceiver(ErrorUtils.createErrorType(ErrorTypeKind.PARSE_ERROR_ARGUMENT, valueArgument.toString())), typesFromSmartCasts = emptySet(), isStable = true ) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolutionOldInference.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolutionOldInference.kt index 04c6335af46..70c3c272766 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolutionOldInference.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolutionOldInference.kt @@ -49,7 +49,7 @@ import org.jetbrains.kotlin.resolve.scopes.* import org.jetbrains.kotlin.resolve.scopes.receivers.* import org.jetbrains.kotlin.resolve.scopes.utils.canBeResolvedWithoutDeprecation import org.jetbrains.kotlin.types.DeferredType -import org.jetbrains.kotlin.types.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.TypeApproximator import org.jetbrains.kotlin.types.expressions.OperatorConventions import org.jetbrains.kotlin.types.isDynamic diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ResolvedAtomCompleter.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ResolvedAtomCompleter.kt index a7905b1170e..231c6ee469b 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ResolvedAtomCompleter.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ResolvedAtomCompleter.kt @@ -41,6 +41,7 @@ import org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue import org.jetbrains.kotlin.resolve.scopes.receivers.TransientReceiver import org.jetbrains.kotlin.types.* +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.expressions.CoercionStrategy import org.jetbrains.kotlin.types.expressions.DoubleColonExpressionResolver import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/util/CallResolverUtil.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/util/CallResolverUtil.kt index 49b3b835da4..5a115c85bf9 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/util/CallResolverUtil.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/util/CallResolverUtil.kt @@ -43,8 +43,10 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValueWithSmartCastInfo import org.jetbrains.kotlin.resolve.scopes.utils.getImplicitReceiversHierarchy import org.jetbrains.kotlin.types.* +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.TypeUtils.DONT_CARE import org.jetbrains.kotlin.types.checker.KotlinTypeChecker +import org.jetbrains.kotlin.types.error.ErrorScopeKind import org.jetbrains.kotlin.types.expressions.OperatorConventions import org.jetbrains.kotlin.types.typeUtil.contains import org.jetbrains.kotlin.util.buildNotFixedVariablesToPossibleResultType @@ -58,8 +60,9 @@ enum class ResolveArgumentsMode { fun hasUnknownFunctionParameter(type: KotlinType): Boolean { assert(ReflectionTypes.isCallableType(type) || type.isSuspendFunctionType) { "type $type is not a function or property" } - return getParameterArgumentsOfCallableType(type).any { - it.type.contains { TypeUtils.isDontCarePlaceholder(it) } || ErrorUtils.containsUninferredParameter(it.type) + return getParameterArgumentsOfCallableType(type).any { typeProjection -> + typeProjection.type.contains { TypeUtils.isDontCarePlaceholder(it) } + || ErrorUtils.containsUninferredTypeVariable(typeProjection.type) } } @@ -136,7 +139,7 @@ fun getErasedReceiverType(receiverParameterDescriptor: ReceiverParameterDescript return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope( receiverType.attributes, receiverTypeConstructor, fakeTypeArguments, - receiverType.isMarkedNullable, ErrorUtils.createErrorScope("Error scope for erased receiver type", /*throwExceptions=*/true) + receiverType.isMarkedNullable, ErrorUtils.createErrorScope(ErrorScopeKind.ERASED_RECEIVER_TYPE_SCOPE, throwExceptions = true) ) } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/util/resolvedCallUtil.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/util/resolvedCallUtil.kt index 58056d85f79..6c2585432c3 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/util/resolvedCallUtil.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/util/resolvedCallUtil.kt @@ -26,6 +26,7 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver import org.jetbrains.kotlin.resolve.scopes.receivers.ImplicitReceiver import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue import org.jetbrains.kotlin.types.* +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.checker.NewCapturedType import org.jetbrains.kotlin.types.typeUtil.contains @@ -117,7 +118,7 @@ fun ResolvedCall<*>.hasInferredReturnType(): Boolean { if (isNewNotCompleted()) return false val returnType = this.resultingDescriptor.returnType ?: return false - return !returnType.contains { ErrorUtils.isUninferredParameter(it) } + return !returnType.contains { ErrorUtils.isUninferredTypeVariable(it) } } fun CandidateApplicability.toResolutionStatus(): ResolutionStatus = when (this) { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyAnnotations.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyAnnotations.kt index 4abe30f439b..06368a11a2c 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyAnnotations.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyAnnotations.kt @@ -35,7 +35,8 @@ import org.jetbrains.kotlin.resolve.source.toSourceElement 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.error.ErrorTypeKind +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.typeUtil.replaceAnnotations abstract class LazyAnnotationsContext( @@ -97,7 +98,7 @@ class LazyAnnotationDescriptor( annotationType }, onRecursiveCall = { - ErrorUtils.createErrorType("Recursion in type of annotation detected") + ErrorUtils.createErrorType(ErrorTypeKind.RECURSIVE_ANNOTATION_TYPE) } ) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/CommonSupertypes.java b/compiler/frontend/src/org/jetbrains/kotlin/types/CommonSupertypes.java index 7de642c858b..20bd05be0ec 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/CommonSupertypes.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/CommonSupertypes.java @@ -10,12 +10,14 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.builtins.KotlinBuiltIns; import org.jetbrains.kotlin.descriptors.*; -import org.jetbrains.kotlin.descriptors.annotations.Annotations; import org.jetbrains.kotlin.renderer.DescriptorRenderer; import org.jetbrains.kotlin.resolve.DescriptorUtils; import org.jetbrains.kotlin.resolve.scopes.MemberScope; +import org.jetbrains.kotlin.types.error.ErrorScopeKind; +import org.jetbrains.kotlin.types.error.ErrorTypeKind; import org.jetbrains.kotlin.types.typeUtil.TypeUtilsKt; import org.jetbrains.kotlin.utils.DFS; +import org.jetbrains.kotlin.types.error.ErrorUtils; import java.util.*; import java.util.stream.Collectors; @@ -112,7 +114,7 @@ public class CommonSupertypes { iterator.remove(); } if (KotlinTypeKt.isError(type)) { - return ErrorUtils.createErrorType("Supertype of error type " + type); + return ErrorUtils.createErrorType(ErrorTypeKind.SUPER_TYPE_FOR_ERROR_TYPE, type.toString()); } nullable |= type.isMarkedNullable(); } @@ -270,7 +272,7 @@ public class CommonSupertypes { newScope = classifier.getDefaultType().getMemberScope(); } else { - newScope = ErrorUtils.createErrorScope("A scope for common supertype which is not a normal classifier", true); + newScope = ErrorUtils.createErrorScope(ErrorScopeKind.NON_CLASSIFIER_SUPER_TYPE_SCOPE, true); } return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(TypeAttributes.Companion.getEmpty(), constructor, newProjections, nullable, newScope); } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/DeferredType.java b/compiler/frontend/src/org/jetbrains/kotlin/types/DeferredType.java index 2712d0fddfc..2c23fdd234d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/DeferredType.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/DeferredType.java @@ -23,6 +23,8 @@ import org.jetbrains.kotlin.resolve.BindingTrace; import org.jetbrains.kotlin.storage.NotNullLazyValue; import org.jetbrains.kotlin.storage.StorageManager; import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner; +import org.jetbrains.kotlin.types.error.ErrorTypeKind; +import org.jetbrains.kotlin.types.error.ErrorUtils; import org.jetbrains.kotlin.util.Box; import org.jetbrains.kotlin.util.ReenteringLazyValueComputationException; @@ -31,7 +33,7 @@ import static org.jetbrains.kotlin.resolve.BindingContext.DEFERRED_TYPE; public class DeferredType extends WrappedType { private static final Function1 RECURSION_PREVENTER = firstTime -> { if (firstTime) throw new ReenteringLazyValueComputationException(); - return ErrorUtils.createErrorType("Recursive dependency"); + return ErrorUtils.createErrorType(ErrorTypeKind.RECURSIVE_TYPE); }; @NotNull diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/TypeIntersector.java b/compiler/frontend/src/org/jetbrains/kotlin/types/TypeIntersector.java index 22f8c2e6fca..fdaa9af8969 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/TypeIntersector.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/TypeIntersector.java @@ -27,6 +27,8 @@ import org.jetbrains.kotlin.resolve.calls.inference.CallHandle; import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystem; import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilderImpl; import org.jetbrains.kotlin.types.checker.KotlinTypeChecker; +import org.jetbrains.kotlin.types.error.ErrorTypeKind; +import org.jetbrains.kotlin.types.error.ErrorUtils; import java.util.*; @@ -68,7 +70,7 @@ public class TypeIntersector { if (nullabilityStripped.isEmpty()) { // All types were errors - return ErrorUtils.createErrorType("Intersection of error types: " + types); + return ErrorUtils.createErrorType(ErrorTypeKind.INTERSECTION_OF_ERROR_TYPES, types.toString()); } KotlinTypeChecker typeChecker = KotlinTypeChecker.DEFAULT; diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java index 0f7d207c0d3..edfe6bd908f 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java @@ -74,6 +74,8 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue; import org.jetbrains.kotlin.resolve.scopes.utils.ScopeUtilsKt; import org.jetbrains.kotlin.types.*; import org.jetbrains.kotlin.types.checker.KotlinTypeChecker; +import org.jetbrains.kotlin.types.error.ErrorTypeKind; +import org.jetbrains.kotlin.types.error.ErrorUtils; import org.jetbrains.kotlin.types.expressions.ControlStructureTypingUtils.ResolveConstruct; import org.jetbrains.kotlin.types.expressions.typeInfoFactory.TypeInfoFactoryKt; import org.jetbrains.kotlin.types.expressions.unqualifiedSuper.UnqualifiedSuperKt; @@ -792,7 +794,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { if (operationType == KtTokens.PLUSPLUS || operationType == KtTokens.MINUSMINUS) { assert returnType != null : "returnType is null for " + resolutionResults.getResultingDescriptor(); if (KotlinBuiltIns.isUnit(returnType)) { - result = ErrorUtils.createErrorType(components.builtIns.getUnit().getName().asString()); + result = ErrorUtils.createErrorType(ErrorTypeKind.UNIT_RETURN_TYPE_FOR_INC_DEC); context.trace.report(INC_DEC_SHOULD_NOT_RETURN_UNIT.on(operationSign)); } else { @@ -920,7 +922,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { ) { if (ktType == null) return false; - if (KotlinTypeKt.isError(ktType) && !ErrorUtils.isUninferredParameter(ktType)) return false; + if (KotlinTypeKt.isError(ktType) && !ErrorUtils.isUninferredTypeVariable(ktType)) return false; if (!TypeUtils.isNullableType(ktType)) return true; diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingVisitor.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingVisitor.java index dda4dc57f7c..88f350c043d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingVisitor.java @@ -37,11 +37,10 @@ import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope; import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver; import org.jetbrains.kotlin.resolve.scopes.receivers.TransientReceiver; import org.jetbrains.kotlin.serialization.deserialization.SuspendFunctionTypeUtilKt; -import org.jetbrains.kotlin.types.CommonSupertypes; -import org.jetbrains.kotlin.types.ErrorUtils; -import org.jetbrains.kotlin.types.KotlinType; -import org.jetbrains.kotlin.types.TypeUtils; +import org.jetbrains.kotlin.types.*; import org.jetbrains.kotlin.types.checker.KotlinTypeChecker; +import org.jetbrains.kotlin.types.error.ErrorTypeKind; +import org.jetbrains.kotlin.types.error.ErrorUtils; import org.jetbrains.kotlin.types.expressions.ControlStructureTypingUtils.ResolveConstruct; import org.jetbrains.kotlin.types.expressions.typeInfoFactory.TypeInfoFactoryKt; @@ -60,9 +59,6 @@ import static org.jetbrains.kotlin.types.expressions.ExpressionTypingServices.ge import static org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils.*; public class ControlStructureTypingVisitor extends ExpressionTypingVisitor { - - private static final String RETURN_NOT_ALLOWED_MESSAGE = "Return not allowed"; - protected ControlStructureTypingVisitor(@NotNull ExpressionTypingInternals facade) { super(facade); } @@ -433,7 +429,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor { loopScope.addVariableDescriptor(variableDescriptor); KtDestructuringDeclaration multiParameter = loopParameter.getDestructuringDeclaration(); if (multiParameter != null) { - KotlinType elementType = expectedParameterType == null ? ErrorUtils.createErrorType("Loop range has no type") : expectedParameterType; + KotlinType elementType = expectedParameterType == null ? ErrorUtils.createErrorType(ErrorTypeKind.NO_TYPE_FOR_LOOP_RANGE) : expectedParameterType; TransientReceiver iteratorNextAsReceiver = new TransientReceiver(elementType); components.annotationResolver.resolveAnnotationsWithArguments(loopScope, loopParameter.getModifierList(), context.trace); components.destructuringDeclarationResolver.defineLocalVariablesFromDestructuringDeclaration( @@ -479,7 +475,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor { } else { if (expectedParameterType == null) { - expectedParameterType = ErrorUtils.createErrorType("Error"); + expectedParameterType = ErrorUtils.createErrorType(ErrorTypeKind.NO_TYPE_FOR_LOOP_PARAMETER); } variableDescriptor = components.descriptorResolver. resolveLocalVariableDescriptor(loopParameter, expectedParameterType, context.trace, context.scope); @@ -852,7 +848,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor { isClassInitializer(containingFunInfo)) { // Unqualified, in a function literal context.trace.report(RETURN_NOT_ALLOWED.on(expression)); - resultType = ErrorUtils.createErrorType(RETURN_NOT_ALLOWED_MESSAGE); + resultType = ErrorUtils.createErrorType(ErrorTypeKind.RETURN_NOT_ALLOWED); } expectedType = getFunctionExpectedReturnType(containingFunctionDescriptor, (KtElement) containingFunInfo.getSecond(), context); @@ -861,7 +857,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor { else { // Outside a function context.trace.report(RETURN_NOT_ALLOWED.on(expression)); - resultType = ErrorUtils.createErrorType(RETURN_NOT_ALLOWED_MESSAGE); + resultType = ErrorUtils.createErrorType(ErrorTypeKind.RETURN_NOT_ALLOWED); } } else if (labelTargetElement != null) { @@ -872,7 +868,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor { if (!InlineUtil.checkNonLocalReturnUsage(functionDescriptor, expression, context)) { // Qualified, non-local context.trace.report(RETURN_NOT_ALLOWED.on(expression)); - resultType = ErrorUtils.createErrorType(RETURN_NOT_ALLOWED_MESSAGE); + resultType = ErrorUtils.createErrorType(ErrorTypeKind.RETURN_NOT_ALLOWED); } else if (labelTargetElement instanceof KtFunctionLiteral && Objects.equals(expression.getLabelName(), "suspend")) { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/DestructuringDeclarationResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/DestructuringDeclarationResolver.kt index 0ee0f966aa7..1c9cf2a0e28 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/DestructuringDeclarationResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/DestructuringDeclarationResolver.kt @@ -31,7 +31,8 @@ import org.jetbrains.kotlin.resolve.checkers.TrailingCommaChecker import org.jetbrains.kotlin.resolve.scopes.LexicalScope import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue -import org.jetbrains.kotlin.types.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorTypeKind +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.TypeUtils import org.jetbrains.kotlin.types.checker.KotlinTypeChecker @@ -93,7 +94,7 @@ class DestructuringDeclarationResolver( receiver: ReceiverValue?, initializer: KtExpression? ): KotlinType { - fun errorType() = ErrorUtils.createErrorType("$componentName() return type") + fun errorType() = ErrorUtils.createErrorType(ErrorTypeKind.ERROR_TYPE_FOR_DESTRUCTURING_COMPONENT, componentName.toString()) if (receiver == null) return errorType() diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/DoubleColonExpressionResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/DoubleColonExpressionResolver.kt index def5e862eba..8e59c2451d0 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/DoubleColonExpressionResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/DoubleColonExpressionResolver.kt @@ -40,8 +40,10 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.Receiver import org.jetbrains.kotlin.resolve.scopes.receivers.TransientReceiver import org.jetbrains.kotlin.resolve.source.toSourceElement import org.jetbrains.kotlin.types.* +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.TypeUtils.NO_EXPECTED_TYPE import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner +import org.jetbrains.kotlin.types.error.ErrorTypeKind import org.jetbrains.kotlin.types.expressions.FunctionWithBigAritySupport.LanguageVersionDependent import org.jetbrains.kotlin.types.expressions.typeInfoFactory.createTypeInfo import org.jetbrains.kotlin.types.expressions.typeInfoFactory.noTypeInfo @@ -127,7 +129,7 @@ class DoubleColonExpressionResolver( } } - return createTypeInfo(ErrorUtils.createErrorType("Unresolved class"), c) + return createTypeInfo(ErrorUtils.createErrorType(ErrorTypeKind.UNRESOLVED_CLASS_TYPE, expression.toString()), c) } private fun checkClassLiteral( @@ -479,7 +481,7 @@ class DoubleColonExpressionResolver( val classifier = qualifierResolutionResult.classifierDescriptor if (classifier == null) { typeResolver.resolveTypeProjections( - typeResolutionContext, ErrorUtils.createErrorType("No type").constructor, qualifierResolutionResult.allProjections + typeResolutionContext, ErrorUtils.createErrorType(ErrorTypeKind.UNRESOLVED_TYPE, expression.text).constructor, qualifierResolutionResult.allProjections ) return null } @@ -534,7 +536,7 @@ class DoubleColonExpressionResolver( if (callableReference.getReferencedName().isEmpty()) { if (!expression.isEmptyLHS) resolveDoubleColonLHS(expression, c) c.trace.report(UNRESOLVED_REFERENCE.on(callableReference, callableReference)) - val errorType = ErrorUtils.createErrorType("Empty callable reference") + val errorType = ErrorUtils.createErrorType(ErrorTypeKind.EMPTY_CALLABLE_REFERENCE) return dataFlowAnalyzer.createCheckedTypeInfo(errorType, c, expression) } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingServices.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingServices.java index f6cb69a43aa..d04bde07a08 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingServices.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingServices.java @@ -28,7 +28,8 @@ import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValue; import org.jetbrains.kotlin.resolve.calls.tower.KotlinResolutionCallbacksImpl; import org.jetbrains.kotlin.resolve.calls.tower.LambdaContextInfo; import org.jetbrains.kotlin.resolve.scopes.*; -import org.jetbrains.kotlin.types.ErrorUtils; +import org.jetbrains.kotlin.types.error.ErrorTypeKind; +import org.jetbrains.kotlin.types.error.ErrorUtils; import org.jetbrains.kotlin.types.KotlinType; import org.jetbrains.kotlin.types.expressions.typeInfoFactory.TypeInfoFactoryKt; import org.jetbrains.kotlin.util.slicedMap.WritableSlice; @@ -79,7 +80,7 @@ public class ExpressionTypingServices { ) { KotlinType type = getType(scope, expression, expectedType, dataFlowInfo, inferenceSession, trace); - return type != null ? type : ErrorUtils.createErrorType("Type for " + expression.getText()); + return type != null ? type : ErrorUtils.createErrorType(ErrorTypeKind.NO_RECORDED_TYPE, expression.getText()); } @NotNull @@ -244,7 +245,7 @@ public class ExpressionTypingServices { return type; } else { - return ErrorUtils.createErrorType("Error function type"); + return ErrorUtils.createErrorType(ErrorTypeKind.RETURN_TYPE_FOR_FUNCTION); } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingVisitorDispatcher.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingVisitorDispatcher.java index ae838e30968..ddf001aedb0 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingVisitorDispatcher.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingVisitorDispatcher.java @@ -25,7 +25,8 @@ import org.jetbrains.kotlin.resolve.calls.context.CallPosition; import org.jetbrains.kotlin.resolve.scopes.LexicalScopeKind; import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope; import org.jetbrains.kotlin.types.DeferredType; -import org.jetbrains.kotlin.types.ErrorUtils; +import org.jetbrains.kotlin.types.error.ErrorTypeKind; +import org.jetbrains.kotlin.types.error.ErrorUtils; import org.jetbrains.kotlin.types.KotlinType; import org.jetbrains.kotlin.types.expressions.typeInfoFactory.TypeInfoFactoryKt; import org.jetbrains.kotlin.util.KotlinFrontEndException; @@ -124,7 +125,7 @@ public abstract class ExpressionTypingVisitorDispatcher extends KtVisitor - freshTypeConstructor to context.createErrorTypeWithCustomConstructor( - "Uninferred type", + freshTypeConstructor to context.createUninferredType( (typeVariable.typeVariable).freshTypeConstructor() ) } diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolution.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolution.kt index 9e06107d7fa..86495b1a95c 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolution.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolution.kt @@ -17,6 +17,7 @@ import org.jetbrains.kotlin.resolve.calls.tower.* import org.jetbrains.kotlin.resolve.descriptorUtil.isCompanionObject import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValueWithSmartCastInfo import org.jetbrains.kotlin.types.* +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.checker.captureFromExpression import org.jetbrains.kotlin.types.expressions.CoercionStrategy import org.jetbrains.kotlin.types.model.TypeVariance diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt index 402d47dd025..014109e5b95 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt @@ -23,7 +23,7 @@ import org.jetbrains.kotlin.resolve.calls.inference.model.ExpectedTypeConstraint import org.jetbrains.kotlin.resolve.calls.model.* import org.jetbrains.kotlin.resolve.calls.tower.CandidateFactory import org.jetbrains.kotlin.resolve.calls.tower.forceResolution -import org.jetbrains.kotlin.types.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.TypeUtils import org.jetbrains.kotlin.types.UnwrappedType import org.jetbrains.kotlin.types.model.safeSubstitute diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/PostponeArgumentsChecks.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/PostponeArgumentsChecks.kt index 96c4d40c92e..271dbe93e37 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/PostponeArgumentsChecks.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/PostponeArgumentsChecks.kt @@ -22,12 +22,9 @@ import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder import org.jetbrains.kotlin.resolve.calls.inference.components.NewTypeSubstitutor import org.jetbrains.kotlin.resolve.calls.inference.model.* import org.jetbrains.kotlin.resolve.calls.model.* -import org.jetbrains.kotlin.types.AbstractTypeChecker -import org.jetbrains.kotlin.types.ErrorUtils -import org.jetbrains.kotlin.types.KotlinType -import org.jetbrains.kotlin.types.UnwrappedType -import org.jetbrains.kotlin.types.model.TypeVariance -import org.jetbrains.kotlin.types.model.convertVariance +import org.jetbrains.kotlin.types.* +import org.jetbrains.kotlin.types.error.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorTypeKind import org.jetbrains.kotlin.types.typeUtil.builtIns import org.jetbrains.kotlin.utils.addToStdlib.safeAs @@ -119,7 +116,7 @@ private fun extraLambdaInfo( contextReceiverType } else { diagnosticsHolder.addDiagnostic(NotEnoughInformationForLambdaParameter(argument, index)) - ErrorUtils.createErrorType("") + ErrorUtils.createErrorType(ErrorTypeKind.UNINFERRED_LAMBDA_CONTEXT_RECEIVER_TYPE) } } ?: emptyList() val parameters = argument.parametersTypes?.mapIndexed { index, parameterType -> @@ -127,7 +124,7 @@ private fun extraLambdaInfo( parameterType } else { diagnosticsHolder.addDiagnostic(NotEnoughInformationForLambdaParameter(argument, index)) - ErrorUtils.createErrorType("") + ErrorUtils.createErrorType(ErrorTypeKind.UNINFERRED_LAMBDA_PARAMETER_TYPE) } } ?: emptyList() diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt index 3d00a19baa3..0b24afeacad 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt @@ -25,6 +25,7 @@ import org.jetbrains.kotlin.resolve.scopes.LexicalScope import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValueWithSmartCastInfo import org.jetbrains.kotlin.resolve.scopes.utils.parentsWithSelf import org.jetbrains.kotlin.types.* +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.model.KotlinTypeMarker import org.jetbrains.kotlin.types.model.TypeConstructorMarker import org.jetbrains.kotlin.types.model.typeConstructor diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/KotlinConstraintSystemCompleter.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/KotlinConstraintSystemCompleter.kt index 408a44778ab..82af42268a3 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/KotlinConstraintSystemCompleter.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/KotlinConstraintSystemCompleter.kt @@ -12,6 +12,8 @@ import org.jetbrains.kotlin.resolve.calls.components.transformToResolvedLambda import org.jetbrains.kotlin.resolve.calls.inference.model.* import org.jetbrains.kotlin.resolve.calls.model.* import org.jetbrains.kotlin.types.* +import org.jetbrains.kotlin.types.error.ErrorTypeKind +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.model.TypeConstructorMarker import org.jetbrains.kotlin.types.model.TypeVariableMarker import org.jetbrains.kotlin.types.model.safeSubstitute @@ -327,15 +329,15 @@ class KotlinConstraintSystemCompleter( val resultErrorType = when { typeVariable is TypeVariableFromCallableDescriptor -> { - ErrorUtils.createUninferredParameterType(typeVariable.originalTypeParameter) + ErrorUtils.createErrorType(ErrorTypeKind.UNINFERRED_TYPE_VARIABLE, typeVariable.originalTypeParameter.name.asString()) } typeVariable is TypeVariableForLambdaParameterType && typeVariable.atom is LambdaKotlinCallArgument -> { diagnosticsHolder.addDiagnostic( NotEnoughInformationForLambdaParameter(typeVariable.atom, typeVariable.index) ) - ErrorUtils.createErrorType("Cannot infer lambda parameter type") + ErrorUtils.createErrorType(ErrorTypeKind.UNINFERRED_LAMBDA_PARAMETER_TYPE) } - else -> ErrorUtils.createErrorType("Cannot infer type variable $typeVariable") + else -> ErrorUtils.createErrorType(ErrorTypeKind.UNINFERRED_TYPE_VARIABLE, typeVariable.toString()) } fixVariable(typeVariable, resultErrorType, FixVariableConstraintPositionImpl(typeVariable, resolvedAtom)) diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/NewTypeSubstitutor.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/NewTypeSubstitutor.kt index 0caea49d935..6f1b4f79e37 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/NewTypeSubstitutor.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/NewTypeSubstitutor.kt @@ -10,9 +10,11 @@ import org.jetbrains.kotlin.resolve.calls.inference.isCaptured import org.jetbrains.kotlin.resolve.calls.inference.model.TypeVariableFromCallableDescriptor import org.jetbrains.kotlin.resolve.calls.inference.substitute import org.jetbrains.kotlin.types.* +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.checker.NewCapturedType import org.jetbrains.kotlin.types.checker.NewCapturedTypeConstructor import org.jetbrains.kotlin.types.checker.intersectTypes +import org.jetbrains.kotlin.types.error.ErrorTypeKind import org.jetbrains.kotlin.types.model.TypeSubstitutorMarker interface NewTypeSubstitutor : TypeSubstitutorMarker { @@ -185,7 +187,7 @@ interface NewTypeSubstitutor : TypeSubstitutorMarker { val arguments = type.arguments if (parameters.size != arguments.size) { // todo error type or exception? - return ErrorUtils.createErrorType("Inconsistent type: $type (parameters.size = ${parameters.size}, arguments.size = ${arguments.size})") + return ErrorUtils.createErrorType(ErrorTypeKind.TYPE_WITH_MISMATCHED_TYPE_ARGUMENTS_AND_PARAMETERS, type.toString(), parameters.size.toString(), arguments.size.toString()) } val newArguments = arrayOfNulls(arguments.size) diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/CallableReferencesCandidateFactory.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/CallableReferencesCandidateFactory.kt index 32c6182e871..ba69a1ef2b7 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/CallableReferencesCandidateFactory.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/CallableReferencesCandidateFactory.kt @@ -24,6 +24,9 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.DetailedReceiver import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValueWithSmartCastInfo import org.jetbrains.kotlin.types.* +import org.jetbrains.kotlin.types.error.ErrorScopeKind +import org.jetbrains.kotlin.types.error.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorTypeKind import org.jetbrains.kotlin.types.expressions.CoercionStrategy import org.jetbrains.kotlin.types.typeUtil.isUnit import org.jetbrains.kotlin.utils.SmartList @@ -41,7 +44,7 @@ class CallableReferencesCandidateFactory( get() = receiver.receiverValue override fun createErrorCandidate(): CallableReferenceResolutionCandidate { - val errorScope = ErrorUtils.createErrorScope("Error resolution candidate for call $kotlinCall") + val errorScope = ErrorUtils.createErrorScope(ErrorScopeKind.SCOPE_FOR_ERROR_RESOLUTION_CANDIDATE, kotlinCall.toString()) val errorDescriptor = errorScope.getContributedFunctions(kotlinCall.rhsName, scopeTower.location).first() val (reflectionCandidateType, callableReferenceAdaptation) = buildReflectionType( @@ -346,7 +349,7 @@ class CallableReferencesCandidateFactory( } val descriptorReturnType = descriptor.returnType - ?: ErrorUtils.createErrorType("Error return type for descriptor: $descriptor") + ?: ErrorUtils.createErrorType(ErrorTypeKind.RETURN_TYPE, descriptor.toString()) return when (descriptor) { is PropertyDescriptor -> { @@ -397,7 +400,7 @@ class CallableReferencesCandidateFactory( } else -> { assert(!descriptor.isSupportedForCallableReference()) { "${descriptor::class} isn't supported to use in callable references actually, but it's listed in `isSupportedForCallableReference` method" } - ErrorUtils.createErrorType("Unsupported descriptor type: $descriptor") to null + ErrorUtils.createErrorType(ErrorTypeKind.UNSUPPORTED_CALLABLE_REFERENCE_TYPE, descriptor.toString()) to null } } } diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/SimpleCandidateFactory.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/SimpleCandidateFactory.kt index bd19a734044..d807d16312a 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/SimpleCandidateFactory.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/SimpleCandidateFactory.kt @@ -6,7 +6,6 @@ package org.jetbrains.kotlin.resolve.calls.model import org.jetbrains.kotlin.descriptors.CallableDescriptor -import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor import org.jetbrains.kotlin.resolve.calls.components.InferenceSession import org.jetbrains.kotlin.resolve.calls.components.KotlinResolutionCallbacks import org.jetbrains.kotlin.resolve.calls.components.NewConstraintSystemImpl @@ -18,8 +17,9 @@ import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind import org.jetbrains.kotlin.resolve.calls.tower.* import org.jetbrains.kotlin.resolve.descriptorUtil.hasDynamicExtensionAnnotation import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValueWithSmartCastInfo -import org.jetbrains.kotlin.types.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.TypeSubstitutor +import org.jetbrains.kotlin.types.error.ErrorScopeKind import org.jetbrains.kotlin.types.isDynamic class SimpleCandidateFactory( @@ -161,7 +161,7 @@ class SimpleCandidateFactory( } override fun createErrorCandidate(): SimpleResolutionCandidate { - val errorScope = ErrorUtils.createErrorScope("Error resolution candidate for call $kotlinCall") + val errorScope = ErrorUtils.createErrorScope(ErrorScopeKind.SCOPE_FOR_ERROR_RESOLUTION_CANDIDATE, kotlinCall.toString()) val errorDescriptor = if (kotlinCall.callKind == KotlinCallKind.VARIABLE) { errorScope.getContributedVariables(kotlinCall.name, scopeTower.location) } else { diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/TowerLevels.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/TowerLevels.kt index 3f1c33ddea6..66f44f54808 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/TowerLevels.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/TowerLevels.kt @@ -36,6 +36,9 @@ import org.jetbrains.kotlin.resolve.scopes.utils.collectFunctions import org.jetbrains.kotlin.resolve.scopes.utils.collectVariables import org.jetbrains.kotlin.resolve.selectMostSpecificInEachOverridableGroup import org.jetbrains.kotlin.types.* +import org.jetbrains.kotlin.types.error.ErrorScope +import org.jetbrains.kotlin.types.error.ErrorUtils +import org.jetbrains.kotlin.types.error.ThrowingScope import org.jetbrains.kotlin.types.typeUtil.getImmediateSuperclassNotAny import org.jetbrains.kotlin.utils.SmartList import org.jetbrains.kotlin.utils.addIfNotNull @@ -92,8 +95,9 @@ internal class MemberScopeTowerLevel( getMembers: ResolutionScope.(KotlinType?) -> Collection ): Collection { val receiverValue = dispatchReceiver.receiverValue + val memberScope = receiverValue.type.memberScope - if (receiverValue.type is AbstractStubType && receiverValue.type.memberScope is ErrorUtils.ErrorScope) { + if (receiverValue.type is AbstractStubType && memberScope is ErrorScope && memberScope !is ThrowingScope) { return arrayListOf() } @@ -215,7 +219,8 @@ internal class ContextReceiversGroupScopeTowerLevel( for (contextReceiver in contextReceiversGroup) { val receiverValue = contextReceiver.receiverValue - if (receiverValue.type is AbstractStubType && receiverValue.type.memberScope is ErrorUtils.ErrorScope) { + val memberScope = receiverValue.type.memberScope + if (receiverValue.type is AbstractStubType && memberScope is ErrorScope && memberScope !is ThrowingScope) { return arrayListOf() } receiverValue.type.memberScope.getMembers(receiverValue.type).mapTo(result) { diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/scopes/utils/ScopeUtils.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/scopes/utils/ScopeUtils.kt index 64b7f4ac944..63d81c95700 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/scopes/utils/ScopeUtils.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/scopes/utils/ScopeUtils.kt @@ -21,7 +21,9 @@ import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.incremental.components.NoLookupLocation import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.scopes.* -import org.jetbrains.kotlin.types.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorClassDescriptor +import org.jetbrains.kotlin.types.error.ErrorEntity +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.util.collectionUtils.concat import org.jetbrains.kotlin.utils.Printer import org.jetbrains.kotlin.utils.SmartList @@ -303,7 +305,7 @@ class ErrorLexicalScope : LexicalScope { override val parent: HierarchicalScope? = null override fun printStructure(p: Printer) { - p.print("") + p.print(ErrorEntity.PARENT_OF_ERROR_SCOPE.debugText) } override fun getContributedClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? = null @@ -319,10 +321,11 @@ class ErrorLexicalScope : LexicalScope { } override fun printStructure(p: Printer) { - p.print("") + p.print(ErrorEntity.ERROR_SCOPE.debugText) } - override val ownerDescriptor: DeclarationDescriptor = ErrorUtils.createErrorClass("") + override val ownerDescriptor: DeclarationDescriptor = + ErrorClassDescriptor(Name.special(ErrorEntity.ERROR_CLASS.debugText.format("unknown"))) override val isOwnerDescriptorAccessibleByLabel: Boolean = false override val implicitReceiver: ReceiverParameterDescriptor? = null override val contextReceiversGroup: List = emptyList() diff --git a/compiler/serialization/src/org/jetbrains/kotlin/serialization/AnnotationSerializer.kt b/compiler/serialization/src/org/jetbrains/kotlin/serialization/AnnotationSerializer.kt index 0f8aff078d7..37a4202d810 100644 --- a/compiler/serialization/src/org/jetbrains/kotlin/serialization/AnnotationSerializer.kt +++ b/compiler/serialization/src/org/jetbrains/kotlin/serialization/AnnotationSerializer.kt @@ -26,7 +26,7 @@ import org.jetbrains.kotlin.metadata.ProtoBuf.Annotation.Argument.Value.Type import org.jetbrains.kotlin.metadata.deserialization.Flags import org.jetbrains.kotlin.resolve.constants.* import org.jetbrains.kotlin.resolve.descriptorUtil.annotationClass -import org.jetbrains.kotlin.types.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.KotlinType open class AnnotationSerializer(private val stringTable: DescriptorAwareStringTable) { diff --git a/compiler/serialization/src/org/jetbrains/kotlin/serialization/DescriptorAwareStringTable.kt b/compiler/serialization/src/org/jetbrains/kotlin/serialization/DescriptorAwareStringTable.kt index 00b73ed0d40..93fbcd79fae 100644 --- a/compiler/serialization/src/org/jetbrains/kotlin/serialization/DescriptorAwareStringTable.kt +++ b/compiler/serialization/src/org/jetbrains/kotlin/serialization/DescriptorAwareStringTable.kt @@ -10,7 +10,7 @@ import org.jetbrains.kotlin.metadata.serialization.StringTable import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.renderer.DescriptorRenderer import org.jetbrains.kotlin.resolve.descriptorUtil.classId -import org.jetbrains.kotlin.types.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorUtils interface DescriptorAwareStringTable : StringTable { fun getQualifiedClassNameIndex(classId: ClassId): Int = diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/resolve/ExpectedResolveData.java b/compiler/tests-common/tests/org/jetbrains/kotlin/resolve/ExpectedResolveData.java index 5f6b4f0ff72..3ed4d034029 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/resolve/ExpectedResolveData.java +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/resolve/ExpectedResolveData.java @@ -34,7 +34,7 @@ import org.jetbrains.kotlin.name.Name; import org.jetbrains.kotlin.psi.*; import org.jetbrains.kotlin.renderer.DescriptorRenderer; import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil; -import org.jetbrains.kotlin.types.ErrorUtils; +import org.jetbrains.kotlin.types.error.ErrorUtils; import org.jetbrains.kotlin.types.KotlinType; import org.jetbrains.kotlin.types.TypeConstructor; diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/resolve/constraintSystem/AbstractConstraintSystemTest.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/resolve/constraintSystem/AbstractConstraintSystemTest.kt index 5ef4406b9d0..90e370d7463 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/resolve/constraintSystem/AbstractConstraintSystemTest.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/resolve/constraintSystem/AbstractConstraintSystemTest.kt @@ -30,7 +30,7 @@ import org.jetbrains.kotlin.test.KotlinTestUtils import org.jetbrains.kotlin.test.KotlinTestWithEnvironment import org.jetbrains.kotlin.test.util.KtTestUtil import org.jetbrains.kotlin.tests.di.createContainerForTests -import org.jetbrains.kotlin.types.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.Variance import java.io.File diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/MultiModuleJavaAnalysisCustomTest.kt b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/MultiModuleJavaAnalysisCustomTest.kt index a56619df5f1..43abf2a84d3 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/MultiModuleJavaAnalysisCustomTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/MultiModuleJavaAnalysisCustomTest.kt @@ -54,7 +54,7 @@ import org.jetbrains.kotlin.test.ConfigurationKind import org.jetbrains.kotlin.test.KotlinTestUtils import org.jetbrains.kotlin.test.TestJdkKind import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase -import org.jetbrains.kotlin.types.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorUtils import org.junit.Assert import java.io.File diff --git a/core/compiler.common/src/org/jetbrains/kotlin/types/model/TypeSystemContext.kt b/core/compiler.common/src/org/jetbrains/kotlin/types/model/TypeSystemContext.kt index 89e24ecb422..6c3c30f999a 100644 --- a/core/compiler.common/src/org/jetbrains/kotlin/types/model/TypeSystemContext.kt +++ b/core/compiler.common/src/org/jetbrains/kotlin/types/model/TypeSystemContext.kt @@ -87,7 +87,7 @@ interface TypeSystemTypeFactoryContext: TypeSystemBuiltInsContext { fun createStarProjection(typeParameter: TypeParameterMarker): TypeArgumentMarker fun createErrorType(debugName: String): SimpleTypeMarker - fun createErrorTypeWithCustomConstructor(debugName: String, constructor: TypeConstructorMarker): KotlinTypeMarker + fun createUninferredType(constructor: TypeConstructorMarker): KotlinTypeMarker } /** diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/components/JavaAnnotationMapper.kt b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/components/JavaAnnotationMapper.kt index d26112eb824..75b62a86355 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/components/JavaAnnotationMapper.kt +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/components/JavaAnnotationMapper.kt @@ -34,7 +34,8 @@ import org.jetbrains.kotlin.resolve.constants.ConstantValue import org.jetbrains.kotlin.resolve.constants.EnumValue import org.jetbrains.kotlin.resolve.constants.StringValue import org.jetbrains.kotlin.storage.getValue -import org.jetbrains.kotlin.types.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorTypeKind +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.SimpleType import java.util.* @@ -159,7 +160,7 @@ object JavaAnnotationTargetMapper { JavaAnnotationMapper.TARGET_ANNOTATION_ALLOWED_TARGETS, module.builtIns.getBuiltInClassByFqName(StandardNames.FqNames.target) ) - parameterDescriptor?.type ?: ErrorUtils.createErrorType("Error: AnnotationTarget[]") + parameterDescriptor?.type ?: ErrorUtils.createErrorType(ErrorTypeKind.UNMAPPED_ANNOTATION_TARGET_TYPE) } } diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaAnnotationDescriptor.kt b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaAnnotationDescriptor.kt index f37c80ddd3b..d7cf2148afd 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaAnnotationDescriptor.kt +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaAnnotationDescriptor.kt @@ -33,7 +33,8 @@ import org.jetbrains.kotlin.renderer.DescriptorRenderer import org.jetbrains.kotlin.resolve.constants.* import org.jetbrains.kotlin.resolve.descriptorUtil.annotationClass import org.jetbrains.kotlin.storage.getValue -import org.jetbrains.kotlin.types.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorTypeKind +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.Variance import org.jetbrains.kotlin.types.isError @@ -47,7 +48,8 @@ class LazyJavaAnnotationDescriptor( } override val type by c.storageManager.createLazyValue { - val fqName = fqName ?: return@createLazyValue ErrorUtils.createErrorType("No fqName: $javaAnnotation") + val fqName = fqName + ?: return@createLazyValue ErrorUtils.createErrorType(ErrorTypeKind.NOT_FOUND_FQNAME_FOR_JAVA_ANNOTATION, javaAnnotation.toString()) val annotationClass = JavaToKotlinClassMapper.mapJavaToKotlin(fqName, c.module.builtIns) ?: javaAnnotation.resolve()?.let { javaClass -> c.components.moduleClassResolver.resolveClass(javaClass) } ?: createTypeForMissingDependencies(fqName) @@ -86,7 +88,7 @@ class LazyJavaAnnotationDescriptor( // Try to load annotation arguments even if the annotation class is not found ?: c.components.module.builtIns.getArrayType( Variance.INVARIANT, - ErrorUtils.createErrorType("Unknown array element type") + ErrorUtils.createErrorType(ErrorTypeKind.UNKNOWN_ARRAY_ELEMENT_TYPE_OF_ANNOTATION_ARGUMENT) ) val values = elements.map { argument -> diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/types/JavaTypeResolver.kt b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/types/JavaTypeResolver.kt index fba789bc422..ab58793a55d 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/types/JavaTypeResolver.kt +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/types/JavaTypeResolver.kt @@ -32,6 +32,8 @@ import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.Variance.* +import org.jetbrains.kotlin.types.error.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorTypeKind import org.jetbrains.kotlin.types.typeUtil.* import org.jetbrains.kotlin.utils.sure @@ -92,7 +94,7 @@ class JavaTypeResolver( } private fun transformJavaClassifierType(javaType: JavaClassifierType, attr: JavaTypeAttributes): KotlinType { - fun errorType() = ErrorUtils.createErrorType("Unresolved java class ${javaType.presentableText}") + fun errorType() = ErrorUtils.createErrorType(ErrorTypeKind.UNRESOLVED_JAVA_CLASS, javaType.presentableText) val useFlexible = !attr.isForAnnotationParameter && attr.howThisTypeIsUsed != SUPERTYPE val isRaw = javaType.isRaw @@ -256,7 +258,9 @@ class JavaTypeResolver( if (typeParameters.size != javaType.typeArguments.size) { // Most of the time this means there is an error in the Java code - return typeParameters.map { p -> TypeProjectionImpl(ErrorUtils.createErrorType(p.name.asString())) }.toList() + return typeParameters.map { p -> + TypeProjectionImpl(ErrorUtils.createErrorType(ErrorTypeKind.MISSED_TYPE_ARGUMENT_FOR_TYPE_PARAMETER, p.name.asString())) + }.toList() } return javaType.typeArguments.withIndex().map { indexedArgument -> val (i, javaTypeArgument) = indexedArgument diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/types/RawType.kt b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/types/RawType.kt index 091bd86291a..be943a8b10b 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/types/RawType.kt +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/types/RawType.kt @@ -19,7 +19,6 @@ package org.jetbrains.kotlin.load.java.lazy.types import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor -import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.load.java.components.TypeUsage import org.jetbrains.kotlin.renderer.DescriptorRenderer import org.jetbrains.kotlin.renderer.DescriptorRendererOptions @@ -30,6 +29,8 @@ import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.checker.KotlinTypeChecker import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner import org.jetbrains.kotlin.types.TypeRefinement +import org.jetbrains.kotlin.types.error.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorTypeKind import org.jetbrains.kotlin.types.typeUtil.builtIns class RawTypeImpl private constructor(lowerBound: SimpleType, upperBound: SimpleType, disableAssertion: Boolean) : @@ -149,7 +150,9 @@ internal class RawSubstitution(typeParameterUpperBoundEraser: TypeParameterUpper ) to false } - if (type.isError) return ErrorUtils.createErrorType("Raw error type: ${type.constructor}") to false + if (type.isError) { + return ErrorUtils.createErrorType(ErrorTypeKind.ERROR_RAW_TYPE, type.constructor.toString()) to false + } val memberScope = declaration.getMemberScope(this) return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope( diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/types/TypeParameterUpperBoundEraser.kt b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/types/TypeParameterUpperBoundEraser.kt index 115d70c47d4..26de1695624 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/types/TypeParameterUpperBoundEraser.kt +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/types/TypeParameterUpperBoundEraser.kt @@ -9,6 +9,8 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor import org.jetbrains.kotlin.storage.LockBasedStorageManager import org.jetbrains.kotlin.types.* +import org.jetbrains.kotlin.types.error.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorTypeKind import org.jetbrains.kotlin.types.typeUtil.extractTypeParametersFromUpperBounds import org.jetbrains.kotlin.types.typeUtil.replaceArgumentsWithStarProjectionOrMapped import org.jetbrains.kotlin.types.typeUtil.replaceArgumentsWithStarProjections @@ -16,7 +18,7 @@ import org.jetbrains.kotlin.types.typeUtil.replaceArgumentsWithStarProjections internal class TypeParameterUpperBoundEraser(rawSubstitution: RawSubstitution? = null) { private val storage = LockBasedStorageManager("Type parameter upper bound erasion results") private val erroneousErasedBound by lazy { - ErrorUtils.createErrorType("Can't compute erased upper bound of type parameter `$this`") + ErrorUtils.createErrorType(ErrorTypeKind.CANNOT_COMPUTE_ERASED_BOUND, this.toString()) } private val rawSubstitution = rawSubstitution ?: RawSubstitution(this) diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/JavaFlexibleTypeDeserializer.kt b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/JavaFlexibleTypeDeserializer.kt index e269842a5db..4542eddea7e 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/JavaFlexibleTypeDeserializer.kt +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/JavaFlexibleTypeDeserializer.kt @@ -21,15 +21,14 @@ import org.jetbrains.kotlin.metadata.ProtoBuf import org.jetbrains.kotlin.metadata.jvm.JvmProtoBuf import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmProtoBufUtil import org.jetbrains.kotlin.serialization.deserialization.FlexibleTypeDeserializer -import org.jetbrains.kotlin.types.ErrorUtils -import org.jetbrains.kotlin.types.KotlinType -import org.jetbrains.kotlin.types.KotlinTypeFactory -import org.jetbrains.kotlin.types.SimpleType +import org.jetbrains.kotlin.types.* +import org.jetbrains.kotlin.types.error.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorTypeKind object JavaFlexibleTypeDeserializer : FlexibleTypeDeserializer { override fun create(proto: ProtoBuf.Type, flexibleId: String, lowerBound: SimpleType, upperBound: SimpleType): KotlinType { if (flexibleId != JvmProtoBufUtil.PLATFORM_TYPE_ID) { - return ErrorUtils.createErrorType("Error java flexible type with id: $flexibleId. ($lowerBound..$upperBound)") + return ErrorUtils.createErrorType(ErrorTypeKind.ERROR_FLEXIBLE_TYPE, flexibleId, lowerBound.toString(), upperBound.toString()) } if (proto.hasExtension(JvmProtoBuf.isRaw)) { return RawTypeImpl(lowerBound, upperBound) diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/descriptorBasedTypeSignatureMapping.kt b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/descriptorBasedTypeSignatureMapping.kt index 02cb3a6c48e..4b6060fe5fa 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/descriptorBasedTypeSignatureMapping.kt +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/descriptorBasedTypeSignatureMapping.kt @@ -12,6 +12,7 @@ import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.name.SpecialNames import org.jetbrains.kotlin.resolve.isInlineClass import org.jetbrains.kotlin.types.* +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.checker.SimpleClassicTypeSystemContext import org.jetbrains.kotlin.types.typeUtil.makeNullable import org.jetbrains.kotlin.types.typeUtil.replaceArgumentsWithStarProjections diff --git a/core/descriptors/src/org/jetbrains/kotlin/builtins/suspendFunctionTypes.kt b/core/descriptors/src/org/jetbrains/kotlin/builtins/suspendFunctionTypes.kt index 1a3928bc89f..0c4632f663d 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/builtins/suspendFunctionTypes.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/builtins/suspendFunctionTypes.kt @@ -18,12 +18,13 @@ import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.storage.LockBasedStorageManager import org.jetbrains.kotlin.types.* +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.typeUtil.asTypeProjection import org.jetbrains.kotlin.types.typeUtil.builtIns private val FAKE_CONTINUATION_CLASS_DESCRIPTOR = MutableClassDescriptor( - EmptyPackageFragmentDescriptor(ErrorUtils.getErrorModule(), COROUTINES_PACKAGE_FQ_NAME), + EmptyPackageFragmentDescriptor(ErrorUtils.errorModule, COROUTINES_PACKAGE_FQ_NAME), ClassKind.INTERFACE, /* isInner = */ false, /* isExternal = */ false, CONTINUATION_INTERFACE_FQ_NAME.shortName(), SourceElement.NO_SOURCE, LockBasedStorageManager.NO_LOCKS ).apply { diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/ModuleDescriptor.kt b/core/descriptors/src/org/jetbrains/kotlin/descriptors/ModuleDescriptor.kt index 7222cad74c5..e9ba5d911ef 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/ModuleDescriptor.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/ModuleDescriptor.kt @@ -37,7 +37,7 @@ interface ModuleDescriptor : DeclarationDescriptor { fun shouldSeeInternalsOf(targetModule: ModuleDescriptor): Boolean - override fun accept(visitor: DeclarationDescriptorVisitor, data: D): R { + override fun accept(visitor: DeclarationDescriptorVisitor, data: D): R? { return visitor.visitModuleDeclaration(this, data) } diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/annotations/AnnotationDescriptor.kt b/core/descriptors/src/org/jetbrains/kotlin/descriptors/annotations/AnnotationDescriptor.kt index 6dda57cb627..e484cfd60a1 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/annotations/AnnotationDescriptor.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/annotations/AnnotationDescriptor.kt @@ -22,7 +22,7 @@ import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.constants.ConstantValue import org.jetbrains.kotlin.resolve.descriptorUtil.annotationClass import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameOrNull -import org.jetbrains.kotlin.types.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.getAbbreviation import org.jetbrains.kotlin.types.model.AnnotationMarker diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/AbstractTypeParameterDescriptor.java b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/AbstractTypeParameterDescriptor.java index cadc8937fee..2a7e97a5a8b 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/AbstractTypeParameterDescriptor.java +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/AbstractTypeParameterDescriptor.java @@ -31,6 +31,8 @@ import org.jetbrains.kotlin.resolve.scopes.TypeIntersectionScope; import org.jetbrains.kotlin.storage.NotNullLazyValue; import org.jetbrains.kotlin.storage.StorageManager; import org.jetbrains.kotlin.types.*; +import org.jetbrains.kotlin.types.error.ErrorTypeKind; +import org.jetbrains.kotlin.types.error.ErrorUtils; import java.util.Collection; import java.util.Collections; @@ -221,7 +223,7 @@ public abstract class AbstractTypeParameterDescriptor extends DeclarationDescrip @Nullable @Override protected KotlinType defaultSupertypeIfEmpty() { - return ErrorUtils.createErrorType("Cyclic upper bounds"); + return ErrorUtils.createErrorType(ErrorTypeKind.CYCLIC_UPPER_BOUNDS); } @Override diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/typeParameterUtils.kt b/core/descriptors/src/org/jetbrains/kotlin/descriptors/typeParameterUtils.kt index 4bdd8ab8b4a..46c03781b3a 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/typeParameterUtils.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/typeParameterUtils.kt @@ -18,7 +18,7 @@ package org.jetbrains.kotlin.descriptors import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.descriptorUtil.parents -import org.jetbrains.kotlin.types.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.TypeProjection import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull diff --git a/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt b/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt index 0b67e2d9f0b..6ca57ae857c 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt @@ -23,8 +23,9 @@ import org.jetbrains.kotlin.resolve.constants.KClassValue import org.jetbrains.kotlin.resolve.descriptorUtil.annotationClass import org.jetbrains.kotlin.resolve.descriptorUtil.declaresOrInheritsDefaultValue import org.jetbrains.kotlin.types.* -import org.jetbrains.kotlin.types.ErrorUtils.UninferredParameterTypeConstructor -import org.jetbrains.kotlin.types.TypeUtils.CANT_INFER_FUNCTION_PARAM_TYPE +import org.jetbrains.kotlin.types.TypeUtils.CANNOT_INFER_FUNCTION_PARAM_TYPE +import org.jetbrains.kotlin.types.error.* +import org.jetbrains.kotlin.types.typeUtil.isUnresolvedType import org.jetbrains.kotlin.util.capitalizeDecapitalize.toLowerCaseAsciiOnly internal class DescriptorRendererImpl( @@ -153,13 +154,13 @@ internal class DescriptorRendererImpl( } private fun StringBuilder.renderSimpleType(type: SimpleType) { - if (type == CANT_INFER_FUNCTION_PARAM_TYPE || TypeUtils.isDontCarePlaceholder(type)) { + if (type == CANNOT_INFER_FUNCTION_PARAM_TYPE || TypeUtils.isDontCarePlaceholder(type)) { append("???") return } - if (ErrorUtils.isUninferredParameter(type)) { + if (ErrorUtils.isUninferredTypeVariable(type)) { if (uninferredTypeParameterAsName) { - append(renderError((type.constructor as UninferredParameterTypeConstructor).typeParameterDescriptor.name.toString())) + append(renderError((type.constructor as ErrorTypeConstructor).getParam(0))) } else { append("???") } @@ -239,11 +240,11 @@ internal class DescriptorRendererImpl( when { type.isError -> { - if (type is UnresolvedType && presentableUnresolvedTypes) { - append(type.presentableName) + if (isUnresolvedType(type) && presentableUnresolvedTypes) { + append(type.debugMessage) } else { if (type is ErrorType && !informativeErrorType) { - append(type.presentableName) + append(type.debugMessage) } else { append(type.constructor.toString()) // Debug name of an error type is more informative } diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorUtils.java b/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorUtils.java index 379227e0a53..0e8700da60e 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorUtils.java +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorUtils.java @@ -22,6 +22,7 @@ import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter; import org.jetbrains.kotlin.resolve.scopes.MemberScope; import org.jetbrains.kotlin.types.*; import org.jetbrains.kotlin.types.checker.KotlinTypeChecker; +import org.jetbrains.kotlin.types.error.ErrorUtils; import java.util.*; diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/calls/inference/CapturedTypeConstructor.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/calls/inference/CapturedTypeConstructor.kt index 3fa2a6ecef0..4fdf1886fe7 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/calls/inference/CapturedTypeConstructor.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/calls/inference/CapturedTypeConstructor.kt @@ -18,10 +18,10 @@ package org.jetbrains.kotlin.resolve.calls.inference import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor -import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.resolve.scopes.MemberScope import org.jetbrains.kotlin.storage.LockBasedStorageManager import org.jetbrains.kotlin.types.* +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.Variance.IN_VARIANCE import org.jetbrains.kotlin.types.Variance.OUT_VARIANCE import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner @@ -29,6 +29,7 @@ import org.jetbrains.kotlin.types.checker.NewCapturedTypeConstructor import org.jetbrains.kotlin.types.model.CapturedTypeConstructorMarker import org.jetbrains.kotlin.types.model.CapturedTypeMarker import org.jetbrains.kotlin.types.TypeRefinement +import org.jetbrains.kotlin.types.error.ErrorScopeKind import org.jetbrains.kotlin.types.typeUtil.builtIns interface CapturedTypeConstructor : CapturedTypeConstructorMarker, TypeConstructor { @@ -83,7 +84,8 @@ class CapturedType( override val memberScope: MemberScope get() = ErrorUtils.createErrorScope( - "No member resolution should be done on captured type, it used only during constraint system resolution", true + ErrorScopeKind.CAPTURED_TYPE_SCOPE, + throwExceptions = true ) override val subTypeRepresentative: KotlinType diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/CompileTimeConstant.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/CompileTimeConstant.kt index 89b0cd850fd..e29d2292c7c 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/CompileTimeConstant.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/CompileTimeConstant.kt @@ -19,9 +19,10 @@ package org.jetbrains.kotlin.resolve.constants import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.builtins.StandardNames import org.jetbrains.kotlin.descriptors.ModuleDescriptor -import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.descriptors.findClassAcrossModuleDependencies import org.jetbrains.kotlin.types.* +import org.jetbrains.kotlin.types.error.ErrorScopeKind +import org.jetbrains.kotlin.types.error.ErrorUtils interface CompileTimeConstant { val isError: Boolean @@ -198,7 +199,7 @@ class IntegerValueTypeConstant( val unknownIntegerType = KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope( TypeAttributes.Empty, typeConstructor, emptyList(), false, - ErrorUtils.createErrorScope("Scope for number value type ($typeConstructor)", true) + ErrorUtils.createErrorScope(ErrorScopeKind.INTEGER_LITERAL_TYPE_SCOPE, throwExceptions = true, typeConstructor.toString()) ) fun getType(expectedType: KotlinType): KotlinType = diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/constantValues.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/constantValues.kt index 096fcdb5493..94ca8b2878e 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/constantValues.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/constantValues.kt @@ -23,13 +23,14 @@ import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor -import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.descriptors.findClassAcrossModuleDependencies import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.descriptorUtil.classId import org.jetbrains.kotlin.types.* +import org.jetbrains.kotlin.types.error.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorTypeKind import org.jetbrains.kotlin.types.typeUtil.replaceArgumentsWithStarProjections abstract class ConstantValue(open val value: T) { @@ -120,7 +121,7 @@ class DoubleValue(value: Double) : ConstantValue(value) { class EnumValue(val enumClassId: ClassId, val enumEntryName: Name) : ConstantValue>(enumClassId to enumEntryName) { override fun getType(module: ModuleDescriptor): KotlinType = module.findClassAcrossModuleDependencies(enumClassId)?.takeIf(DescriptorUtils::isEnumClass)?.defaultType - ?: ErrorUtils.createErrorType("Containing class for error-class based enum entry $enumClassId.$enumEntryName") + ?: ErrorUtils.createErrorType(ErrorTypeKind.ERROR_ENUM_TYPE, enumClassId.toString(), enumEntryName.toString()) override fun accept(visitor: AnnotationArgumentVisitor, data: D) = visitor.visitEnumValue(this, data) @@ -139,7 +140,7 @@ abstract class ErrorValue : ConstantValue(Unit) { override fun accept(visitor: AnnotationArgumentVisitor, data: D) = visitor.visitErrorValue(this, data) class ErrorValueWithMessage(val message: String) : ErrorValue() { - override fun getType(module: ModuleDescriptor) = ErrorUtils.createErrorType(message) + override fun getType(module: ModuleDescriptor) = ErrorUtils.createErrorType(ErrorTypeKind.ERROR_CONSTANT_VALUE, message) override fun toString() = message } @@ -188,7 +189,7 @@ class KClassValue(value: Value) : ConstantValue(value) { is Value.NormalClass -> { val (classId, arrayDimensions) = value.value val descriptor = module.findClassAcrossModuleDependencies(classId) - ?: return ErrorUtils.createErrorType("Unresolved type: $classId (arrayDimensions=$arrayDimensions)") + ?: return ErrorUtils.createErrorType(ErrorTypeKind.UNRESOLVED_KCLASS_CONSTANT_VALUE, classId.toString(), arrayDimensions.toString()) // If this value refers to a class named test.Foo.Bar where both Foo and Bar have generic type parameters, // we're constructing a type `test.Foo<*>.Bar<*>` below @@ -266,7 +267,7 @@ class StringValue(value: String) : ConstantValue(value) { class UByteValue(byteValue: Byte) : UnsignedValueConstant(byteValue) { override fun getType(module: ModuleDescriptor): KotlinType { return module.findClassAcrossModuleDependencies(StandardNames.FqNames.uByte)?.defaultType - ?: ErrorUtils.createErrorType("Unsigned type UByte not found") + ?: ErrorUtils.createErrorType(ErrorTypeKind.NOT_FOUND_UNSIGNED_TYPE, "UByte") } override fun accept(visitor: AnnotationArgumentVisitor, data: D): R = visitor.visitUByteValue(this, data) @@ -279,7 +280,7 @@ class UByteValue(byteValue: Byte) : UnsignedValueConstant(byteValue) { class UShortValue(shortValue: Short) : UnsignedValueConstant(shortValue) { override fun getType(module: ModuleDescriptor): KotlinType { return module.findClassAcrossModuleDependencies(StandardNames.FqNames.uShort)?.defaultType - ?: ErrorUtils.createErrorType("Unsigned type UShort not found") + ?: ErrorUtils.createErrorType(ErrorTypeKind.NOT_FOUND_UNSIGNED_TYPE, "UShort") } override fun accept(visitor: AnnotationArgumentVisitor, data: D): R = visitor.visitUShortValue(this, data) @@ -292,7 +293,7 @@ class UShortValue(shortValue: Short) : UnsignedValueConstant(shortValue) class UIntValue(intValue: Int) : UnsignedValueConstant(intValue) { override fun getType(module: ModuleDescriptor): KotlinType { return module.findClassAcrossModuleDependencies(StandardNames.FqNames.uInt)?.defaultType - ?: ErrorUtils.createErrorType("Unsigned type UInt not found") + ?: ErrorUtils.createErrorType(ErrorTypeKind.NOT_FOUND_UNSIGNED_TYPE, "UInt") } override fun accept(visitor: AnnotationArgumentVisitor, data: D) = visitor.visitUIntValue(this, data) @@ -305,7 +306,7 @@ class UIntValue(intValue: Int) : UnsignedValueConstant(intValue) { class ULongValue(longValue: Long) : UnsignedValueConstant(longValue) { override fun getType(module: ModuleDescriptor): KotlinType { return module.findClassAcrossModuleDependencies(StandardNames.FqNames.uLong)?.defaultType - ?: ErrorUtils.createErrorType("Unsigned type ULong not found") + ?: ErrorUtils.createErrorType(ErrorTypeKind.NOT_FOUND_UNSIGNED_TYPE, "ULong") } override fun accept(visitor: AnnotationArgumentVisitor, data: D): R = visitor.visitULongValue(this, data) diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/AbstractTypeConstructor.kt b/core/descriptors/src/org/jetbrains/kotlin/types/AbstractTypeConstructor.kt index 84a1a5f31f7..96001434f20 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/AbstractTypeConstructor.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/AbstractTypeConstructor.kt @@ -21,6 +21,7 @@ import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.storage.StorageManager import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner import org.jetbrains.kotlin.types.checker.refineTypes +import org.jetbrains.kotlin.types.error.ErrorUtils abstract class AbstractTypeConstructor(storageManager: StorageManager) : ClassifierBasedTypeConstructor() { override fun getSupertypes() = supertypes().supertypesWithoutCycles @@ -70,12 +71,12 @@ abstract class AbstractTypeConstructor(storageManager: StorageManager) : Classif // The first one is used for computation of neighbours in supertypes graph (see Companion.computeNeighbours) private class Supertypes(val allSupertypes: Collection) { // initializer is only needed as a stub for case when 'getSupertypes' is called while 'supertypes' are being calculated - var supertypesWithoutCycles: List = listOf(ErrorUtils.ERROR_TYPE_FOR_LOOP_IN_SUPERTYPES) + var supertypesWithoutCycles: List = listOf(ErrorUtils.errorTypeForLoopInSupertypes) } private val supertypes = storageManager.createLazyValueWithPostCompute( { Supertypes(computeSupertypes()) }, - { Supertypes(listOf(ErrorUtils.ERROR_TYPE_FOR_LOOP_IN_SUPERTYPES)) }, + { Supertypes(listOf(ErrorUtils.errorTypeForLoopInSupertypes)) }, { supertypes -> // It's important that loops disconnection begins in post-compute phase, because it guarantees that // when we start calculation supertypes of supertypes (for computing neighbours), they start their disconnection loop process diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/ClassifierBasedTypeConstructor.kt b/core/descriptors/src/org/jetbrains/kotlin/types/ClassifierBasedTypeConstructor.kt index 46d159f21c4..f121a7fce01 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/ClassifierBasedTypeConstructor.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/ClassifierBasedTypeConstructor.kt @@ -10,6 +10,7 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor import org.jetbrains.kotlin.resolve.DescriptorUtils +import org.jetbrains.kotlin.types.error.ErrorUtils abstract class ClassifierBasedTypeConstructor : TypeConstructor { private var hashCode = 0 diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/ErrorType.kt b/core/descriptors/src/org/jetbrains/kotlin/types/ErrorType.kt deleted file mode 100644 index c0a945ef2b9..00000000000 --- a/core/descriptors/src/org/jetbrains/kotlin/types/ErrorType.kt +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2010-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.types - -import org.jetbrains.kotlin.descriptors.annotations.Annotations -import org.jetbrains.kotlin.resolve.scopes.MemberScope -import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner - -open class ErrorType @JvmOverloads internal constructor( - override val constructor: TypeConstructor, - override val memberScope: MemberScope, - override val arguments: List = emptyList(), - override val isMarkedNullable: Boolean = false, - open val presentableName: String = "???" -) : SimpleType() { - override val attributes: TypeAttributes - get() = TypeAttributes.Empty - - override fun toString(): String = - constructor.toString() + if (arguments.isEmpty()) "" else arguments.joinToString(", ", "<", ">", -1, "...", null) - - override fun replaceAttributes(newAttributes: TypeAttributes): SimpleType = this - - override fun makeNullableAsSpecified(newNullability: Boolean): SimpleType = - ErrorType(constructor, memberScope, arguments, newNullability) - - @TypeRefinement - override fun refine(kotlinTypeRefiner: KotlinTypeRefiner) = this -} - -class UnresolvedType( - override val presentableName: String, - constructor: TypeConstructor, - memberScope: MemberScope, - arguments: List, - isMarkedNullable: Boolean -) : ErrorType(constructor, memberScope, arguments, isMarkedNullable) { - override fun makeNullableAsSpecified(newNullability: Boolean): SimpleType = - UnresolvedType(presentableName, constructor, memberScope, arguments, newNullability) - - @TypeRefinement - override fun refine(kotlinTypeRefiner: KotlinTypeRefiner) = this -} diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/ErrorUtils.java b/core/descriptors/src/org/jetbrains/kotlin/types/ErrorUtils.java deleted file mode 100644 index b4509afd31d..00000000000 --- a/core/descriptors/src/org/jetbrains/kotlin/types/ErrorUtils.java +++ /dev/null @@ -1,639 +0,0 @@ -/* - * Copyright 2010-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.types; - -import kotlin.jvm.functions.Function1; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.kotlin.builtins.DefaultBuiltIns; -import org.jetbrains.kotlin.builtins.KotlinBuiltIns; -import org.jetbrains.kotlin.descriptors.*; -import org.jetbrains.kotlin.descriptors.annotations.Annotations; -import org.jetbrains.kotlin.descriptors.impl.ClassConstructorDescriptorImpl; -import org.jetbrains.kotlin.descriptors.impl.ClassDescriptorImpl; -import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl; -import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl; -import org.jetbrains.kotlin.incremental.components.LookupLocation; -import org.jetbrains.kotlin.name.FqName; -import org.jetbrains.kotlin.name.Name; -import org.jetbrains.kotlin.platform.TargetPlatform; -import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt; -import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter; -import org.jetbrains.kotlin.resolve.scopes.MemberScope; -import org.jetbrains.kotlin.storage.LockBasedStorageManager; -import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner; -import org.jetbrains.kotlin.types.error.ErrorSimpleFunctionDescriptorImpl; -import org.jetbrains.kotlin.utils.Printer; - -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Set; - -import static java.util.Collections.emptySet; -import static kotlin.collections.CollectionsKt.emptyList; - -public class ErrorUtils { - private static final ModuleDescriptor ERROR_MODULE; - - static { - ERROR_MODULE = new ModuleDescriptor() { - @Nullable - @Override - public T getCapability(@NotNull ModuleCapability capability) { - return null; - } - - @NotNull - @Override - public Annotations getAnnotations() { - return Annotations.Companion.getEMPTY(); - } - - @NotNull - @Override - public Collection getSubPackagesOf(@NotNull FqName fqName, @NotNull Function1 nameFilter) { - return emptyList(); - } - - @NotNull - @Override - public Name getName() { - return Name.special(""); - } - - @NotNull - @Override - public Name getStableName() { - return Name.special(""); - } - - @Nullable - @Override - public TargetPlatform getPlatform() { - return null; - } - - @NotNull - @Override - public PackageViewDescriptor getPackage(@NotNull FqName fqName) { - throw new IllegalStateException("Should not be called!"); - } - - @NotNull - @Override - public List getAllDependencyModules() { - return emptyList(); - } - - @NotNull - @Override - public List getExpectedByModules() { - return emptyList(); - } - - @NotNull - @Override - public Set getAllExpectedByModules() { - return emptySet(); - } - - @Override - public R accept(@NotNull DeclarationDescriptorVisitor visitor, D data) { - return null; - } - - @Override - public void acceptVoid(DeclarationDescriptorVisitor visitor) { - } - - @Override - public boolean shouldSeeInternalsOf(@NotNull ModuleDescriptor targetModule) { - return false; - } - - @NotNull - @Override - public DeclarationDescriptor getOriginal() { - return this; - } - - @Nullable - @Override - public DeclarationDescriptor getContainingDeclaration() { - return null; - } - - @NotNull - @Override - public KotlinBuiltIns getBuiltIns() { - return DefaultBuiltIns.getInstance(); - } - - @Override - public boolean isValid() { - return false; - } - - @Override - public void assertValid() { - throw new InvalidModuleException("ERROR_MODULE is not a valid module"); - } - }; - } - - /** - * @return true iff any of the types referenced in parameter types (including type parameters and extension receiver) of the function - * is an error type. Does not check the return type of the function. - */ - public static boolean containsErrorTypeInParameters(@NotNull FunctionDescriptor function) { - ReceiverParameterDescriptor receiverParameter = function.getExtensionReceiverParameter(); - if (receiverParameter != null && containsErrorType(receiverParameter.getType())) { - return true; - } - for (ValueParameterDescriptor parameter : function.getValueParameters()) { - if (containsErrorType(parameter.getType())) { - return true; - } - } - for (TypeParameterDescriptor parameter : function.getTypeParameters()) { - for (KotlinType upperBound : parameter.getUpperBounds()) { - if (containsErrorType(upperBound)) { - return true; - } - } - } - - return false; - } - - public static class ErrorScope implements MemberScope { - private final String debugMessage; - - private ErrorScope(@NotNull String debugMessage) { - this.debugMessage = debugMessage; - } - - @Nullable - @Override - public ClassifierDescriptor getContributedClassifier(@NotNull Name name, @NotNull LookupLocation location) { - return createErrorClass(name.asString()); - } - - @Nullable - @Override - public DescriptorWithDeprecation getContributedClassifierIncludeDeprecated( - @NotNull Name name, @NotNull LookupLocation location - ) { - return null; - } - - @NotNull - @Override - public Set getContributedVariables(@NotNull Name name, @NotNull LookupLocation location) { - return ERROR_PROPERTY_GROUP; - } - - @NotNull - @Override - public Set getContributedFunctions(@NotNull Name name, @NotNull LookupLocation location) { - return Collections.singleton(createErrorFunction(this)); - } - - @NotNull - @Override - public Set getFunctionNames() { - return emptySet(); - } - - @NotNull - @Override - public Set getVariableNames() { - return emptySet(); - } - - @NotNull - @Override - public Set getClassifierNames() { - return emptySet(); - } - - @Override - public void recordLookup(@NotNull Name name, @NotNull LookupLocation location) { - - } - - @NotNull - @Override - public Collection getContributedDescriptors( - @NotNull DescriptorKindFilter kindFilter, @NotNull Function1 nameFilter - ) { - return Collections.emptyList(); - } - - @Override - public boolean definitelyDoesNotContainName(@NotNull Name name) { - return false; - } - - @Override - public String toString() { - return "ErrorScope{" + debugMessage + '}'; - } - - @Override - public void printScopeStructure(@NotNull Printer p) { - p.println(getClass().getSimpleName(), ": ", debugMessage); - } - } - - private static class ThrowingScope implements MemberScope { - private final String debugMessage; - - private ThrowingScope(@NotNull String message) { - debugMessage = message; - } - - @Nullable - @Override - public ClassifierDescriptor getContributedClassifier(@NotNull Name name, @NotNull LookupLocation location) { - throw new IllegalStateException(debugMessage+", required name: " + name); - } - - @Nullable - @Override - public DescriptorWithDeprecation getContributedClassifierIncludeDeprecated( - @NotNull Name name, @NotNull LookupLocation location - ) { - throw new IllegalStateException(debugMessage + ", required name: " + name); - } - - @NotNull - @Override - public Collection getContributedVariables(@NotNull Name name, @NotNull LookupLocation location) { - throw new IllegalStateException(debugMessage+", required name: " + name); - } - - @NotNull - @Override - public Collection getContributedFunctions( - @NotNull Name name, @NotNull LookupLocation location - ) { - throw new IllegalStateException(debugMessage+", required name: " + name); - } - - @NotNull - @Override - public Collection getContributedDescriptors( - @NotNull DescriptorKindFilter kindFilter, @NotNull Function1 nameFilter - ) { - throw new IllegalStateException(debugMessage); - } - - @NotNull - @Override - public Set getFunctionNames() { - throw new IllegalStateException(); - } - - @NotNull - @Override - public Set getVariableNames() { - throw new IllegalStateException(); - } - - @Override - public Set getClassifierNames() { - throw new IllegalStateException(); - } - - @Override - public void recordLookup(@NotNull Name name, @NotNull LookupLocation location) { - throw new IllegalStateException(); - } - - @Override - public boolean definitelyDoesNotContainName(@NotNull Name name) { - return false; - } - - @Override - public String toString() { - return "ThrowingScope{" + debugMessage + '}'; - } - - @Override - public void printScopeStructure(@NotNull Printer p) { - p.println(getClass().getSimpleName(), ": ", debugMessage); - } - } - - private static final ErrorClassDescriptor ERROR_CLASS = new ErrorClassDescriptor(Name.special("")); - - private static class ErrorClassDescriptor extends ClassDescriptorImpl { - public ErrorClassDescriptor(@NotNull Name name) { - super(getErrorModule(), name, - Modality.OPEN, ClassKind.CLASS, Collections.emptyList(), SourceElement.NO_SOURCE, - /* isExternal = */ false, LockBasedStorageManager.NO_LOCKS - ); - - ClassConstructorDescriptorImpl - errorConstructor = ClassConstructorDescriptorImpl.create(this, Annotations.Companion.getEMPTY(), true, SourceElement.NO_SOURCE); - errorConstructor.initialize(Collections.emptyList(), - DescriptorVisibilities.INTERNAL); - MemberScope memberScope = createErrorScope(getName().asString()); - errorConstructor.setReturnType( - new ErrorType( - createErrorTypeConstructorWithCustomDebugName("", this), - memberScope - ) - ); - - initialize(memberScope, Collections.singleton(errorConstructor), errorConstructor); - } - - @NotNull - @Override - public ClassDescriptor substitute(@NotNull TypeSubstitutor substitutor) { - return this; - } - - @Override - public String toString() { - return getName().asString(); - } - - @NotNull - @Override - public MemberScope getMemberScope(@NotNull List typeArguments, @NotNull KotlinTypeRefiner kotlinTypeRefiner) { - return createErrorScope("Error scope for class " + getName() + " with arguments: " + typeArguments); - } - - @NotNull - @Override - public MemberScope getMemberScope(@NotNull TypeSubstitution typeSubstitution, @NotNull KotlinTypeRefiner kotlinTypeRefiner) { - return createErrorScope("Error scope for class " + getName() + " with arguments: " + typeSubstitution); - } - } - - @NotNull - public static ClassDescriptor createErrorClass(@NotNull String debugMessage) { - return new ErrorClassDescriptor(Name.special("")); - } - - @NotNull - public static MemberScope createErrorScope(@NotNull String debugMessage) { - return createErrorScope(debugMessage, false); - } - - @NotNull - public static MemberScope createErrorScope(@NotNull String debugMessage, boolean throwExceptions) { - if (throwExceptions) { - return new ThrowingScope(debugMessage); - } - return new ErrorScope(debugMessage); - } - - // Do not move it into AbstractTypeConstructor.Companion because of cycle in initialization(see KT-13264) - public static final SimpleType ERROR_TYPE_FOR_LOOP_IN_SUPERTYPES = createErrorType(""); - - private static final KotlinType ERROR_PROPERTY_TYPE = createErrorType(""); - private static final PropertyDescriptor ERROR_PROPERTY = createErrorProperty(); - - private static final Set ERROR_PROPERTY_GROUP = Collections.singleton(ERROR_PROPERTY); - - @NotNull - private static PropertyDescriptorImpl createErrorProperty() { - PropertyDescriptorImpl descriptor = PropertyDescriptorImpl.create( - ERROR_CLASS, - Annotations.Companion.getEMPTY(), - Modality.OPEN, - DescriptorVisibilities.PUBLIC, - true, - Name.special(""), - CallableMemberDescriptor.Kind.DECLARATION, - SourceElement.NO_SOURCE, - false, false, false, false, false, false - ); - descriptor.setType(ERROR_PROPERTY_TYPE, Collections.emptyList(), null, null, - Collections.emptyList()); - - return descriptor; - } - - @NotNull - private static SimpleFunctionDescriptor createErrorFunction(@NotNull ErrorScope ownerScope) { - ErrorSimpleFunctionDescriptorImpl function = new ErrorSimpleFunctionDescriptorImpl(ERROR_CLASS, ownerScope); - function.initialize( - null, null, Collections.emptyList(), - Collections.emptyList(), // TODO - Collections.emptyList(), // TODO - createErrorType(""), - Modality.OPEN, - DescriptorVisibilities.PUBLIC - ); - return function; - } - - @NotNull - public static SimpleType createErrorType(@NotNull String debugMessage) { - return createErrorTypeWithArguments(debugMessage, Collections.emptyList()); - } - - @NotNull - public static SimpleType createErrorTypeWithCustomDebugName(@NotNull String debugName) { - return createErrorTypeWithCustomConstructor(debugName, createErrorTypeConstructorWithCustomDebugName(debugName)); - } - - @NotNull - public static SimpleType createErrorTypeWithCustomConstructor(@NotNull String debugName, @NotNull TypeConstructor typeConstructor) { - return new ErrorType(typeConstructor, createErrorScope(debugName)); - } - - @NotNull - public static SimpleType createErrorTypeWithArguments(@NotNull String debugMessage, @NotNull List arguments) { - return new ErrorType(createErrorTypeConstructor(debugMessage), createErrorScope(debugMessage), arguments, false); - } - - @NotNull - public static SimpleType createUnresolvedType(@NotNull String presentableName, @NotNull List arguments) { - return new UnresolvedType(presentableName, createErrorTypeConstructor(presentableName), createErrorScope(presentableName), - arguments, false); - } - - @NotNull - public static TypeConstructor createErrorTypeConstructor(@NotNull String debugMessage) { - return createErrorTypeConstructorWithCustomDebugName("[ERROR : " + debugMessage + "]", ERROR_CLASS); - } - - @NotNull - public static TypeConstructor createErrorTypeConstructorWithCustomDebugName(@NotNull String debugName) { - return createErrorTypeConstructorWithCustomDebugName(debugName, ERROR_CLASS); - } - - @NotNull - private static TypeConstructor createErrorTypeConstructorWithCustomDebugName( - @NotNull final String debugName, @NotNull final ErrorClassDescriptor errorClass - ) { - return new TypeConstructor() { - @NotNull - @Override - public List getParameters() { - return emptyList(); - } - - @NotNull - @Override - public Collection getSupertypes() { - return emptyList(); - } - - @Override - public boolean isFinal() { - return false; - } - - @Override - public boolean isDenotable() { - return false; - } - - @Nullable - @Override - public ClassifierDescriptor getDeclarationDescriptor() { - return errorClass; - } - - @NotNull - @Override - public KotlinBuiltIns getBuiltIns() { - return DefaultBuiltIns.getInstance(); - } - - @Override - public String toString() { - return debugName; - } - - @TypeRefinement - @Override - @NotNull - public TypeConstructor refine(@NotNull KotlinTypeRefiner kotlinTypeRefiner) { - return this; - } - }; - } - - public static boolean containsErrorType(@Nullable KotlinType type) { - if (type == null) return false; - if (KotlinTypeKt.isError(type)) return true; - for (TypeProjection projection : type.getArguments()) { - if (!projection.isStarProjection() && containsErrorType(projection.getType())) return true; - } - return false; - } - - public static boolean isError(@Nullable DeclarationDescriptor candidate) { - if (candidate == null) return false; - return isErrorClass(candidate) || isErrorClass(candidate.getContainingDeclaration()) || candidate == ERROR_MODULE; - } - - private static boolean isErrorClass(@Nullable DeclarationDescriptor candidate) { - return candidate instanceof ErrorClassDescriptor; - } - - @NotNull - public static ModuleDescriptor getErrorModule() { - return ERROR_MODULE; - } - - public static boolean isUninferredParameter(@Nullable KotlinType type) { - return type != null && type.getConstructor() instanceof UninferredParameterTypeConstructor; - } - - public static boolean containsUninferredParameter(@Nullable KotlinType type) { - return TypeUtils.contains(type, new Function1() { - @Override - public Boolean invoke(UnwrappedType argumentType) { - return isUninferredParameter(argumentType); - } - }); - } - - @NotNull - public static KotlinType createUninferredParameterType(@NotNull TypeParameterDescriptor typeParameterDescriptor) { - return createErrorTypeWithCustomConstructor("Scope for error type for not inferred parameter: " + typeParameterDescriptor.getName(), - new UninferredParameterTypeConstructor(typeParameterDescriptor)); - } - - public static class UninferredParameterTypeConstructor implements TypeConstructor { - private final TypeParameterDescriptor typeParameterDescriptor; - private final TypeConstructor errorTypeConstructor; - - private UninferredParameterTypeConstructor(@NotNull TypeParameterDescriptor descriptor) { - typeParameterDescriptor = descriptor; - errorTypeConstructor = createErrorTypeConstructorWithCustomDebugName("CANT_INFER_TYPE_PARAMETER: " + descriptor.getName()); - } - - @NotNull - public TypeParameterDescriptor getTypeParameterDescriptor() { - return typeParameterDescriptor; - } - - @NotNull - @Override - public List getParameters() { - return errorTypeConstructor.getParameters(); - } - - @NotNull - @Override - public Collection getSupertypes() { - return errorTypeConstructor.getSupertypes(); - } - - @Override - public boolean isFinal() { - return errorTypeConstructor.isFinal(); - } - - @Override - public boolean isDenotable() { - return errorTypeConstructor.isDenotable(); - } - - @Nullable - @Override - public ClassifierDescriptor getDeclarationDescriptor() { - return errorTypeConstructor.getDeclarationDescriptor(); - } - - @NotNull - @Override - public KotlinBuiltIns getBuiltIns() { - return DescriptorUtilsKt.getBuiltIns(typeParameterDescriptor); - } - - @NotNull - @Override - public TypeConstructor refine(@NotNull KotlinTypeRefiner kotlinTypeRefiner) { - return this; - } - } - - private ErrorUtils() {} -} diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/FunctionPlaceholders.kt b/core/descriptors/src/org/jetbrains/kotlin/types/FunctionPlaceholders.kt index 1bdc959f9dd..05bed0d1ebb 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/FunctionPlaceholders.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/FunctionPlaceholders.kt @@ -20,15 +20,18 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.descriptors.ClassifierDescriptor import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner +import org.jetbrains.kotlin.types.error.ErrorTypeKind +import org.jetbrains.kotlin.types.error.ErrorUtils class FunctionPlaceholders(private val builtIns: KotlinBuiltIns) { fun createFunctionPlaceholderType( argumentTypes: List, hasDeclaredArguments: Boolean ): KotlinType { - return ErrorUtils.createErrorTypeWithCustomConstructor( - "function placeholder type", - FunctionPlaceholderTypeConstructor(argumentTypes, hasDeclaredArguments, builtIns) + return ErrorUtils.createErrorType( + ErrorTypeKind.FUNCTION_PLACEHOLDER_TYPE, + FunctionPlaceholderTypeConstructor(argumentTypes, hasDeclaredArguments, builtIns), + argumentTypes.toString() ) } } @@ -43,7 +46,8 @@ class FunctionPlaceholderTypeConstructor( val hasDeclaredArguments: Boolean, private val kotlinBuiltIns: KotlinBuiltIns ) : TypeConstructor { - private val errorTypeConstructor: TypeConstructor = ErrorUtils.createErrorTypeConstructorWithCustomDebugName("PLACEHOLDER_FUNCTION_TYPE" + argumentTypes) + private val errorTypeConstructor: TypeConstructor = + ErrorUtils.createErrorTypeConstructor(ErrorTypeKind.FUNCTION_PLACEHOLDER_TYPE, argumentTypes.toString()) override fun getParameters(): List { return errorTypeConstructor.parameters diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/KotlinType.kt b/core/descriptors/src/org/jetbrains/kotlin/types/KotlinType.kt index 15b0118f640..d7244ad7c15 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/KotlinType.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/KotlinType.kt @@ -23,6 +23,7 @@ import org.jetbrains.kotlin.renderer.DescriptorRendererOptions import org.jetbrains.kotlin.resolve.scopes.MemberScope import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner import org.jetbrains.kotlin.types.checker.StrictEqualityTypeChecker +import org.jetbrains.kotlin.types.error.ErrorType import org.jetbrains.kotlin.types.model.FlexibleTypeMarker import org.jetbrains.kotlin.types.model.KotlinTypeMarker import org.jetbrains.kotlin.types.model.SimpleTypeMarker diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/KotlinTypeFactory.kt b/core/descriptors/src/org/jetbrains/kotlin/types/KotlinTypeFactory.kt index 8c97ddac9d2..99300903431 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/KotlinTypeFactory.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/KotlinTypeFactory.kt @@ -28,6 +28,10 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.getKotlinTypeRefiner import org.jetbrains.kotlin.resolve.descriptorUtil.module import org.jetbrains.kotlin.resolve.scopes.MemberScope import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner +import org.jetbrains.kotlin.types.error.ErrorScope +import org.jetbrains.kotlin.types.error.ErrorScopeKind +import org.jetbrains.kotlin.types.error.ErrorUtils +import org.jetbrains.kotlin.types.error.ThrowingScope typealias RefinedTypeFactory = (KotlinTypeRefiner) -> SimpleType? @@ -54,7 +58,9 @@ object KotlinTypeFactory { refinerToUse ) } - is TypeAliasDescriptor -> ErrorUtils.createErrorScope("Scope for abbreviation: ${descriptor.name}", true) + is TypeAliasDescriptor -> ErrorUtils.createErrorScope( + ErrorScopeKind.SCOPE_FOR_ABBREVIATION_TYPE, throwExceptions = true, descriptor.name.toString() + ) else -> { if (constructor is IntersectionTypeConstructor) { return constructor.createScopeForKotlinType() @@ -192,7 +198,7 @@ object KotlinTypeFactory { constructor, emptyList(), nullable, - ErrorUtils.createErrorScope("Scope for integer literal type", true) + ErrorUtils.createErrorScope(ErrorScopeKind.INTEGER_LITERAL_TYPE_SCOPE, throwExceptions = true, "unknown integer literal type") ) } @@ -220,7 +226,7 @@ private class SimpleTypeImpl( } init { - if (memberScope is ErrorUtils.ErrorScope) { + if (memberScope is ErrorScope && memberScope !is ThrowingScope) { throw IllegalStateException("SimpleTypeImpl should not be created for error type: $memberScope\n$constructor") } } diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/StubTypes.kt b/core/descriptors/src/org/jetbrains/kotlin/types/StubTypes.kt index b2783661bc1..5f67d84342a 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/StubTypes.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/StubTypes.kt @@ -5,10 +5,13 @@ package org.jetbrains.kotlin.types -import org.jetbrains.kotlin.descriptors.annotations.Annotations +import org.jetbrains.kotlin.resolve.scopes.MemberScope import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner import org.jetbrains.kotlin.types.checker.NewTypeVariableConstructor +import org.jetbrains.kotlin.types.error.ErrorScopeKind +import org.jetbrains.kotlin.types.error.ErrorTypeKind import org.jetbrains.kotlin.types.model.StubTypeMarker +import org.jetbrains.kotlin.types.error.ErrorUtils class StubTypeForBuilderInference( originalTypeVariable: NewTypeVariableConstructor, @@ -18,7 +21,7 @@ class StubTypeForBuilderInference( override fun materialize(newNullability: Boolean): AbstractStubType = StubTypeForBuilderInference(originalTypeVariable, newNullability, constructor) - override val memberScope = originalTypeVariable.builtIns.anyType.memberScope + override val memberScope: MemberScope = originalTypeVariable.builtIns.anyType.memberScope override fun toString(): String { // BI means builder inference @@ -54,7 +57,7 @@ class StubTypeForProvideDelegateReceiver( } abstract class AbstractStubType(val originalTypeVariable: NewTypeVariableConstructor, override val isMarkedNullable: Boolean) : SimpleType() { - override val memberScope = ErrorUtils.createErrorScope("Scope for stub type: $originalTypeVariable") + override val memberScope: MemberScope = ErrorUtils.createErrorScope(ErrorScopeKind.STUB_TYPE_SCOPE, originalTypeVariable.toString()) override val arguments: List get() = emptyList() @@ -75,6 +78,6 @@ abstract class AbstractStubType(val originalTypeVariable: NewTypeVariableConstru companion object { fun createConstructor(originalTypeVariable: NewTypeVariableConstructor) = - ErrorUtils.createErrorTypeConstructor("Constructor for stub type: $originalTypeVariable") + ErrorUtils.createErrorTypeConstructor(ErrorTypeKind.STUB_TYPE, originalTypeVariable.toString()) } } diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/TypeAliasExpander.kt b/core/descriptors/src/org/jetbrains/kotlin/types/TypeAliasExpander.kt index 20cd671e002..333eb7d0e9d 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/TypeAliasExpander.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/TypeAliasExpander.kt @@ -8,10 +8,11 @@ package org.jetbrains.kotlin.types import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor import org.jetbrains.kotlin.descriptors.annotations.Annotations -import org.jetbrains.kotlin.descriptors.annotations.composeAnnotations import org.jetbrains.kotlin.resolve.scopes.MemberScope +import org.jetbrains.kotlin.types.error.ErrorTypeKind import org.jetbrains.kotlin.types.typeUtil.containsTypeAliasParameters import org.jetbrains.kotlin.types.typeUtil.requiresTypeAliasExpansion +import org.jetbrains.kotlin.types.error.ErrorUtils class TypeAliasExpander( private val reportStrategy: TypeAliasExpansionReportStrategy, @@ -188,7 +189,8 @@ class TypeAliasExpander( reportStrategy.recursiveTypeAlias(typeDescriptor) return TypeProjectionImpl( Variance.INVARIANT, - ErrorUtils.createErrorType("Recursive type alias: ${typeDescriptor.name}") + ErrorUtils.createErrorType( + ErrorTypeKind.RECURSIVE_TYPE_ALIAS, typeDescriptor.name.toString()) ) } diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/TypeSubstitutor.java b/core/descriptors/src/org/jetbrains/kotlin/types/TypeSubstitutor.java index 2247e8af913..64cd86f498b 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/TypeSubstitutor.java +++ b/core/descriptors/src/org/jetbrains/kotlin/types/TypeSubstitutor.java @@ -28,6 +28,8 @@ import org.jetbrains.kotlin.descriptors.annotations.FilteredAnnotations; import org.jetbrains.kotlin.name.FqName; import org.jetbrains.kotlin.resolve.calls.inference.CapturedTypeConstructorKt; import org.jetbrains.kotlin.types.checker.NewCapturedTypeConstructor; +import org.jetbrains.kotlin.types.error.ErrorTypeKind; +import org.jetbrains.kotlin.types.error.ErrorUtils; import org.jetbrains.kotlin.types.model.TypeSubstitutorMarker; import org.jetbrains.kotlin.types.typeUtil.TypeUtilsKt; import org.jetbrains.kotlin.types.typesApproximation.CapturedTypeApproximationKt; @@ -131,7 +133,7 @@ public class TypeSubstitutor implements TypeSubstitutorMarker { try { return unsafeSubstitute(new TypeProjectionImpl(howThisTypeIsUsed, type), null, 0).getType(); } catch (SubstitutionException e) { - return ErrorUtils.createErrorType(e.getMessage()); + return ErrorUtils.createErrorType(ErrorTypeKind.UNABLE_TO_SUBSTITUTE_TYPE, e.getMessage()); } } diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.java b/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.java index 801bdb45cad..0b21f631cf9 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.java +++ b/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.java @@ -15,7 +15,6 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor; import org.jetbrains.kotlin.descriptors.ClassifierDescriptor; import org.jetbrains.kotlin.descriptors.DeclarationDescriptor; import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor; -import org.jetbrains.kotlin.descriptors.annotations.Annotations; import org.jetbrains.kotlin.name.FqName; import org.jetbrains.kotlin.name.FqNameUnsafe; import org.jetbrains.kotlin.resolve.DescriptorUtils; @@ -25,13 +24,16 @@ import org.jetbrains.kotlin.resolve.scopes.MemberScope; import org.jetbrains.kotlin.types.checker.KotlinTypeChecker; import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner; import org.jetbrains.kotlin.types.checker.NewTypeVariableConstructor; +import org.jetbrains.kotlin.types.error.ErrorTypeKind; +import org.jetbrains.kotlin.types.error.ErrorUtils; import org.jetbrains.kotlin.utils.SmartSet; import java.util.*; public class TypeUtils { - public static final SimpleType DONT_CARE = ErrorUtils.createErrorTypeWithCustomDebugName("DONT_CARE"); - public static final SimpleType CANT_INFER_FUNCTION_PARAM_TYPE = ErrorUtils.createErrorType("Cannot be inferred"); + public static final SimpleType DONT_CARE = ErrorUtils.createErrorType(ErrorTypeKind.DONT_CARE); + public static final SimpleType CANNOT_INFER_FUNCTION_PARAM_TYPE = + ErrorUtils.createErrorType(ErrorTypeKind.UNINFERRED_LAMBDA_PARAMETER_TYPE); public static class SpecialType extends DelegatingSimpleType { private final String name; @@ -207,7 +209,7 @@ public class TypeUtils { Function1 refinedTypeFactory ) { if (ErrorUtils.isError(classifierDescriptor)) { - return ErrorUtils.createErrorType("Unsubstituted type for " + classifierDescriptor); + return ErrorUtils.createErrorType(ErrorTypeKind.UNABLE_TO_SUBSTITUTE_TYPE, classifierDescriptor.toString()); } TypeConstructor typeConstructor = classifierDescriptor.getTypeConstructor(); return makeUnsubstitutedType(typeConstructor, unsubstitutedMemberScope, refinedTypeFactory); diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.kt b/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.kt index f8ba9f41e69..ea4f3a02d3d 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.kt @@ -25,10 +25,14 @@ import org.jetbrains.kotlin.resolve.calls.inference.isCaptured import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.checker.* +import org.jetbrains.kotlin.types.error.ErrorType import org.jetbrains.kotlin.types.model.SimpleTypeMarker import org.jetbrains.kotlin.types.model.TypeArgumentMarker import org.jetbrains.kotlin.types.model.TypeVariableTypeConstructorMarker import org.jetbrains.kotlin.utils.addToStdlib.safeAs +import org.jetbrains.kotlin.types.error.ErrorUtils +import kotlin.contracts.ExperimentalContracts +import kotlin.contracts.contract enum class TypeNullability { NOT_NULL, @@ -399,3 +403,11 @@ fun KotlinType.isStubTypeForBuilderInference(): Boolean = this is StubTypeForBuilderInference || isDefNotNullStubType() private inline fun KotlinType.isDefNotNullStubType() = this is DefinitelyNotNullType && this.original is S + +@OptIn(ExperimentalContracts::class) +fun isUnresolvedType(type: KotlinType): Boolean { + contract { + returns(true) implies (type is ErrorType) + } + return type is ErrorType && type.kind.isUnresolved +} diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/checker/ClassicTypeSystemContext.kt b/core/descriptors/src/org/jetbrains/kotlin/types/checker/ClassicTypeSystemContext.kt index 9acb709f073..c6425f21dbd 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/checker/ClassicTypeSystemContext.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/checker/ClassicTypeSystemContext.kt @@ -24,6 +24,7 @@ import org.jetbrains.kotlin.resolve.isInlineClass import org.jetbrains.kotlin.resolve.substitutedUnderlyingType import org.jetbrains.kotlin.resolve.unsubstitutedUnderlyingType import org.jetbrains.kotlin.types.* +import org.jetbrains.kotlin.types.error.ErrorTypeKind import org.jetbrains.kotlin.types.model.* import org.jetbrains.kotlin.types.typeUtil.* import org.jetbrains.kotlin.utils.addIfNotNull @@ -33,6 +34,7 @@ import org.jetbrains.kotlin.types.typeUtil.isSignedOrUnsignedNumberType as class import org.jetbrains.kotlin.types.typeUtil.isStubTypeForVariableInSubtyping as isSimpleTypeStubTypeForVariableInSubtyping import org.jetbrains.kotlin.types.typeUtil.isStubTypeForBuilderInference as isSimpleTypeStubTypeForBuilderInference import org.jetbrains.kotlin.types.typeUtil.isStubType as isSimpleTypeStubType +import org.jetbrains.kotlin.types.error.ErrorUtils interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSystemCommonBackendContext { override fun TypeConstructorMarker.isDenotable(): Boolean { @@ -87,12 +89,12 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy override fun TypeConstructorMarker.toErrorType(): SimpleTypeMarker { require(this is TypeConstructor && ErrorUtils.isError(declarationDescriptor), this::errorMessage) - return ErrorUtils.createErrorType("from type constructor(${toString()})") + return ErrorUtils.createErrorType(ErrorTypeKind.RESOLUTION_ERROR_TYPE, "from type constructor $this") } override fun KotlinTypeMarker.isUninferredParameter(): Boolean { require(this is KotlinType, this::errorMessage) - return ErrorUtils.isUninferredParameter(this) + return ErrorUtils.isUninferredTypeVariable(this) } override fun SimpleTypeMarker.isStubType(): Boolean { @@ -698,12 +700,11 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy } override fun createErrorType(debugName: String): SimpleTypeMarker { - return ErrorUtils.createErrorType(debugName) + return ErrorUtils.createErrorType(ErrorTypeKind.RESOLUTION_ERROR_TYPE, debugName) } - override fun createErrorTypeWithCustomConstructor(debugName: String, constructor: TypeConstructorMarker): KotlinTypeMarker { - require(constructor is TypeConstructor, constructor::errorMessage) - return ErrorUtils.createErrorTypeWithCustomConstructor(debugName, constructor) + override fun createUninferredType(constructor: TypeConstructorMarker): KotlinTypeMarker { + return ErrorUtils.createErrorType(ErrorTypeKind.UNINFERRED_TYPE_VARIABLE, constructor as TypeConstructor, constructor.toString()) } override fun TypeConstructorMarker.isCapturedTypeConstructor(): Boolean { diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/checker/IntersectionType.kt b/core/descriptors/src/org/jetbrains/kotlin/types/checker/IntersectionType.kt index 48f472c9c61..a67af1648bb 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/checker/IntersectionType.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/checker/IntersectionType.kt @@ -18,8 +18,10 @@ package org.jetbrains.kotlin.types.checker import org.jetbrains.kotlin.resolve.constants.IntegerLiteralTypeConstructor import org.jetbrains.kotlin.types.* +import org.jetbrains.kotlin.types.error.ErrorTypeKind import java.util.* import kotlin.collections.LinkedHashSet +import org.jetbrains.kotlin.types.error.ErrorUtils fun intersectWrappedTypes(types: Collection) = intersectTypes(types.map { it.unwrap() }) @@ -46,7 +48,7 @@ fun intersectTypes(types: List): UnwrappedType { } } if (hasErrorType) { - return ErrorUtils.createErrorType("Intersection of error types: $types") + return ErrorUtils.createErrorType(ErrorTypeKind.INTERSECTION_OF_ERROR_TYPES, types.toString()) } if (!hasFlexibleTypes) { diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/checker/NewCapturedType.kt b/core/descriptors/src/org/jetbrains/kotlin/types/checker/NewCapturedType.kt index 393f8c2c73f..55eb1b8207a 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/checker/NewCapturedType.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/checker/NewCapturedType.kt @@ -19,7 +19,7 @@ package org.jetbrains.kotlin.types.checker import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.descriptors.ClassifierDescriptor import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor -import org.jetbrains.kotlin.descriptors.annotations.Annotations +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.resolve.calls.inference.CapturedTypeConstructor import org.jetbrains.kotlin.resolve.scopes.MemberScope import org.jetbrains.kotlin.types.* @@ -27,6 +27,7 @@ import org.jetbrains.kotlin.types.FlexibleTypeBoundsChecker.areTypesMayBeLowerAn import org.jetbrains.kotlin.types.model.CaptureStatus import org.jetbrains.kotlin.types.model.CapturedTypeMarker import org.jetbrains.kotlin.types.TypeRefinement +import org.jetbrains.kotlin.types.error.ErrorScopeKind import org.jetbrains.kotlin.types.typeUtil.asTypeProjection import org.jetbrains.kotlin.types.typeUtil.builtIns @@ -210,7 +211,7 @@ class NewCapturedType( override val arguments: List get() = listOf() 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(ErrorScopeKind.CAPTURED_TYPE_SCOPE, throwExceptions = true) override fun replaceAttributes(newAttributes: TypeAttributes): SimpleType = NewCapturedType(captureStatus, constructor, lowerType, newAttributes, isMarkedNullable, isProjectionNotNull) diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorClassDescriptor.kt b/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorClassDescriptor.kt new file mode 100644 index 00000000000..2a76194a5ca --- /dev/null +++ b/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorClassDescriptor.kt @@ -0,0 +1,49 @@ +/* + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.types.error + +import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.descriptors.annotations.Annotations +import org.jetbrains.kotlin.descriptors.impl.ClassConstructorDescriptorImpl +import org.jetbrains.kotlin.descriptors.impl.ClassDescriptorImpl +import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.resolve.scopes.MemberScope +import org.jetbrains.kotlin.storage.LockBasedStorageManager +import org.jetbrains.kotlin.types.TypeProjection +import org.jetbrains.kotlin.types.TypeSubstitution +import org.jetbrains.kotlin.types.TypeSubstitutor +import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner + +class ErrorClassDescriptor(name: Name) : ClassDescriptorImpl( + ErrorUtils.errorModule, name, Modality.OPEN, ClassKind.CLASS, emptyList(), SourceElement.NO_SOURCE, false, LockBasedStorageManager.NO_LOCKS +) { + init { + val errorConstructor = ClassConstructorDescriptorImpl.create(this, Annotations.EMPTY, true, SourceElement.NO_SOURCE) + .apply { + initialize( + emptyList(), + DescriptorVisibilities.INTERNAL + ) + } + val memberScope = ErrorUtils.createErrorScope(ErrorScopeKind.SCOPE_FOR_ERROR_CLASS, errorConstructor.name.toString(), "") + errorConstructor.returnType = ErrorType( + ErrorUtils.createErrorTypeConstructor(ErrorTypeKind.ERROR_CLASS), + memberScope, + ErrorTypeKind.ERROR_CLASS + ) + initialize(memberScope, setOf(errorConstructor), errorConstructor) + } + + override fun substitute(substitutor: TypeSubstitutor): ClassDescriptor = this + + override fun getMemberScope(typeArguments: List, kotlinTypeRefiner: KotlinTypeRefiner): MemberScope = + ErrorUtils.createErrorScope(ErrorScopeKind.SCOPE_FOR_ERROR_CLASS, name.toString(), typeArguments.toString()) + + override fun getMemberScope(typeSubstitution: TypeSubstitution, kotlinTypeRefiner: KotlinTypeRefiner): MemberScope = + ErrorUtils.createErrorScope(ErrorScopeKind.SCOPE_FOR_ERROR_CLASS, name.toString(), typeSubstitution.toString()) + + override fun toString(): String = name.asString() +} \ No newline at end of file diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorEntity.kt b/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorEntity.kt new file mode 100644 index 00000000000..c00de504f36 --- /dev/null +++ b/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorEntity.kt @@ -0,0 +1,16 @@ +/* + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.types.error + +enum class ErrorEntity(val debugText: String) { + ERROR_CLASS(""), + ERROR_FUNCTION(""), + ERROR_SCOPE(""), + ERROR_MODULE(""), + ERROR_PROPERTY(""), + ERROR_TYPE("[Error type: %s]"), + PARENT_OF_ERROR_SCOPE(""), +} diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorFunctionDescriptor.kt b/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorFunctionDescriptor.kt new file mode 100644 index 00000000000..6a03c1930cd --- /dev/null +++ b/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorFunctionDescriptor.kt @@ -0,0 +1,88 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ +package org.jetbrains.kotlin.types.error + +import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.descriptors.annotations.Annotations +import org.jetbrains.kotlin.descriptors.annotations.Annotations.Companion.EMPTY +import org.jetbrains.kotlin.descriptors.impl.FunctionDescriptorImpl +import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl +import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.types.KotlinType +import org.jetbrains.kotlin.types.TypeSubstitution + +class ErrorFunctionDescriptor(containingDeclaration: ClassDescriptor) : + SimpleFunctionDescriptorImpl( + containingDeclaration, null, EMPTY, Name.special(ErrorEntity.ERROR_FUNCTION.debugText), CallableMemberDescriptor.Kind.DECLARATION, SourceElement.NO_SOURCE +) { + init { + initialize( + null, null, emptyList(), emptyList(), emptyList(), + ErrorUtils.createErrorType(ErrorTypeKind.RETURN_TYPE_FOR_FUNCTION), Modality.OPEN, DescriptorVisibilities.PUBLIC + ) + } + + override fun createSubstitutedCopy( + newOwner: DeclarationDescriptor, + original: FunctionDescriptor?, + kind: CallableMemberDescriptor.Kind, + newName: Name?, + annotations: Annotations, + source: SourceElement + ): FunctionDescriptorImpl = this + + override fun copy( + newOwner: DeclarationDescriptor, + modality: Modality, + visibility: DescriptorVisibility, + kind: CallableMemberDescriptor.Kind, + copyOverrides: Boolean + ): SimpleFunctionDescriptor = this + + override fun newCopyBuilder(): FunctionDescriptor.CopyBuilder = + object : FunctionDescriptor.CopyBuilder { + override fun setOwner(owner: DeclarationDescriptor): FunctionDescriptor.CopyBuilder = this + override fun setModality(modality: Modality): FunctionDescriptor.CopyBuilder = this + override fun setVisibility(visibility: DescriptorVisibility): FunctionDescriptor.CopyBuilder = this + override fun setKind(kind: CallableMemberDescriptor.Kind): FunctionDescriptor.CopyBuilder = this + override fun setCopyOverrides(copyOverrides: Boolean): FunctionDescriptor.CopyBuilder = this + override fun setName(name: Name): FunctionDescriptor.CopyBuilder = this + override fun setSubstitution(substitution: TypeSubstitution): FunctionDescriptor.CopyBuilder = this + override fun setValueParameters( + parameters: List + ): FunctionDescriptor.CopyBuilder = this + override fun putUserData(userDataKey: CallableDescriptor.UserDataKey, + value: V + ): FunctionDescriptor.CopyBuilder = this + override fun setTypeParameters( + parameters: List + ): FunctionDescriptor.CopyBuilder = this + override fun setReturnType(type: KotlinType): FunctionDescriptor.CopyBuilder = this + override fun setContextReceiverParameters( + contextReceiverParameters: List + ): FunctionDescriptor.CopyBuilder = this + override fun setExtensionReceiverParameter( + extensionReceiverParameter: ReceiverParameterDescriptor? + ): FunctionDescriptor.CopyBuilder = this + + override fun setDispatchReceiverParameter( + dispatchReceiverParameter: ReceiverParameterDescriptor? + ): FunctionDescriptor.CopyBuilder = this + override fun setOriginal(original: CallableMemberDescriptor?): FunctionDescriptor.CopyBuilder = this + override fun setSignatureChange(): FunctionDescriptor.CopyBuilder = this + override fun setPreserveSourceElement(): FunctionDescriptor.CopyBuilder = this + override fun setDropOriginalInContainingParts(): FunctionDescriptor.CopyBuilder = this + override fun setHiddenToOvercomeSignatureClash(): FunctionDescriptor.CopyBuilder = this + override fun setHiddenForResolutionEverywhereBesideSupercalls(): FunctionDescriptor.CopyBuilder = this + override fun setAdditionalAnnotations( + additionalAnnotations: Annotations + ): FunctionDescriptor.CopyBuilder = this + override fun build(): SimpleFunctionDescriptor = this@ErrorFunctionDescriptor + } + + override fun isSuspend(): Boolean = false + override fun getUserData(key: CallableDescriptor.UserDataKey): V? = null + override fun setOverriddenDescriptors(overriddenDescriptors: Collection) {} +} diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorModuleDescriptor.kt b/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorModuleDescriptor.kt new file mode 100644 index 00000000000..34d33837feb --- /dev/null +++ b/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorModuleDescriptor.kt @@ -0,0 +1,36 @@ +/* + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.types.error + +import org.jetbrains.kotlin.builtins.DefaultBuiltIns +import org.jetbrains.kotlin.builtins.KotlinBuiltIns +import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.descriptors.annotations.Annotations +import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.platform.TargetPlatform + +object ErrorModuleDescriptor : ModuleDescriptor { + override val stableName: Name = Name.special(ErrorEntity.ERROR_MODULE.debugText) + override val platform: TargetPlatform? = null + override val allDependencyModules: List = emptyList() + override val expectedByModules: List = emptyList() + override val allExpectedByModules: Set = emptySet() + override val annotations: Annotations get() = Annotations.EMPTY + override val builtIns: KotlinBuiltIns = DefaultBuiltIns.Instance + override val isValid: Boolean = false + + override fun getCapability(capability: ModuleCapability): T? = null + override fun getSubPackagesOf(fqName: FqName, nameFilter: Function1): Collection = emptyList() + override fun getName(): Name = stableName + override fun getPackage(fqName: FqName): PackageViewDescriptor = throw IllegalStateException("Should not be called!") + override fun getOriginal(): DeclarationDescriptor = this + override fun getContainingDeclaration(): DeclarationDescriptor? = null + override fun shouldSeeInternalsOf(targetModule: ModuleDescriptor): Boolean = false + override fun assertValid() = throw InvalidModuleException("ERROR_MODULE is not a valid module") + override fun accept(visitor: DeclarationDescriptorVisitor, data: D): R? = null + override fun acceptVoid(visitor: DeclarationDescriptorVisitor) {} +} \ No newline at end of file diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorPropertyDescriptor.kt b/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorPropertyDescriptor.kt new file mode 100644 index 00000000000..61a1f7e88bc --- /dev/null +++ b/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorPropertyDescriptor.kt @@ -0,0 +1,22 @@ +/* + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.types.error + +import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.descriptors.annotations.Annotations +import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl +import org.jetbrains.kotlin.name.Name + +class ErrorPropertyDescriptor : PropertyDescriptor by ( + PropertyDescriptorImpl.create( + ErrorUtils.errorClass, Annotations.EMPTY, Modality.OPEN, + DescriptorVisibilities.PUBLIC, true, Name.special(ErrorEntity.ERROR_PROPERTY.debugText), + CallableMemberDescriptor.Kind.DECLARATION, SourceElement.NO_SOURCE, + false, false, false, false, false, false + ).apply { + setType(ErrorUtils.errorPropertyType, emptyList(), null, null, emptyList()) + } + ) diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorScope.kt b/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorScope.kt new file mode 100644 index 00000000000..a4a959393d5 --- /dev/null +++ b/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorScope.kt @@ -0,0 +1,46 @@ +/* + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.types.error + +import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.incremental.components.LookupLocation +import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter +import org.jetbrains.kotlin.resolve.scopes.MemberScope +import org.jetbrains.kotlin.utils.Printer + +open class ErrorScope(val kind: ErrorScopeKind, vararg formatParams: String) : MemberScope { + protected val debugMessage = kind.debugMessage.format(*formatParams) + + override fun getContributedClassifier(name: Name, location: LookupLocation): ClassifierDescriptor = + ErrorClassDescriptor(Name.special(ErrorEntity.ERROR_CLASS.debugText.format(name))) + + override fun getContributedClassifierIncludeDeprecated( + name: Name, location: LookupLocation + ): DescriptorWithDeprecation? = null + + override fun getContributedVariables(name: Name, location: LookupLocation): Set = ErrorUtils.errorPropertyGroup + + override fun getContributedFunctions(name: Name, location: LookupLocation): Set = + setOf(ErrorFunctionDescriptor(ErrorUtils.errorClass)) + + override fun getContributedDescriptors( + kindFilter: DescriptorKindFilter, nameFilter: Function1 + ): Collection = emptyList() + + override fun getFunctionNames(): Set = emptySet() + override fun getVariableNames(): Set = emptySet() + override fun getClassifierNames(): Set = emptySet() + + override fun recordLookup(name: Name, location: LookupLocation) {} + override fun definitelyDoesNotContainName(name: Name): Boolean = false + + override fun toString(): String = "ErrorScope{$debugMessage}" + + override fun printScopeStructure(p: Printer) { + p.println(javaClass.simpleName, ": ", debugMessage) + } +} \ No newline at end of file diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorScopeKind.kt b/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorScopeKind.kt new file mode 100644 index 00000000000..bca3ec2c4ad --- /dev/null +++ b/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorScopeKind.kt @@ -0,0 +1,23 @@ +/* + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.types.error + +enum class ErrorScopeKind(val debugMessage: String) { + /* Special type scopes */ + CAPTURED_TYPE_SCOPE("No member resolution should be done on captured type, it used only during constraint system resolution"), + INTEGER_LITERAL_TYPE_SCOPE("Scope for integer literal type (%s)"), + ERASED_RECEIVER_TYPE_SCOPE("Error scope for erased receiver type"), + SCOPE_FOR_ABBREVIATION_TYPE("Scope for abbreviation %s"), + STUB_TYPE_SCOPE("Scope for stub type %s"), + NON_CLASSIFIER_SUPER_TYPE_SCOPE("A scope for common supertype which is not a normal classifier"), + ERROR_TYPE_SCOPE("Scope for error type %s"), + UNSUPPORTED_TYPE_SCOPE("Scope for unsupported type %s"), + + /* Other scopes */ + SCOPE_FOR_ERROR_CLASS("Error scope for class %s with arguments: %s"), + SCOPE_FOR_ERROR_RESOLUTION_CANDIDATE("Error resolution candidate for call %s"), + ; +} \ No newline at end of file diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorSimpleFunctionDescriptorImpl.java b/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorSimpleFunctionDescriptorImpl.java deleted file mode 100644 index 76e50451839..00000000000 --- a/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorSimpleFunctionDescriptorImpl.java +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -package org.jetbrains.kotlin.types.error; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.kotlin.descriptors.*; -import org.jetbrains.kotlin.descriptors.annotations.Annotations; -import org.jetbrains.kotlin.descriptors.impl.FunctionDescriptorImpl; -import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl; -import org.jetbrains.kotlin.name.Name; -import org.jetbrains.kotlin.types.ErrorUtils; -import org.jetbrains.kotlin.types.KotlinType; -import org.jetbrains.kotlin.types.TypeSubstitution; - -import java.util.Collection; -import java.util.List; - -public class ErrorSimpleFunctionDescriptorImpl extends SimpleFunctionDescriptorImpl { - // used for diagnostic only - @SuppressWarnings({"UnusedDeclaration", "FieldCanBeLocal"}) - private final ErrorUtils.ErrorScope ownerScope; - - public ErrorSimpleFunctionDescriptorImpl(@NotNull ClassDescriptor containingDeclaration, @NotNull ErrorUtils.ErrorScope ownerScope) { - super(containingDeclaration, null, Annotations.Companion.getEMPTY(), Name.special(""), Kind.DECLARATION, SourceElement.NO_SOURCE); - this.ownerScope = ownerScope; - } - - @NotNull - @Override - protected FunctionDescriptorImpl createSubstitutedCopy( - @NotNull DeclarationDescriptor newOwner, - @Nullable FunctionDescriptor original, - @NotNull Kind kind, - @Nullable Name newName, - @NotNull Annotations annotations, - @NotNull SourceElement source - ) { - return this; - } - - @NotNull - @Override - public SimpleFunctionDescriptor copy(DeclarationDescriptor newOwner, Modality modality, DescriptorVisibility visibility, Kind kind, boolean copyOverrides) { - return this; - } - - @NotNull - @Override - public CopyBuilder newCopyBuilder() { - return new CopyBuilder() { - @NotNull - @Override - public CopyBuilder setOwner(@NotNull DeclarationDescriptor owner) { - return this; - } - - @NotNull - @Override - public CopyBuilder setModality(@NotNull Modality modality) { - return this; - } - - @NotNull - @Override - public CopyBuilder setVisibility(@NotNull DescriptorVisibility visibility) { - return this; - } - - @NotNull - @Override - public CopyBuilder setKind(@NotNull Kind kind) { - return this; - } - - @NotNull - @Override - public CopyBuilder setCopyOverrides(boolean copyOverrides) { - return this; - } - - @NotNull - @Override - public CopyBuilder setName(@NotNull Name name) { - return this; - } - - @NotNull - @Override - public CopyBuilder setValueParameters(@NotNull List parameters) { - return this; - } - - @NotNull - @Override - public CopyBuilder setSubstitution(@NotNull TypeSubstitution substitution) { - return this; - } - - @NotNull - @Override - public CopyBuilder putUserData( - @NotNull UserDataKey userDataKey, - V value - ) { - return this; - } - - @NotNull - @Override - public CopyBuilder setTypeParameters(@NotNull List parameters) { - return this; - } - - @NotNull - @Override - public CopyBuilder setReturnType(@NotNull KotlinType type) { - return this; - } - - @NotNull - @Override - public CopyBuilder setContextReceiverParameters(@NotNull List contextReceiverParameters) { - return this; - } - - @NotNull - @Override - public CopyBuilder setExtensionReceiverParameter(@Nullable ReceiverParameterDescriptor extensionReceiverParameter) { - return this; - } - - @NotNull - @Override - public CopyBuilder setDispatchReceiverParameter(@Nullable ReceiverParameterDescriptor dispatchReceiverParameter) { - return this; - } - - @NotNull - @Override - public CopyBuilder setOriginal(@Nullable CallableMemberDescriptor original) { - return this; - } - - @NotNull - @Override - public CopyBuilder setSignatureChange() { - return this; - } - - @NotNull - @Override - public CopyBuilder setPreserveSourceElement() { - return this; - } - - @NotNull - @Override - public CopyBuilder setDropOriginalInContainingParts() { - return this; - } - - @NotNull - @Override - public CopyBuilder setHiddenToOvercomeSignatureClash() { - return this; - } - - @NotNull - @Override - public CopyBuilder setHiddenForResolutionEverywhereBesideSupercalls() { - return this; - } - - @NotNull - @Override - public CopyBuilder setAdditionalAnnotations(@NotNull Annotations additionalAnnotations) { - return this; - } - - @Nullable - @Override - public SimpleFunctionDescriptor build() { - return ErrorSimpleFunctionDescriptorImpl.this; - } - }; - } - - @Override - public boolean isSuspend() { - return false; - } - - @Override - public V getUserData(UserDataKey key) { - return null; - } - - @Override - public void setOverriddenDescriptors(@NotNull Collection overriddenDescriptors) { - // nop - } -} diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorType.kt b/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorType.kt new file mode 100644 index 00000000000..8239e37a2c3 --- /dev/null +++ b/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorType.kt @@ -0,0 +1,32 @@ +/* + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.types.error + +import org.jetbrains.kotlin.resolve.scopes.MemberScope +import org.jetbrains.kotlin.types.* +import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner + +class ErrorType @JvmOverloads internal constructor( + override val constructor: TypeConstructor, + override val memberScope: MemberScope, + val kind: ErrorTypeKind, + override val arguments: List = emptyList(), + override val isMarkedNullable: Boolean = false, + private vararg val formatParams: String +) : SimpleType() { + val debugMessage = String.format(kind.debugMessage, *formatParams) + + override val attributes: TypeAttributes + get() = TypeAttributes.Empty + + override fun replaceAttributes(newAttributes: TypeAttributes): SimpleType = this + + override fun makeNullableAsSpecified(newNullability: Boolean): SimpleType = + ErrorType(constructor, memberScope, kind, arguments, newNullability, *formatParams) + + @TypeRefinement + override fun refine(kotlinTypeRefiner: KotlinTypeRefiner) = this +} diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorTypeConstructor.kt b/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorTypeConstructor.kt new file mode 100644 index 00000000000..e022dc7f3d9 --- /dev/null +++ b/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorTypeConstructor.kt @@ -0,0 +1,31 @@ +/* + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.types.error + +import org.jetbrains.kotlin.builtins.DefaultBuiltIns +import org.jetbrains.kotlin.builtins.KotlinBuiltIns +import org.jetbrains.kotlin.descriptors.ClassifierDescriptor +import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor +import org.jetbrains.kotlin.types.KotlinType +import org.jetbrains.kotlin.types.TypeConstructor +import org.jetbrains.kotlin.types.TypeRefinement +import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner + +class ErrorTypeConstructor(val kind: ErrorTypeKind, private vararg val formatParams: String) : TypeConstructor { + private val debugText = ErrorEntity.ERROR_TYPE.debugText.format(kind.debugMessage.format(*formatParams)) + + fun getParam(i: Int): String = formatParams[i] + + override fun getParameters(): List = emptyList() + override fun getSupertypes(): Collection = emptyList() + override fun isFinal(): Boolean = false + override fun isDenotable(): Boolean = false + override fun getDeclarationDescriptor(): ClassifierDescriptor = ErrorUtils.errorClass + override fun getBuiltIns(): KotlinBuiltIns = DefaultBuiltIns.Instance + override fun toString(): String = debugText + @TypeRefinement + override fun refine(kotlinTypeRefiner: KotlinTypeRefiner): TypeConstructor = this +} diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorTypeKind.kt b/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorTypeKind.kt new file mode 100644 index 00000000000..3ebc779c4b3 --- /dev/null +++ b/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorTypeKind.kt @@ -0,0 +1,121 @@ +/* + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.types.error + +enum class ErrorTypeKind(val debugMessage: String, val isUnresolved: Boolean = false) { + /* Unresolved types */ + UNRESOLVED_TYPE("Unresolved type for %s", true), + UNRESOLVED_TYPE_PARAMETER_TYPE("Unresolved type parameter type", true), + UNRESOLVED_CLASS_TYPE("Unresolved class %s", true), + UNRESOLVED_JAVA_CLASS("Unresolved java class %s", true), + UNRESOLVED_DECLARATION("Unresolved declaration %s", true), + UNRESOLVED_KCLASS_CONSTANT_VALUE("Unresolved type for %s (arrayDimensions=%s)", true), + UNRESOLVED_TYPE_ALIAS("Unresolved type alias %s"), + + /* Return types */ + RETURN_TYPE("Return type for %s cannot be resolved"), + RETURN_TYPE_FOR_FUNCTION("Return type for function cannot be resolved"), + RETURN_TYPE_FOR_PROPERTY("Return type for property %s cannot be resolved"), + RETURN_TYPE_FOR_CONSTRUCTOR("Return type for constructor %s cannot be resolved"), + IMPLICIT_RETURN_TYPE_FOR_FUNCTION("Implicit return type for function %s cannot be resolved"), + IMPLICIT_RETURN_TYPE_FOR_PROPERTY("Implicit return type for property %s cannot be resolved"), + IMPLICIT_RETURN_TYPE_FOR_PROPERTY_ACCESSOR("Implicit return type for property accessor %s cannot be resolved"), + ERROR_TYPE_FOR_DESTRUCTURING_COMPONENT("%s() return type"), + + /* Recursion or cyclic */ + RECURSIVE_TYPE("Recursive type"), + RECURSIVE_TYPE_ALIAS("Recursive type alias %s"), + RECURSIVE_ANNOTATION_TYPE("Recursive annotation's type"), + CYCLIC_UPPER_BOUNDS("Cyclic upper bounds"), + CYCLIC_SUPERTYPES("Cyclic supertypes"), + + /* Resolution and type inference */ + UNINFERRED_LAMBDA_CONTEXT_RECEIVER_TYPE("Cannot infer a lambda context receiver type"), + UNINFERRED_LAMBDA_PARAMETER_TYPE("Cannot infer a lambda parameter type"), + UNINFERRED_TYPE_VARIABLE("Cannot infer a type variable %s"), + RESOLUTION_ERROR_TYPE("Resolution error type (%s)"), + ERROR_EXPECTED_TYPE("Error expected type"), + ERROR_DATA_FLOW_TYPE("Error type for data flow"), + ERROR_WHILE_RECONSTRUCTING_BARE_TYPE("Failed to reconstruct type %s"), + UNABLE_TO_SUBSTITUTE_TYPE("Unable to substitute type (%s)"), + + /* Special internal error types */ + DONT_CARE("Special DONT_CARE type"), + STUB_TYPE("Stub type %s"), + FUNCTION_PLACEHOLDER_TYPE("Function placeholder type (arguments: %s)"), + TYPE_FOR_RESULT("Stubbed 'Result' type"), + TYPE_FOR_COMPILER_EXCEPTION("Error type for a compiler exception while analyzing %s"), + + /* Inconsistent types */ + ERROR_FLEXIBLE_TYPE("Error java flexible type with id %s. (%s..%s)"), + ERROR_RAW_TYPE("Error raw type %s"), + TYPE_WITH_MISMATCHED_TYPE_ARGUMENTS_AND_PARAMETERS("Inconsistent type %s (parameters.size = %s, arguments.size = %s)"), + ILLEGAL_TYPE_RANGE_FOR_DYNAMIC("Illegal type range for dynamic type %s..%s"), + + /* Deserialization */ + CANNOT_LOAD_DESERIALIZE_TYPE_PARAMETER("Unknown type parameter %s. Please try recompiling module containing \"%s\""), + CANNOT_LOAD_DESERIALIZE_TYPE_PARAMETER_BY_NAME("Couldn't deserialize type parameter %s in %s"), + INCONSISTENT_SUSPEND_FUNCTION("Inconsistent suspend function type in metadata with constructor %s"), + UNEXPECTED_FLEXIBLE_TYPE_ID("Unexpected id of a flexible type %s. (%s..%s)"), + UNKNOWN_TYPE("Unknown type"), + + /* Stubs for not specified types */ + NO_TYPE_SPECIFIED("No type specified for %s"), + NO_TYPE_FOR_LOOP_RANGE("Loop range has no type"), + NO_TYPE_FOR_LOOP_PARAMETER("Loop parameter has no type"), + MISSED_TYPE_FOR_PARAMETER("Missed a type for a value parameter %s"), + MISSED_TYPE_ARGUMENT_FOR_TYPE_PARAMETER("Missed a type argument for a type parameter %s"), + + /* Illegal type usages */ + PARSE_ERROR_ARGUMENT("Error type for parse error argument %s"), + STAR_PROJECTION_IN_CALL("Error type for star projection directly passing as a call type argument"), + PROHIBITED_DYNAMIC_TYPE("Dynamic type in a not allowed context"), + NOT_ANNOTATION_TYPE_IN_ANNOTATION_CONTEXT("Not an annotation type %s in the annotation context"), + UNIT_RETURN_TYPE_FOR_INC_DEC("Unit type returned by inc or dec"), + RETURN_NOT_ALLOWED("Return not allowed"), + + /* Plugin related */ + UNRESOLVED_PARCEL_TYPE("Unresolved 'Parcel' type", true), + KAPT_ERROR_TYPE("Kapt error type"), + SYNTHETIC_ELEMENT_ERROR_TYPE("Error type for synthetic element"), + AD_HOC_ERROR_TYPE_FOR_LIGHTER_CLASSES_RESOLVE("Error type in ad hoc resolve for lighter classes"), + + /* Expressions related types */ + ERROR_EXPRESSION_TYPE("Error expression type"), + ERROR_RECEIVER_TYPE("Error receiver type for %s"), + ERROR_CONSTANT_VALUE("Error constant value %s"), + EMPTY_CALLABLE_REFERENCE("Empty callable reference"), + UNSUPPORTED_CALLABLE_REFERENCE_TYPE("Unsupported callable reference type %s"), + TYPE_FOR_DELEGATION("Error delegation type for %s"), + + /* Declaration related types */ + UNAVAILABLE_TYPE_FOR_DECLARATION("Type is unavailable for declaration %s"), + ERROR_TYPE_PARAMETER("Error type parameter"), + ERROR_TYPE_PROJECTION("Error type projection"), + ERROR_SUPER_TYPE("Error super type"), + SUPER_TYPE_FOR_ERROR_TYPE("Supertype of error type %s"), + ERROR_PROPERTY_TYPE("Error property type"), + ERROR_CLASS("Error class"), + TYPE_FOR_ERROR_TYPE_CONSTRUCTOR("Type for error type constructor (%s)"), + INTERSECTION_OF_ERROR_TYPES("Intersection of error types %s"), + CANNOT_COMPUTE_ERASED_BOUND("Cannot compute erased upper bound of a type parameter %s"), + + /* Couldn't load a type */ + NOT_FOUND_UNSIGNED_TYPE("Unsigned type %s not found"), + ERROR_ENUM_TYPE("Not found the corresponding enum class for given enum entry %s.%s"), + NO_RECORDED_TYPE("Not found recorded type for %s"), + NOT_FOUND_DESCRIPTOR_FOR_FUNCTION("Descriptor not found for function %s"), + NOT_FOUND_DESCRIPTOR_FOR_CLASS("Cannot build class type, descriptor not found for builder %s"), + NOT_FOUND_DESCRIPTOR_FOR_TYPE_PARAMETER("Cannot build type parameter type, descriptor not found for builder %s"), + UNMAPPED_ANNOTATION_TARGET_TYPE("Type for unmapped Java annotation target to Kotlin one"), // java.lang.annotation.Target -> kotlin.annotation.Target + UNKNOWN_ARRAY_ELEMENT_TYPE_OF_ANNOTATION_ARGUMENT("Unknown type for an array element of a java annotation argument"), + NOT_FOUND_FQNAME_FOR_JAVA_ANNOTATION("No fqName for annotation %s"), + NOT_FOUND_FQNAME("No fqName for %s"), + + /* Other error types */ + TYPE_FOR_GENERATED_ERROR_EXPRESSION("Type for generated error expression"), + ; +} diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorUtils.kt b/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorUtils.kt new file mode 100644 index 00000000000..b9f77d1610e --- /dev/null +++ b/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorUtils.kt @@ -0,0 +1,102 @@ +/* + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.types.error + +import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.types.* +import org.jetbrains.kotlin.types.typeUtil.contains + +object ErrorUtils { + val errorModule: ModuleDescriptor = ErrorModuleDescriptor + val errorClass: ErrorClassDescriptor = ErrorClassDescriptor(Name.special(ErrorEntity.ERROR_CLASS.debugText.format("unknown class"))) + + // Do not move it into AbstractTypeConstructor.Companion because of cycle in initialization(see KT-13264) + val errorTypeForLoopInSupertypes: KotlinType = createErrorType(ErrorTypeKind.CYCLIC_SUPERTYPES) + val errorPropertyType: KotlinType = createErrorType(ErrorTypeKind.ERROR_PROPERTY_TYPE) + + private val errorProperty: PropertyDescriptor = ErrorPropertyDescriptor() + val errorPropertyGroup: Set = setOf(errorProperty) + + /** + * @return true if any of the types referenced in parameter types (including type parameters and extension receiver) of the function + * is an error type. Does not check the return type of the function. + */ + fun containsErrorTypeInParameters(function: FunctionDescriptor): Boolean { + val receiverParameter = function.extensionReceiverParameter + if (receiverParameter != null && containsErrorType(receiverParameter.type)) + return true + + for (parameter in function.valueParameters) { + if (containsErrorType(parameter.type)) + return true + } + + for (parameter in function.typeParameters) { + for (upperBound in parameter.upperBounds) { + if (containsErrorType(upperBound)) + return true + } + } + return false + } + + @JvmStatic + fun createErrorScope(kind: ErrorScopeKind, vararg formatParams: String): ErrorScope = + createErrorScope(kind, throwExceptions = false, *formatParams) + + @JvmStatic + fun createErrorScope(kind: ErrorScopeKind, throwExceptions: Boolean, vararg formatParams: String): ErrorScope = + if (throwExceptions) ThrowingScope(kind, *formatParams) else ErrorScope(kind, *formatParams) + + @JvmStatic + fun createErrorType(kind: ErrorTypeKind, vararg formatParams: String): ErrorType = + createErrorTypeWithArguments(kind, emptyList(), *formatParams) + + fun createErrorType(kind: ErrorTypeKind, typeConstructor: TypeConstructor, vararg formatParams: String): ErrorType = + createErrorTypeWithArguments(kind, emptyList(), typeConstructor, *formatParams) + + fun createErrorTypeWithArguments(kind: ErrorTypeKind, arguments: List, vararg formatParams: String): ErrorType = + createErrorTypeWithArguments(kind, arguments, createErrorTypeConstructor(kind, *formatParams), *formatParams) + + fun createErrorTypeWithArguments( + kind: ErrorTypeKind, + arguments: List, + typeConstructor: TypeConstructor, + vararg formatParams: String + ): ErrorType = ErrorType( + typeConstructor, createErrorScope(ErrorScopeKind.ERROR_TYPE_SCOPE, typeConstructor.toString()), + kind, arguments, isMarkedNullable = false, *formatParams + ) + + fun createErrorTypeConstructor(kind: ErrorTypeKind, vararg formatParams: String): ErrorTypeConstructor = + ErrorTypeConstructor(kind, *formatParams) + + fun containsErrorType(type: KotlinType?): Boolean { + if (type == null) return false + if (type.isError) return true + for (projection in type.arguments) { + if (!projection.isStarProjection && containsErrorType(projection.type)) + return true + } + return false + } + + @JvmStatic + fun isError(candidate: DeclarationDescriptor?): Boolean = + candidate != null && (isErrorClass(candidate) || isErrorClass(candidate.containingDeclaration) || candidate === errorModule) + + private fun isErrorClass(candidate: DeclarationDescriptor?): Boolean = candidate is ErrorClassDescriptor + + @JvmStatic + fun isUninferredTypeVariable(type: KotlinType?): Boolean { + if (type == null) return false + val constructor = type.constructor + return constructor is ErrorTypeConstructor && constructor.kind == ErrorTypeKind.UNINFERRED_TYPE_VARIABLE + } + + fun containsUninferredTypeVariable(type: KotlinType): Boolean = type.contains(::isUninferredTypeVariable) +} diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/error/ThrowingScope.kt b/core/descriptors/src/org/jetbrains/kotlin/types/error/ThrowingScope.kt new file mode 100644 index 00000000000..ca3c070b934 --- /dev/null +++ b/core/descriptors/src/org/jetbrains/kotlin/types/error/ThrowingScope.kt @@ -0,0 +1,41 @@ +/* + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.types.error + +import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.incremental.components.LookupLocation +import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter +import org.jetbrains.kotlin.utils.Printer + +class ThrowingScope(kind: ErrorScopeKind, vararg formatParams: String) : ErrorScope(kind, *formatParams) { + override fun getContributedClassifier(name: Name, location: LookupLocation): ClassifierDescriptor = + throw IllegalStateException("$debugMessage, required name: $name") + + override fun getContributedClassifierIncludeDeprecated( + name: Name, location: LookupLocation + ): DescriptorWithDeprecation = throw IllegalStateException("$debugMessage, required name: $name") + + override fun getContributedVariables(name: Name, location: LookupLocation): Set = + throw IllegalStateException("$debugMessage, required name: $name") + + override fun getContributedFunctions(name: Name, location: LookupLocation): Set = + throw IllegalStateException("$debugMessage, required name: $name") + + override fun getContributedDescriptors( + kindFilter: DescriptorKindFilter, nameFilter: Function1 + ): Collection = throw IllegalStateException(debugMessage) + + override fun getFunctionNames(): Set = throw IllegalStateException() + override fun getVariableNames(): Set = throw IllegalStateException() + override fun getClassifierNames(): Set = throw IllegalStateException() + override fun recordLookup(name: Name, location: LookupLocation) = throw IllegalStateException() + override fun definitelyDoesNotContainName(name: Name): Boolean = false + override fun toString(): String = "ThrowingScope{$debugMessage}" + override fun printScopeStructure(p: Printer) { + p.println(javaClass.simpleName, ": ", debugMessage) + } +} diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/AnnotationDeserializer.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/AnnotationDeserializer.kt index 862e4468fff..6d40e601010 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/AnnotationDeserializer.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/AnnotationDeserializer.kt @@ -30,7 +30,7 @@ import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.constants.* -import org.jetbrains.kotlin.types.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.KotlinType class AnnotationDeserializer(private val module: ModuleDescriptor, private val notFoundClasses: NotFoundClasses) { diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/TypeDeserializer.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/TypeDeserializer.kt index 756ee73d079..4064bcf1dd4 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/TypeDeserializer.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/TypeDeserializer.kt @@ -18,6 +18,8 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedAnnotations import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedTypeParameterDescriptor import org.jetbrains.kotlin.types.* +import org.jetbrains.kotlin.types.error.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorTypeKind import org.jetbrains.kotlin.types.typeUtil.builtIns import org.jetbrains.kotlin.utils.addToStdlib.safeAs import java.util.* @@ -89,7 +91,7 @@ class TypeDeserializer( val constructor = typeConstructor(proto) if (ErrorUtils.isError(constructor.declarationDescriptor)) { - return ErrorUtils.createErrorTypeWithCustomConstructor(constructor.toString(), constructor) + return ErrorUtils.createErrorType(ErrorTypeKind.TYPE_FOR_ERROR_TYPE_CONSTRUCTOR, constructor, constructor.toString()) } val annotations = DeserializedAnnotations(c.storageManager) { @@ -160,16 +162,18 @@ class TypeDeserializer( proto.hasTypeParameter() -> loadTypeParameter(proto.typeParameter) ?: return ErrorUtils.createErrorTypeConstructor( - "Unknown type parameter ${proto.typeParameter}. Please try recompiling module containing \"$containerPresentableName\"" + ErrorTypeKind.CANNOT_LOAD_DESERIALIZE_TYPE_PARAMETER, proto.typeParameter.toString(), containerPresentableName ) proto.hasTypeParameterName() -> { val name = c.nameResolver.getString(proto.typeParameterName) ownTypeParameters.find { it.name.asString() == name } - ?: return ErrorUtils.createErrorTypeConstructor("Deserialized type parameter $name in ${c.containingDeclaration}") + ?: return ErrorUtils.createErrorTypeConstructor( + ErrorTypeKind.CANNOT_LOAD_DESERIALIZE_TYPE_PARAMETER_BY_NAME, name, c.containingDeclaration.toString() + ) } proto.hasTypeAliasName() -> typeAliasDescriptors(proto.typeAliasName) ?: notFoundClass(proto.typeAliasName) - else -> return ErrorUtils.createErrorTypeConstructor("Unknown type") + else -> return ErrorUtils.createErrorTypeConstructor(ErrorTypeKind.UNKNOWN_TYPE) } return classifier.typeConstructor } @@ -199,8 +203,7 @@ class TypeDeserializer( else -> null } return result ?: ErrorUtils.createErrorTypeWithArguments( - "Bad suspend function in metadata with constructor: $functionTypeConstructor", - arguments + ErrorTypeKind.INCONSISTENT_SUSPEND_FUNCTION, arguments, functionTypeConstructor ) } @@ -291,7 +294,8 @@ class TypeDeserializer( } val projection = ProtoEnumFlags.variance(typeArgumentProto.projection) - val type = typeArgumentProto.type(c.typeTable) ?: return TypeProjectionImpl(ErrorUtils.createErrorType("No type recorded")) + val type = typeArgumentProto.type(c.typeTable) + ?: return TypeProjectionImpl(ErrorUtils.createErrorType(ErrorTypeKind.NO_RECORDED_TYPE, typeArgumentProto.toString())) return TypeProjectionImpl(projection, type(type)) } diff --git a/js/js.frontend/src/org/jetbrains/kotlin/js/analyzer/JsAnalysisResult.kt b/js/js.frontend/src/org/jetbrains/kotlin/js/analyzer/JsAnalysisResult.kt index 98105183549..a24485c4447 100644 --- a/js/js.frontend/src/org/jetbrains/kotlin/js/analyzer/JsAnalysisResult.kt +++ b/js/js.frontend/src/org/jetbrains/kotlin/js/analyzer/JsAnalysisResult.kt @@ -19,8 +19,6 @@ package org.jetbrains.kotlin.js.analyzer import org.jetbrains.kotlin.analyzer.AnalysisResult import org.jetbrains.kotlin.resolve.BindingTrace import org.jetbrains.kotlin.descriptors.ModuleDescriptor -import org.jetbrains.kotlin.resolve.BindingContext -import org.jetbrains.kotlin.types.ErrorUtils import java.io.File open class JsAnalysisResult( diff --git a/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/DynamicTypeDeserializer.kt b/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/DynamicTypeDeserializer.kt index 8df594e253e..b557ff147e3 100644 --- a/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/DynamicTypeDeserializer.kt +++ b/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/DynamicTypeDeserializer.kt @@ -18,25 +18,24 @@ package org.jetbrains.kotlin.serialization.js import org.jetbrains.kotlin.metadata.ProtoBuf import org.jetbrains.kotlin.serialization.deserialization.FlexibleTypeDeserializer -import org.jetbrains.kotlin.types.ErrorUtils -import org.jetbrains.kotlin.types.KotlinType -import org.jetbrains.kotlin.types.SimpleType +import org.jetbrains.kotlin.types.* +import org.jetbrains.kotlin.types.error.ErrorUtils; import org.jetbrains.kotlin.types.checker.StrictEqualityTypeChecker -import org.jetbrains.kotlin.types.createDynamicType +import org.jetbrains.kotlin.types.error.ErrorTypeKind import org.jetbrains.kotlin.types.typeUtil.builtIns object DynamicTypeDeserializer : FlexibleTypeDeserializer { const val id = "kotlin.DynamicType" override fun create(proto: ProtoBuf.Type, flexibleId: String, lowerBound: SimpleType, upperBound: SimpleType): KotlinType { - if (flexibleId != id) return ErrorUtils.createErrorType("Unexpected id: $flexibleId. ($lowerBound..$upperBound)") + if (flexibleId != id) return ErrorUtils.createErrorType(ErrorTypeKind.UNEXPECTED_FLEXIBLE_TYPE_ID, flexibleId, lowerBound.toString(), upperBound.toString()) return if (StrictEqualityTypeChecker.strictEqualTypes(lowerBound, lowerBound.builtIns.nothingType) && StrictEqualityTypeChecker.strictEqualTypes(upperBound, upperBound.builtIns.nullableAnyType) ) { createDynamicType(lowerBound.builtIns) } else { - ErrorUtils.createErrorType("Illegal type range for dynamic type: $lowerBound..$upperBound") + ErrorUtils.createErrorType(ErrorTypeKind.ILLEGAL_TYPE_RANGE_FOR_DYNAMIC, lowerBound.toString(), upperBound.toString()) } } } diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportHeaderGenerator.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportHeaderGenerator.kt index 813aef48985..83597813720 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportHeaderGenerator.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportHeaderGenerator.kt @@ -19,7 +19,7 @@ import org.jetbrains.kotlin.resolve.deprecation.DeprecationInfo import org.jetbrains.kotlin.resolve.deprecation.DeprecationLevelValue import org.jetbrains.kotlin.resolve.descriptorUtil.* import org.jetbrains.kotlin.resolve.scopes.MemberScope -import org.jetbrains.kotlin.types.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.TypeUtils import org.jetbrains.kotlin.types.typeUtil.builtIns diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportLazy.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportLazy.kt index 4a030ac4549..528b4536ef1 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportLazy.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportLazy.kt @@ -36,7 +36,7 @@ import org.jetbrains.kotlin.resolve.scopes.LexicalScopeKind import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope import org.jetbrains.kotlin.resolve.scopes.LocalRedeclarationChecker import org.jetbrains.kotlin.resolve.source.PsiSourceFile -import org.jetbrains.kotlin.types.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorUtils interface ObjCExportLazy { interface Configuration { diff --git a/plugins/android-extensions/android-extensions-compiler/src/org/jetbrains/kotlin/android/parcel/ParcelableResolveExtension.kt b/plugins/android-extensions/android-extensions-compiler/src/org/jetbrains/kotlin/android/parcel/ParcelableResolveExtension.kt index ed9bac8c5a8..2bb94542cd9 100644 --- a/plugins/android-extensions/android-extensions-compiler/src/org/jetbrains/kotlin/android/parcel/ParcelableResolveExtension.kt +++ b/plugins/android-extensions/android-extensions-compiler/src/org/jetbrains/kotlin/android/parcel/ParcelableResolveExtension.kt @@ -35,7 +35,8 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe import org.jetbrains.kotlin.resolve.descriptorUtil.module import org.jetbrains.kotlin.resolve.extensions.SyntheticResolveExtension -import org.jetbrains.kotlin.types.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorTypeKind +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.SimpleType @@ -120,7 +121,7 @@ open class ParcelableResolveExtension : SyntheticResolveExtension { && result.none { it.isWriteToParcel() } ) { val builtIns = thisDescriptor.builtIns - val parcelClassType = resolveParcelClassType(thisDescriptor.module) ?: ErrorUtils.createErrorType("Unresolved 'Parcel' type") + val parcelClassType = resolveParcelClassType(thisDescriptor.module) ?: ErrorUtils.createErrorType(ErrorTypeKind.UNRESOLVED_PARCEL_TYPE) result += createMethod( thisDescriptor, WRITE_TO_PARCEL, Modality.OPEN, builtIns.unitType, "parcel" to parcelClassType, "flags" to builtIns.intType diff --git a/plugins/android-extensions/android-extensions-compiler/src/org/jetbrains/kotlin/android/synthetic/descriptors/LazySyntheticElementResolveContext.kt b/plugins/android-extensions/android-extensions-compiler/src/org/jetbrains/kotlin/android/synthetic/descriptors/LazySyntheticElementResolveContext.kt index 8f9ddad2aa3..8e82e0dfe9f 100644 --- a/plugins/android-extensions/android-extensions-compiler/src/org/jetbrains/kotlin/android/synthetic/descriptors/LazySyntheticElementResolveContext.kt +++ b/plugins/android-extensions/android-extensions-compiler/src/org/jetbrains/kotlin/android/synthetic/descriptors/LazySyntheticElementResolveContext.kt @@ -24,7 +24,8 @@ import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.resolve.descriptorUtil.module import org.jetbrains.kotlin.storage.StorageManager -import org.jetbrains.kotlin.types.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorTypeKind +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.SimpleType import java.util.* @@ -67,7 +68,7 @@ internal class SyntheticElementResolveContext( val layoutContainer: SimpleType? ) { companion object { - private fun errorType() = ErrorUtils.createErrorType("") + private fun errorType() = ErrorUtils.createErrorType(ErrorTypeKind.SYNTHETIC_ELEMENT_ERROR_TYPE) val ERROR_CONTEXT = SyntheticElementResolveContext(errorType(), errorType(), null, errorType(), null, null, null) } diff --git a/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/ClassFileToSourceStubConverter.kt b/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/ClassFileToSourceStubConverter.kt index f7d06fe8b9e..136844e6d5e 100644 --- a/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/ClassFileToSourceStubConverter.kt +++ b/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/ClassFileToSourceStubConverter.kt @@ -63,7 +63,8 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperClassOrAny import org.jetbrains.kotlin.resolve.descriptorUtil.isCompanionObject import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin import org.jetbrains.kotlin.resolve.source.getPsi -import org.jetbrains.kotlin.types.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorTypeKind +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.isError import org.jetbrains.kotlin.types.typeUtil.isEnum @@ -530,7 +531,7 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati assert(correctErrorTypes) return getNonErrorType( - ErrorUtils.createErrorType("Error super class"), + ErrorUtils.createErrorType(ErrorTypeKind.ERROR_SUPER_TYPE), ErrorTypeCorrector.TypeKind.SUPER_TYPE, ref ) { throw SuperTypeCalculationFailure() } diff --git a/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/ErrorTypeCorrector.kt b/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/ErrorTypeCorrector.kt index 2a31e9e3b2c..9d93c8d25b4 100644 --- a/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/ErrorTypeCorrector.kt +++ b/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/ErrorTypeCorrector.kt @@ -34,6 +34,8 @@ import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.source.getPsi import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.checker.SimpleClassicTypeSystemContext +import org.jetbrains.kotlin.types.error.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorTypeKind private typealias SubstitutionMap = Map> @@ -137,7 +139,7 @@ class ErrorTypeCorrector( if (arguments.isEmpty()) return baseExpression val typeReference = PsiTreeUtil.getParentOfType(type, KtTypeReference::class.java, true) - val kotlinType = bindingContext[BindingContext.TYPE, typeReference] ?: ErrorUtils.createErrorType("Kapt error type") + val kotlinType = bindingContext[BindingContext.TYPE, typeReference] ?: ErrorUtils.createErrorType(ErrorTypeKind.KAPT_ERROR_TYPE) val typeSystem = SimpleClassicTypeSystemContext val typeMappingMode = when (typeKind) { diff --git a/plugins/parcelize/parcelize-compiler/src/org/jetbrains/kotlin/parcelize/ParcelizeResolveExtension.kt b/plugins/parcelize/parcelize-compiler/src/org/jetbrains/kotlin/parcelize/ParcelizeResolveExtension.kt index 6dcd21a24b3..197180e98c4 100644 --- a/plugins/parcelize/parcelize-compiler/src/org/jetbrains/kotlin/parcelize/ParcelizeResolveExtension.kt +++ b/plugins/parcelize/parcelize-compiler/src/org/jetbrains/kotlin/parcelize/ParcelizeResolveExtension.kt @@ -41,7 +41,8 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.descriptorUtil.* import org.jetbrains.kotlin.resolve.extensions.SyntheticResolveExtension import org.jetbrains.kotlin.resolve.source.PsiSourceElement -import org.jetbrains.kotlin.types.ErrorUtils +import org.jetbrains.kotlin.types.error.ErrorTypeKind +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.SimpleType @@ -141,7 +142,7 @@ open class ParcelizeResolveExtension : SyntheticResolveExtension { && result.none { it.isWriteToParcel() } ) { val builtIns = thisDescriptor.builtIns - val parcelClassType = resolveParcelClassType(thisDescriptor.module) ?: ErrorUtils.createErrorType("Unresolved 'Parcel' type") + val parcelClassType = resolveParcelClassType(thisDescriptor.module) ?: ErrorUtils.createErrorType(ErrorTypeKind.UNRESOLVED_PARCEL_TYPE) result += createMethod( thisDescriptor, WRITE_TO_PARCEL, Modality.OPEN, builtIns.unitType, "parcel" to parcelClassType, "flags" to builtIns.intType diff --git a/plugins/scripting/scripting-ide-common/src/org/jetbrains/kotlin/scripting/ide_common/idea/util/FuzzyType.kt b/plugins/scripting/scripting-ide-common/src/org/jetbrains/kotlin/scripting/ide_common/idea/util/FuzzyType.kt index c2e7ef6cd7f..bfc057cc1f6 100644 --- a/plugins/scripting/scripting-ide-common/src/org/jetbrains/kotlin/scripting/ide_common/idea/util/FuzzyType.kt +++ b/plugins/scripting/scripting-ide-common/src/org/jetbrains/kotlin/scripting/ide_common/idea/util/FuzzyType.kt @@ -14,6 +14,7 @@ import org.jetbrains.kotlin.resolve.calls.inference.CallHandle import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilderImpl import org.jetbrains.kotlin.resolve.calls.inference.constraintPosition.ConstraintPositionKind import org.jetbrains.kotlin.types.* +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.checker.StrictEqualityTypeChecker import org.jetbrains.kotlin.types.typeUtil.* import java.util.* @@ -142,7 +143,7 @@ class FuzzyType( valueTransform = { val typeProjection = TypeProjectionImpl(Variance.INVARIANT, it.defaultType) val substitutedProjection = substitutorToKeepCapturedTypes.substitute(typeProjection) - substitutedProjection?.takeUnless { ErrorUtils.containsUninferredParameter(it.type) } ?: typeProjection + substitutedProjection?.takeUnless { ErrorUtils.containsUninferredTypeVariable(it.type) } ?: typeProjection }) return TypeConstructorSubstitution.createByConstructorsMap(substitutionMap, approximateCapturedTypes = true).buildSubstitutor() } diff --git a/plugins/scripting/scripting-ide-common/src/org/jetbrains/kotlin/scripting/ide_common/idea/util/TypeUtils.kt b/plugins/scripting/scripting-ide-common/src/org/jetbrains/kotlin/scripting/ide_common/idea/util/TypeUtils.kt index 5d163cdc82a..1bf6a89f9b2 100644 --- a/plugins/scripting/scripting-ide-common/src/org/jetbrains/kotlin/scripting/ide_common/idea/util/TypeUtils.kt +++ b/plugins/scripting/scripting-ide-common/src/org/jetbrains/kotlin/scripting/ide_common/idea/util/TypeUtils.kt @@ -10,6 +10,9 @@ package org.jetbrains.kotlin.scripting.ide_common.idea.util import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMapper import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.types.* +import org.jetbrains.kotlin.types.error.ErrorScopeKind +import org.jetbrains.kotlin.types.error.ErrorType +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.typeUtil.TypeNullability import org.jetbrains.kotlin.types.typeUtil.nullability import org.jetbrains.kotlin.types.typeUtil.substitute @@ -73,6 +76,6 @@ private fun KotlinType.approximateNonDynamicFlexibleTypes( constructor, arguments.map { it.substitute { type -> type.approximateFlexibleTypes(preferNotNull = true) } }, isMarkedNullable, - ErrorUtils.createErrorScope("This type is not supposed to be used in member resolution", true) + ErrorUtils.createErrorScope(ErrorScopeKind.UNSUPPORTED_TYPE_SCOPE, true) ) }