Make KotlinType.isError extension instead of member

This commit is contained in:
Alexander Udalov
2017-04-24 18:25:58 +03:00
parent 787a32f4f1
commit 38ea9986ab
71 changed files with 154 additions and 131 deletions
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.diagnostics.DiagnosticFactory;
import org.jetbrains.kotlin.diagnostics.Errors;
import org.jetbrains.kotlin.resolve.VarianceConflictDiagnosticData;
import org.jetbrains.kotlin.serialization.deserialization.descriptors.SinceKotlinInfo;
import org.jetbrains.kotlin.types.KotlinTypeKt;
import org.jetbrains.kotlin.util.MappedExtensionProvider;
import org.jetbrains.kotlin.util.OperatorNameConventions;
@@ -696,7 +697,7 @@ public class DefaultErrorMessages {
MAP.put(FUNCTION_EXPECTED, "Expression ''{0}''{1} cannot be invoked as a function. " +
"The function ''" + OperatorNameConventions.INVOKE.asString() + "()'' is not found",
ELEMENT_TEXT, (type, context) -> {
if (type.isError()) return "";
if (KotlinTypeKt.isError(type)) return "";
return " of type '" + RENDER_TYPE.render(type, context) + "'";
});
MAP.put(FUNCTION_CALL_EXPECTED, "Function invocation ''{0}({1})'' expected", ELEMENT_TEXT,
@@ -36,6 +36,7 @@ import org.jetbrains.kotlin.resolve.inline.InlineUtil
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.TypeUtils
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils
import org.jetbrains.kotlin.types.isError
class AnnotationChecker(private val additionalCheckers: Iterable<AdditionalAnnotationChecker>) {
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.resolve.OverridingUtil.OverrideCompatibilityInfo.Res
import org.jetbrains.kotlin.resolve.lazy.DelegationFilter
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.isDynamic
import org.jetbrains.kotlin.types.isError
import org.jetbrains.kotlin.utils.keysToMapExceptNulls
class DelegationResolver<T : CallableMemberDescriptor> private constructor(
@@ -152,7 +152,7 @@ public class DescriptorResolver {
}
private static void addValidSupertype(List<KotlinType> supertypes, KotlinType declaredSupertype) {
if (!declaredSupertype.isError()) {
if (!KotlinTypeKt.isError(declaredSupertype)) {
supertypes.add(declaredSupertype);
}
}
@@ -251,7 +251,7 @@ public class DescriptorResolver {
}
// If we have an abbreviated type (written with a type alias), it still can contain type projections in top-level arguments.
if (!type.isError() && SpecialTypesKt.getAbbreviatedType(type) != null && !hasProjectionsInWrittenArguments) {
if (!KotlinTypeKt.isError(type) && SpecialTypesKt.getAbbreviatedType(type) != null && !hasProjectionsInWrittenArguments) {
// Only interface inheritance should be checked here.
// Corresponding check for classes is performed for type alias constructor calls in CandidateResolver.
if (TypeUtilsKt.isInterface(type) && TypeUtilsKt.containsTypeProjectionsInTopLevelArguments(type)) {
@@ -566,7 +566,7 @@ public class DescriptorResolver {
KotlinType upperBound = request.upperBoundType;
KtTypeReference upperBoundElement = request.upperBound;
if (!upperBound.isError()) {
if (!KotlinTypeKt.isError(upperBound)) {
if (!allBounds.add(new Pair<>(typeParameterName, upperBound.getConstructor()))) {
trace.report(REPEATED_BOUND.on(upperBoundElement));
}
@@ -1154,7 +1154,7 @@ public class DescriptorResolver {
}
public static void checkBounds(@NotNull KtTypeReference typeReference, @NotNull KotlinType type, @NotNull BindingTrace trace) {
if (type.isError()) return;
if (KotlinTypeKt.isError(type)) return;
KtTypeElement typeElement = typeReference.getTypeElement();
if (typeElement == null) return;
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.diagnostics.DiagnosticSink.DO_NOTHING
import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.types.TypeUtils
import org.jetbrains.kotlin.types.isError
// Checker for all seven EXPOSED_* errors
// All functions return true if everything is OK, or false in case of any errors
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.resolve.calls.results.isSignatureNotLessSpecific
import org.jetbrains.kotlin.resolve.descriptorUtil.hasHidesMembersAnnotation
import org.jetbrains.kotlin.resolve.descriptorUtil.isExtension
import org.jetbrains.kotlin.resolve.descriptorUtil.varargParameterPosition
import org.jetbrains.kotlin.types.isError
import org.jetbrains.kotlin.util.OperatorNameConventions
class ShadowedExtensionChecker(val typeSpecificityComparator: TypeSpecificityComparator, val trace: DiagnosticSink) {
@@ -47,6 +47,7 @@ import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil;
import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver;
import org.jetbrains.kotlin.types.KotlinType;
import org.jetbrains.kotlin.types.KotlinTypeKt;
import org.jetbrains.kotlin.types.expressions.ExpressionTypingContext;
import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices;
import org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher;
@@ -328,7 +329,7 @@ public class CallResolver {
return checkArgumentTypesAndFail(context); // No type there
}
KotlinType constructedType = typeResolver.resolveType(context.scope, typeReference, context.trace, true);
if (constructedType.isError()) {
if (KotlinTypeKt.isError(constructedType)) {
return checkArgumentTypesAndFail(context);
}
@@ -28,7 +28,6 @@ import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.before
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.BindingContext.*
import org.jetbrains.kotlin.resolve.BindingTrace
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.kotlin.resolve.calls.callUtil.isSafeCall
@@ -43,6 +42,7 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.TransientReceiver
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils
import org.jetbrains.kotlin.types.expressions.PreliminaryDeclarationVisitor
import org.jetbrains.kotlin.types.isError
/**
* This class is intended to create data flow values for different kind of expressions.
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.resolve.calls.smartcasts.Nullability.NOT_NULL
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.TypeUtils
import org.jetbrains.kotlin.types.isError
import org.jetbrains.kotlin.types.isFlexible
import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf
import org.jetbrains.kotlin.utils.newLinkedHashSetWithExpectedSize
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.resolve.calls.CallTransformer
import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext
import org.jetbrains.kotlin.resolve.calls.model.*
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.isError
import org.jetbrains.kotlin.utils.sure
// resolved call
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.psi.KtProperty
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.types.isError
object ConstModifierChecker : SimpleDeclarationChecker {
override fun check(
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.psi.KtElement;
import org.jetbrains.kotlin.resolve.BindingTrace;
import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext;
import org.jetbrains.kotlin.types.KotlinType;
import org.jetbrains.kotlin.types.KotlinTypeKt;
import org.jetbrains.kotlin.types.TypeUtils;
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker;
@@ -277,7 +278,7 @@ public class CompileTimeConstantChecker {
}
private static boolean noExpectedTypeOrError(KotlinType expectedType) {
return TypeUtils.noExpectedType(expectedType) || expectedType.isError();
return TypeUtils.noExpectedType(expectedType) || KotlinTypeKt.isError(expectedType);
}
private boolean reportConstantExpectedTypeMismatch(
@@ -45,6 +45,7 @@ import org.jetbrains.kotlin.types.TypeUtils
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
import org.jetbrains.kotlin.types.expressions.DoubleColonLHS
import org.jetbrains.kotlin.types.expressions.OperatorConventions
import org.jetbrains.kotlin.types.isError
import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf
import org.jetbrains.kotlin.util.OperatorNameConventions
import java.math.BigInteger
@@ -733,9 +734,9 @@ private class ConstantExpressionEvaluatorVisitor(
}
override fun visitClassLiteralExpression(expression: KtClassLiteralExpression, expectedType: KotlinType?): CompileTimeConstant<*>? {
val jetType = trace.getType(expression)!!
if (jetType.isError) return null
return KClassValue(jetType).wrap()
val type = trace.getType(expression)!!
if (type.isError) return null
return KClassValue(type).wrap()
}
private fun resolveArguments(valueArguments: List<ValueArgument>, expectedType: KotlinType): List<CompileTimeConstant<*>?> {
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.resolve.lazy.LazyEntity
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
import org.jetbrains.kotlin.resolve.source.toSourceElement
import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.types.isError
abstract class LazyAnnotationsContext(
val annotationResolver: AnnotationResolver,
@@ -52,10 +52,7 @@ import org.jetbrains.kotlin.storage.MemoizedFunctionToNotNull;
import org.jetbrains.kotlin.storage.NotNullLazyValue;
import org.jetbrains.kotlin.storage.NullableLazyValue;
import org.jetbrains.kotlin.storage.StorageManager;
import org.jetbrains.kotlin.types.AbstractClassTypeConstructor;
import org.jetbrains.kotlin.types.KotlinType;
import org.jetbrains.kotlin.types.TypeConstructor;
import org.jetbrains.kotlin.types.TypeUtils;
import org.jetbrains.kotlin.types.*;
import java.util.ArrayList;
import java.util.Collection;
@@ -70,7 +67,7 @@ import static org.jetbrains.kotlin.resolve.ModifiersChecker.*;
public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDescriptorWithResolutionScopes, LazyEntity {
private static final Function1<KotlinType, Boolean> VALID_SUPERTYPE = type -> {
assert !type.isError() : "Error types must be filtered out in DescriptorResolver";
assert !KotlinTypeKt.isError(type) : "Error types must be filtered out in DescriptorResolver";
return TypeUtils.getClassDescriptor(type) != null;
};
@@ -29,10 +29,7 @@ import org.jetbrains.kotlin.storage.NotNullLazyValue
import org.jetbrains.kotlin.storage.NullableLazyValue
import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.storage.getValue
import org.jetbrains.kotlin.types.SimpleType
import org.jetbrains.kotlin.types.TypeSubstitutor
import org.jetbrains.kotlin.types.Variance
import org.jetbrains.kotlin.types.asSimpleType
import org.jetbrains.kotlin.types.*
class LazyTypeAliasDescriptor(
override val storageManager: StorageManager,
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.resolve.lazy.LazyClassContext;
import org.jetbrains.kotlin.resolve.lazy.LazyEntity;
import org.jetbrains.kotlin.resolve.source.KotlinSourceElementKt;
import org.jetbrains.kotlin.types.KotlinType;
import org.jetbrains.kotlin.types.KotlinTypeKt;
import java.util.ArrayList;
import java.util.Collection;
@@ -76,7 +77,7 @@ public class LazyTypeParameterDescriptor extends AbstractLazyTypeParameterDescri
for (KtTypeReference typeReference : getAllUpperBounds()) {
KotlinType resolvedType = resolveBoundType(typeReference);
if (!resolvedType.isError()) {
if (!KotlinTypeKt.isError(resolvedType)) {
upperBounds.add(resolvedType);
}
}
@@ -122,7 +122,7 @@ public class CommonSupertypes {
if (KotlinBuiltIns.isNothingOrNullableNothing(type)) {
iterator.remove();
}
if (type.isError()) {
if (KotlinTypeKt.isError(type)) {
return ErrorUtils.createErrorType("Supertype of error type " + type);
}
nullable |= type.isMarkedNullable();
@@ -54,7 +54,7 @@ public class TypeIntersector {
boolean allNullable = true;
List<KotlinType> nullabilityStripped = new ArrayList<>(types.size());
for (KotlinType type : types) {
if (type.isError()) continue;
if (KotlinTypeKt.isError(type)) continue;
if (KotlinBuiltIns.isNothingOrNullableNothing(type)) {
nothingOrNullableNothing = type;
@@ -144,7 +144,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
@Nullable KotlinType type
) {
// Receivers are normally analyzed at resolve, with an exception of KT-10175
if (type != null && !type.isError() && !isLValueOrUnsafeReceiver(expression)) {
if (type != null && !KotlinTypeKt.isError(type) && !isLValueOrUnsafeReceiver(expression)) {
DataFlowValue dataFlowValue = DataFlowValueFactory.createDataFlowValue(expression, type, context);
Nullability nullability = context.dataFlowInfo.getStableNullability(dataFlowValue);
if (!nullability.canBeNonNull() && nullability.canBeNull()) {
@@ -362,7 +362,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
KotlinType targetType,
ExpressionTypingContext context
) {
if (actualType == null || noExpectedType(targetType) || targetType.isError()) return;
if (actualType == null || noExpectedType(targetType) || KotlinTypeKt.isError(targetType)) return;
if (DynamicTypesKt.isDynamic(targetType)) {
KtTypeReference right = expression.getRight();
@@ -565,7 +565,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
}
boolean validClassifier = classifierCandidate != null && !ErrorUtils.isError(classifierCandidate);
boolean validType = supertype != null && !supertype.isError();
boolean validType = supertype != null && !KotlinTypeKt.isError(supertype);
if (result == null && (validClassifier || validType)) {
context.trace.report(NOT_A_SUPERTYPE.on(superTypeQualifier));
}
@@ -963,7 +963,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
) {
if (ktType == null) return false;
if (ktType.isError() && !ErrorUtils.isUninferredParameter(ktType)) return false;
if (KotlinTypeKt.isError(ktType) && !ErrorUtils.isUninferredParameter(ktType)) return false;
if (!TypeUtils.isNullableType(ktType)) return true;
@@ -1235,7 +1235,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
KotlinTypeInfo typeInfo = getTypeInfoForBinaryCall(OperatorNameConventions.COMPARE_TO, context, expression);
KotlinType compareToReturnType = typeInfo.getType();
KotlinType type = null;
if (compareToReturnType != null && !compareToReturnType.isError()) {
if (compareToReturnType != null && !KotlinTypeKt.isError(compareToReturnType)) {
if (KotlinTypeChecker.DEFAULT.equalTypes(components.builtIns.getIntType(), compareToReturnType)) {
type = components.builtIns.getBooleanType();
}
@@ -37,6 +37,7 @@ import org.jetbrains.kotlin.resolve.calls.smartcasts.*;
import org.jetbrains.kotlin.resolve.constants.*;
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator;
import org.jetbrains.kotlin.types.KotlinType;
import org.jetbrains.kotlin.types.KotlinTypeKt;
import org.jetbrains.kotlin.types.TypeConstructor;
import org.jetbrains.kotlin.types.TypeUtils;
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker;
@@ -326,7 +327,8 @@ public class DataFlowAnalyzer {
@Nullable
public KotlinType checkStatementType(@NotNull KtExpression expression, @NotNull ResolutionContext context) {
if (!noExpectedType(context.expectedType) && !KotlinBuiltIns.isUnit(context.expectedType) && !context.expectedType.isError()) {
if (!noExpectedType(context.expectedType) && !KotlinBuiltIns.isUnit(context.expectedType) &&
!KotlinTypeKt.isError(context.expectedType)) {
context.trace.report(EXPECTED_TYPE_MISMATCH.on(expression, context.expectedType));
return null;
}
@@ -43,6 +43,7 @@ import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil;
import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope;
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver;
import org.jetbrains.kotlin.types.KotlinType;
import org.jetbrains.kotlin.types.KotlinTypeKt;
import org.jetbrains.kotlin.types.TypeUtils;
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker;
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.TypeInfoFactoryKt;
@@ -89,7 +90,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
@NotNull ExpressionTypingContext context
) {
if (assignmentType != null && !KotlinBuiltIns.isUnit(assignmentType) && !noExpectedType(context.expectedType) &&
!context.expectedType.isError() && TypeUtils.equalTypes(context.expectedType, assignmentType)) {
!KotlinTypeKt.isError(context.expectedType) && TypeUtils.equalTypes(context.expectedType, assignmentType)) {
context.trace.report(Errors.ASSIGNMENT_TYPE_MISMATCH.on(expression, context.expectedType));
return null;
}
@@ -16,15 +16,17 @@
package org.jetbrains.kotlin.types.expressions
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.resolve.calls.smartcasts.Nullability
import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValue
import org.jetbrains.kotlin.resolve.BindingTrace
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.KtBinaryExpression
import org.jetbrains.kotlin.psi.KtExpression
import org.jetbrains.kotlin.psi.KtPsiUtil
import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValue
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory
import org.jetbrains.kotlin.resolve.calls.smartcasts.Nullability
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.isError
object SenselessComparisonChecker {
@JvmStatic fun checkSenselessComparisonWithNull(
@@ -57,4 +59,4 @@ object SenselessComparisonChecker {
context.trace.report(Errors.SENSELESS_COMPARISON.on(expression, expression, expressionIsAlways))
}
}
}
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.incremental.record
import org.jetbrains.kotlin.psi.KtExpression
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.isError
import org.jetbrains.kotlin.types.typeUtil.isUnit
fun LookupTracker.record(expression: KtExpression, type: KotlinType) {