changed comparison to NO_EXPECTED_TYPE to

'noExpectedType' invocation
This commit is contained in:
Svetlana Isakova
2013-06-24 16:58:00 +04:00
parent 0eed0c6c7f
commit d1a21bfd3e
14 changed files with 36 additions and 19 deletions
@@ -50,6 +50,7 @@ import static org.jetbrains.jet.lang.cfg.PseudocodeVariablesData.VariableUseStat
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
import static org.jetbrains.jet.lang.resolve.BindingContext.CAPTURED_IN_CLOSURE;
import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE;
import static org.jetbrains.jet.lang.types.TypeUtils.noExpectedType;
public class JetFlowInformationProvider {
@@ -152,7 +153,7 @@ public class JetFlowInformationProvider {
@Override
public void visitExpression(JetExpression expression) {
if (blockBody && expectedReturnType != NO_EXPECTED_TYPE && !KotlinBuiltIns.getInstance().isUnit(expectedReturnType) && !rootUnreachableElements.contains(expression)) {
if (blockBody && !noExpectedType(expectedReturnType) && !KotlinBuiltIns.getInstance().isUnit(expectedReturnType) && !rootUnreachableElements.contains(expression)) {
noReturnError[0] = true;
}
}
@@ -62,6 +62,7 @@ import static org.jetbrains.jet.lang.resolve.calls.CallResolverUtil.ResolveArgum
import static org.jetbrains.jet.lang.resolve.calls.CallTransformer.CallForImplicitInvoke;
import static org.jetbrains.jet.lang.resolve.calls.results.ResolutionStatus.*;
import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE;
import static org.jetbrains.jet.lang.types.TypeUtils.noExpectedType;
public class CandidateResolver {
@NotNull
@@ -625,7 +626,7 @@ public class CandidateResolver {
}
else {
JetType resultingType;
if (expectedType == NO_EXPECTED_TYPE || ArgumentTypeResolver.isSubtypeOfForArgumentType(type, expectedType)) {
if (noExpectedType(expectedType) || ArgumentTypeResolver.isSubtypeOfForArgumentType(type, expectedType)) {
resultingType = type;
}
else {
@@ -40,6 +40,7 @@ import static org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystemImp
import static org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystemImpl.ConstraintKind.SUB_TYPE;
import static org.jetbrains.jet.lang.resolve.calls.inference.TypeConstraintsImpl.BoundKind;
import static org.jetbrains.jet.lang.resolve.calls.inference.TypeConstraintsImpl.BoundKind.*;
import static org.jetbrains.jet.lang.types.TypeUtils.noExpectedType;
public class ConstraintSystemImpl implements ConstraintSystem {
@@ -165,7 +166,7 @@ public class ConstraintSystemImpl implements ConstraintSystem {
@NotNull JetType subjectType,
@NotNull ConstraintPosition constraintPosition
) {
if (constrainingType == TypeUtils.NO_EXPECTED_TYPE) return;
if (constrainingType != null && noExpectedType(constrainingType)) return;
if (constraintPosition == ConstraintPosition.EXPECTED_TYPE_POSITION) {
systemWithoutExpectedTypeConstraint = copy();
@@ -44,6 +44,7 @@ import java.util.List;
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
import static org.jetbrains.jet.lang.resolve.BindingContext.*;
import static org.jetbrains.jet.lang.types.TypeUtils.noExpectedType;
public class TracingStrategyImpl implements TracingStrategy {
private final JetReferenceExpression reference;
@@ -228,7 +229,7 @@ public class TracingStrategyImpl implements TracingStrategy {
JetType substitutedReturnType = constraintSystem.getResultingSubstitutor().substitute(declaredReturnType, Variance.INVARIANT);
assert substitutedReturnType != null; //todo
assert data.expectedType != TypeUtils.NO_EXPECTED_TYPE : "Expected type doesn't exist, but there is an expected type mismatch error";
assert !noExpectedType(data.expectedType) : "Expected type doesn't exist, but there is an expected type mismatch error";
trace.report(TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH.on(reference, substitutedReturnType, data.expectedType));
}
else if (constraintSystem.hasTypeConstructorMismatch()) {
@@ -309,7 +309,7 @@ public class CompileTimeConstantResolver {
}
private boolean noExpectedType(JetType expectedType) {
return expectedType == TypeUtils.NO_EXPECTED_TYPE || KotlinBuiltIns.getInstance().isUnit(expectedType) || ErrorUtils.isErrorType(expectedType);
return TypeUtils.noExpectedType(expectedType) || KotlinBuiltIns.getInstance().isUnit(expectedType) || ErrorUtils.isErrorType(expectedType);
}
}
@@ -32,6 +32,8 @@ import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import java.util.*;
import static org.jetbrains.jet.lang.types.TypeUtils.noExpectedType;
public class ErrorUtils {
private static final ModuleDescriptor ERROR_MODULE;
@@ -392,7 +394,7 @@ public class ErrorUtils {
}
public static boolean isErrorType(@NotNull JetType type) {
return type != TypeUtils.NO_EXPECTED_TYPE && !(type instanceof NamespaceType) &&
return !noExpectedType(type) && !(type instanceof NamespaceType) &&
(
(type instanceof DeferredType && (((DeferredType) type).getActualType() == null
|| isErrorType(((DeferredType) type).getActualType()))) ||
@@ -73,6 +73,10 @@ public class TypeUtils {
}
};
public static boolean noExpectedType(@NotNull JetType type) {
return type == NO_EXPECTED_TYPE;
}
@NotNull
public static JetType makeNullable(@NotNull JetType type) {
return makeNullableAsSpecified(type, true);
@@ -67,6 +67,7 @@ import static org.jetbrains.jet.lang.resolve.BindingContext.*;
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.getStaticNestedClassesScope;
import static org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue.NO_RECEIVER;
import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE;
import static org.jetbrains.jet.lang.types.TypeUtils.noExpectedType;
import static org.jetbrains.jet.lang.types.expressions.ExpressionTypingUtils.*;
@SuppressWarnings("SuspiciousMethodCalls")
@@ -191,7 +192,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
JetSimpleNameExpression operationSign = expression.getOperationReference();
IElementType operationType = operationSign.getReferencedNameElementType();
if (operationType == JetTokens.COLON) {
if (targetType != NO_EXPECTED_TYPE && !JetTypeChecker.INSTANCE.isSubtypeOf(actualType, targetType)) {
if (!noExpectedType(targetType) && !JetTypeChecker.INSTANCE.isSubtypeOf(actualType, targetType)) {
context.trace.report(TYPE_MISMATCH.on(expression.getLeft(), targetType, actualType));
return false;
}
@@ -213,7 +214,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
JetType targetType,
ExpressionTypingContext context
) {
if (actualType == null || targetType == NO_EXPECTED_TYPE) return;
if (actualType == null || noExpectedType(targetType)) return;
JetTypeChecker typeChecker = JetTypeChecker.INSTANCE;
if (!typeChecker.isSubtypeOf(targetType, actualType)) {
@@ -819,7 +820,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
assert operationSign.getReferencedNameElementType() == JetTokens.EXCLEXCL;
JetType expectedType;
if (context.expectedType != NO_EXPECTED_TYPE) {
if (!noExpectedType(context.expectedType)) {
expectedType = TypeUtils.makeNullable(context.expectedType);
}
else {
@@ -44,6 +44,7 @@ import java.util.List;
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
import static org.jetbrains.jet.lang.resolve.BindingContext.*;
import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE;
import static org.jetbrains.jet.lang.types.TypeUtils.noExpectedType;
import static org.jetbrains.jet.lang.types.expressions.CoercionStrategy.COERCION_TO_UNIT;
import static org.jetbrains.jet.lang.types.expressions.ExpressionTypingUtils.CANT_INFER_LAMBDA_PARAM_TYPE;
@@ -106,7 +107,7 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor {
}
JetType expectedType = context.expectedType;
boolean functionTypeExpected = expectedType != NO_EXPECTED_TYPE && KotlinBuiltIns.getInstance().isFunctionOrExtensionFunctionType(
boolean functionTypeExpected = !noExpectedType(expectedType) && KotlinBuiltIns.getInstance().isFunctionOrExtensionFunctionType(
expectedType);
AnonymousFunctionDescriptor functionDescriptor = createFunctionDescriptor(expression, context, functionTypeExpected);
@@ -117,7 +118,7 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor {
List<JetType> valueParametersTypes = DescriptorUtils.getValueParametersTypes(functionDescriptor.getValueParameters());
JetType resultType = KotlinBuiltIns.getInstance().getFunctionType(
Collections.<AnnotationDescriptor>emptyList(), receiver, valueParametersTypes, safeReturnType);
if (expectedType != NO_EXPECTED_TYPE && KotlinBuiltIns.getInstance().isFunctionOrExtensionFunctionType(expectedType)) {
if (!noExpectedType(expectedType) && KotlinBuiltIns.getInstance().isFunctionOrExtensionFunctionType(expectedType)) {
// all checks were done before
return JetTypeInfo.create(resultType, context.dataFlowInfo);
}
@@ -54,6 +54,7 @@ import java.util.List;
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
import static org.jetbrains.jet.lang.resolve.BindingContext.*;
import static org.jetbrains.jet.lang.types.TypeUtils.noExpectedType;
import static org.jetbrains.jet.lang.types.expressions.ExpressionTypingUtils.*;
public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
@@ -542,7 +543,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
facade.getTypeInfo(returnedExpression, context.replaceExpectedType(expectedType).replaceScope(context.scope));
}
else {
if (expectedType != TypeUtils.NO_EXPECTED_TYPE && expectedType != null && !KotlinBuiltIns.getInstance().isUnit(expectedType)) {
if (expectedType != null && !noExpectedType(expectedType) && !KotlinBuiltIns.getInstance().isUnit(expectedType)) {
context.trace.report(RETURN_TYPE_MISMATCH.on(expression, expectedType));
}
}
@@ -36,6 +36,7 @@ import org.jetbrains.jet.lexer.JetTokens;
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
import static org.jetbrains.jet.lang.resolve.BindingContext.AUTOCAST;
import static org.jetbrains.jet.lang.types.TypeUtils.noExpectedType;
public class DataFlowUtils {
private DataFlowUtils() {
@@ -137,11 +138,11 @@ public class DataFlowUtils {
@Nullable
public static JetType checkType(@Nullable JetType expressionType, @NotNull JetExpression expression, @NotNull ResolutionContext context) {
if (context.expectedType != TypeUtils.NO_EXPECTED_TYPE) {
if (!noExpectedType(context.expectedType)) {
context.trace.record(BindingContext.EXPECTED_EXPRESSION_TYPE, expression, context.expectedType);
}
if (expressionType == null || context.expectedType == null || context.expectedType == TypeUtils.NO_EXPECTED_TYPE ||
if (expressionType == null || noExpectedType(context.expectedType) ||
JetTypeChecker.INSTANCE.isSubtypeOf(expressionType, context.expectedType)) {
return expressionType;
}
@@ -169,7 +170,7 @@ public class DataFlowUtils {
@Nullable
public static JetType checkStatementType(@NotNull JetExpression expression, @NotNull ResolutionContext context) {
if (context.expectedType != TypeUtils.NO_EXPECTED_TYPE && !KotlinBuiltIns.getInstance().isUnit(context.expectedType) && !ErrorUtils.isErrorType(context.expectedType)) {
if (!noExpectedType(context.expectedType) && !KotlinBuiltIns.getInstance().isUnit(context.expectedType) && !ErrorUtils.isErrorType(context.expectedType)) {
context.trace.report(EXPECTED_TYPE_MISMATCH.on(expression, context.expectedType));
return null;
}
@@ -183,7 +184,7 @@ public class DataFlowUtils {
@Nullable
public static JetType checkImplicitCast(@Nullable JetType expressionType, @NotNull JetExpression expression, @NotNull ExpressionTypingContext context, boolean isStatement) {
if (expressionType != null && context.expectedType == TypeUtils.NO_EXPECTED_TYPE && !isStatement &&
if (expressionType != null && noExpectedType(context.expectedType) && !isStatement &&
(KotlinBuiltIns.getInstance().isUnit(expressionType) || KotlinBuiltIns.getInstance().isAny(expressionType))) {
context.trace.report(IMPLICIT_CAST_TO_UNIT_OR_ANY.on(expression, expressionType));
@@ -47,6 +47,7 @@ import java.util.List;
import static org.jetbrains.jet.lang.resolve.BindingContext.STATEMENT;
import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE;
import static org.jetbrains.jet.lang.types.TypeUtils.noExpectedType;
import static org.jetbrains.jet.lang.types.expressions.ExpressionTypingUtils.makeTraceInterceptingTypeMismatch;
public class ExpressionTypingServices {
@@ -263,7 +264,7 @@ public class ExpressionTypingServices {
JetExpression statementExpression = (JetExpression) statement;
//TODO constructor assert context.expectedType != FORBIDDEN : ""
if (!iterator.hasNext()) {
if (context.expectedType != NO_EXPECTED_TYPE) {
if (!noExpectedType(context.expectedType)) {
if (coercionStrategyForLastExpression == CoercionStrategy.COERCION_TO_UNIT && KotlinBuiltIns.getInstance().isUnit(context.expectedType)) {
// This implements coercion to Unit
TemporaryBindingTrace temporaryTraceExpectingUnit = TemporaryBindingTrace.create(trace, "trace to resolve coercion to unit with expected type");
@@ -57,6 +57,7 @@ import java.util.*;
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
import static org.jetbrains.jet.lang.resolve.BindingContext.*;
import static org.jetbrains.jet.lang.types.TypeUtils.noExpectedType;
public class ExpressionTypingUtils {
@@ -406,7 +407,7 @@ public class ExpressionTypingUtils {
if (results.isSuccess()) {
context.trace.record(COMPONENT_RESOLVED_CALL, entry, results.getResultingCall());
componentType = results.getResultingDescriptor().getReturnType();
if (componentType != null && expectedType != TypeUtils.NO_EXPECTED_TYPE
if (componentType != null && !noExpectedType(expectedType)
&& !JetTypeChecker.INSTANCE.isSubtypeOf(componentType, expectedType)) {
context.trace.report(
@@ -47,6 +47,7 @@ import java.util.Collection;
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
import static org.jetbrains.jet.lang.resolve.BindingContext.AMBIGUOUS_REFERENCE_TARGET;
import static org.jetbrains.jet.lang.resolve.BindingContext.VARIABLE_REASSIGNMENT;
import static org.jetbrains.jet.lang.types.TypeUtils.noExpectedType;
@SuppressWarnings("SuspiciousMethodCalls")
public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisitor {
@@ -74,7 +75,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
@NotNull JetBinaryExpression expression,
@NotNull ExpressionTypingContext context
) {
if (assignmentType != null && !KotlinBuiltIns.getInstance().isUnit(assignmentType) && context.expectedType != TypeUtils.NO_EXPECTED_TYPE &&
if (assignmentType != null && !KotlinBuiltIns.getInstance().isUnit(assignmentType) && !noExpectedType(context.expectedType) &&
TypeUtils.equalTypes(context.expectedType, assignmentType)) {
context.trace.report(Errors.ASSIGNMENT_TYPE_MISMATCH.on(expression, context.expectedType));
return null;