[FE 1.0] Refactor error utils: split error entities and introduce error type and error scope kinds

This commit is contained in:
Victor Petukhov
2022-03-17 13:32:36 +04:00
committed by teamcity
parent 8c1fcddea3
commit b5933c70e2
139 changed files with 1061 additions and 1204 deletions
@@ -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 {
@@ -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
@@ -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;
}
@@ -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;
@@ -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
@@ -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 {
@@ -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;
}
@@ -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())
}
}
@@ -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 {
@@ -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<KtTypeProjection>,
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!!)
@@ -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<DeclarationSignatureAnonymousTypeTransformer>
) {
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
@@ -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())
)
}
@@ -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
}
@@ -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<KotlinType>()
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
}
@@ -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)
}
@@ -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) {
@@ -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 {
@@ -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
}
@@ -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) ->
@@ -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.*
@@ -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
@@ -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)
}
}
@@ -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
@@ -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;
@@ -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)
}
@@ -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()),
)
}
@@ -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
)
@@ -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
@@ -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
@@ -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)
)
}
@@ -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) {
@@ -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)
}
)
@@ -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);
}
@@ -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<Boolean, KotlinType> RECURSION_PREVENTER = firstTime -> {
if (firstTime) throw new ReenteringLazyValueComputationException();
return ErrorUtils.createErrorType("Recursive dependency");
return ErrorUtils.createErrorType(ErrorTypeKind.RECURSIVE_TYPE);
};
@NotNull
@@ -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;
@@ -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;
@@ -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")) {
@@ -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()
@@ -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)
}
@@ -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);
}
}
@@ -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<Kotlin
return typeInfo;
}
return typeInfo
.replaceType(ErrorUtils.createErrorType("Type for " + expression.getText()))
.replaceType(ErrorUtils.createErrorType(ErrorTypeKind.NO_RECORDED_TYPE, expression.getText()))
.replaceDataFlowInfo(context.dataFlowInfo);
}
@@ -223,7 +224,7 @@ public abstract class ExpressionTypingVisitorDispatcher extends KtVisitor<Kotlin
context.trace.report(Errors.EXCEPTION_FROM_ANALYZER.on(expression, e));
logOrThrowException(expression, e);
return TypeInfoFactoryKt.createTypeInfo(
ErrorUtils.createErrorType(e.getClass().getSimpleName() + " from analyzer"),
ErrorUtils.createErrorType(ErrorTypeKind.TYPE_FOR_COMPILER_EXCEPTION, e.getClass().getSimpleName()),
context
);
}
@@ -31,7 +31,7 @@ import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResults;
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver;
import org.jetbrains.kotlin.resolve.scopes.receivers.TransientReceiver;
import org.jetbrains.kotlin.types.DynamicTypesKt;
import org.jetbrains.kotlin.types.ErrorUtils;
import org.jetbrains.kotlin.types.error.ErrorUtils;
import org.jetbrains.kotlin.types.KotlinType;
import org.jetbrains.kotlin.util.OperatorNameConventions;
import org.jetbrains.kotlin.util.slicedMap.WritableSlice;
@@ -243,7 +243,7 @@ internal class FunctionsTypingVisitor(facade: ExpressionTypingInternals) : Expre
return components.builtIns.unitType
}
}
return returnType ?: CANT_INFER_FUNCTION_PARAM_TYPE
return returnType ?: CANNOT_INFER_FUNCTION_PARAM_TYPE
}
private fun computeUnsafeReturnType(
@@ -37,8 +37,10 @@ import org.jetbrains.kotlin.resolve.checkers.PrimitiveNumericComparisonCallCheck
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
import org.jetbrains.kotlin.resolve.scopes.LexicalScopeKind
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.KotlinTypeChecker
import org.jetbrains.kotlin.types.error.ErrorTypeKind
import org.jetbrains.kotlin.types.expressions.ControlStructureTypingUtils.*
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.createTypeInfo
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.noTypeInfo
@@ -92,7 +94,7 @@ class PatternMatchingTypingVisitor internal constructor(facade: ExpressionTyping
val element: KtElement?,
val typeInfo: KotlinTypeInfo?,
val scopeWithSubject: LexicalScope?,
val type: KotlinType = typeInfo?.type ?: ErrorUtils.createErrorType("Unknown type")
val type: KotlinType = typeInfo?.type ?: ErrorUtils.createErrorType(ErrorTypeKind.UNKNOWN_TYPE)
) {
protected abstract fun createDataFlowValue(contextAfterSubject: ExpressionTypingContext, builtIns: KotlinBuiltIns): DataFlowValue
@@ -24,10 +24,9 @@ import org.jetbrains.kotlin.psi.KtTypeReference;
import org.jetbrains.kotlin.resolve.BindingContext;
import org.jetbrains.kotlin.resolve.BindingTrace;
import org.jetbrains.kotlin.resolve.PossiblyBareType;
import org.jetbrains.kotlin.types.ErrorUtils;
import org.jetbrains.kotlin.types.KotlinType;
import org.jetbrains.kotlin.types.TypeConstructor;
import org.jetbrains.kotlin.types.TypeReconstructionResult;
import org.jetbrains.kotlin.types.*;
import org.jetbrains.kotlin.types.error.ErrorUtils;
import org.jetbrains.kotlin.types.error.ErrorTypeKind;
import static org.jetbrains.kotlin.diagnostics.Errors.NO_TYPE_ARGUMENTS_ON_RHS;
@@ -60,7 +59,7 @@ public class TypeReconstructionUtil {
return targetType;
}
return ErrorUtils.createErrorType("Failed to reconstruct type: " + right.getText());
return ErrorUtils.createErrorType(ErrorTypeKind.ERROR_WHILE_RECONSTRUCTING_BARE_TYPE, right.getText());
}
@NotNull