removed UNKNOWN_EXPECTED_TYPE

it's NO_EXPECTED_TYPE + ContextDependency.DEPENDENT
This commit is contained in:
Svetlana Isakova
2013-08-30 18:14:24 +04:00
parent 92611e1460
commit 8b27c72736
4 changed files with 9 additions and 12 deletions
@@ -174,7 +174,7 @@ public class ArgumentTypeResolver {
if (recordedTypeInfo != null) {
return recordedTypeInfo;
}
ResolutionContext newContext = context.replaceExpectedType(TypeUtils.UNKNOWN_EXPECTED_TYPE).replaceContextDependency(
ResolutionContext newContext = context.replaceExpectedType(TypeUtils.NO_EXPECTED_TYPE).replaceContextDependency(
ContextDependency.DEPENDENT);
return expressionTypingServices.getTypeInfo(expression, newContext);
@@ -83,12 +83,10 @@ public class TypeUtils {
public static final JetType NO_EXPECTED_TYPE = new SpecialType("NO_EXPECTED_TYPE");
public static final JetType UNKNOWN_EXPECTED_TYPE = new SpecialType("UNKNOWN_EXPECTED_TYPE");
public static final JetType UNIT_EXPECTED_TYPE = new SpecialType("UNIT_EXPECTED_TYPE");
public static boolean noExpectedType(@NotNull JetType type) {
return type == NO_EXPECTED_TYPE || type == UNKNOWN_EXPECTED_TYPE || type == UNIT_EXPECTED_TYPE;
return type == NO_EXPECTED_TYPE || type == UNIT_EXPECTED_TYPE;
}
@NotNull
@@ -69,7 +69,6 @@ import static org.jetbrains.jet.lang.resolve.calls.context.ContextDependency.DEP
import static org.jetbrains.jet.lang.resolve.calls.context.ContextDependency.INDEPENDENT;
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.UNKNOWN_EXPECTED_TYPE;
import static org.jetbrains.jet.lang.types.TypeUtils.noExpectedType;
import static org.jetbrains.jet.lang.types.expressions.ControlStructureTypingUtils.*;
import static org.jetbrains.jet.lang.types.expressions.ExpressionTypingUtils.*;
@@ -124,7 +123,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance();
CompileTimeConstantResolver compileTimeConstantResolver = context.getCompileTimeConstantResolver();
if (context.expectedType == UNKNOWN_EXPECTED_TYPE) {
if (noExpectedType(context.expectedType) && context.contextDependency == DEPENDENT) {
if (elementType == JetNodeTypes.INTEGER_CONSTANT) {
Long longValue = CompileTimeConstantResolver.parseLongValue(text);
if (longValue != null) {
@@ -141,8 +140,8 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
CompileTimeConstant<?> value = compileTimeConstantResolver.getCompileTimeConstant(expression, context.expectedType);
if (value instanceof ErrorValue) {
// 'checkType' for 'UNKNOWN_EXPECTED_TYPE' will take place in 'completeInferenceForArgument'
if (context.expectedType != UNKNOWN_EXPECTED_TYPE) {
// 'checkType' for 'ContextDependency.DEPENDENT' will take place in 'completeInferenceForArgument'
if (context.contextDependency == INDEPENDENT) {
context.trace.report(ERROR_COMPILE_TIME_VALUE.on(expression, ((ErrorValue) value).getMessage()));
}
return JetTypeInfo.create(getDefaultType(elementType), context.dataFlowInfo);
@@ -38,6 +38,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.resolve.calls.context.ContextDependency.INDEPENDENT;
import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE;
import static org.jetbrains.jet.lang.types.TypeUtils.noExpectedType;
@@ -196,10 +197,9 @@ public class DataFlowUtils {
@Nullable
public static JetType checkImplicitCast(@Nullable JetType expressionType, @NotNull JetExpression expression, @NotNull ExpressionTypingContext context, boolean isStatement) {
if (expressionType != null && context.expectedType == NO_EXPECTED_TYPE && !isStatement &&
(KotlinBuiltIns.getInstance().isUnit(expressionType) || KotlinBuiltIns.getInstance().isAny(expressionType))) {
if (expressionType != null && context.expectedType == NO_EXPECTED_TYPE && context.contextDependency == INDEPENDENT && !isStatement
&& (KotlinBuiltIns.getInstance().isUnit(expressionType) || KotlinBuiltIns.getInstance().isAny(expressionType))) {
context.trace.report(IMPLICIT_CAST_TO_UNIT_OR_ANY.on(expression, expressionType));
}
return expressionType;
}
@@ -207,7 +207,7 @@ public class DataFlowUtils {
@NotNull
public static JetTypeInfo illegalStatementType(@NotNull JetExpression expression, @NotNull ExpressionTypingContext context, @NotNull ExpressionTypingInternals facade) {
facade.checkStatementType(
expression, context.replaceExpectedType(TypeUtils.NO_EXPECTED_TYPE).replaceContextDependency(ContextDependency.INDEPENDENT));
expression, context.replaceExpectedType(TypeUtils.NO_EXPECTED_TYPE).replaceContextDependency(INDEPENDENT));
context.trace.report(EXPRESSION_EXPECTED.on(expression, expression));
return JetTypeInfo.create(null, context.dataFlowInfo);
}