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) { if (recordedTypeInfo != null) {
return recordedTypeInfo; return recordedTypeInfo;
} }
ResolutionContext newContext = context.replaceExpectedType(TypeUtils.UNKNOWN_EXPECTED_TYPE).replaceContextDependency( ResolutionContext newContext = context.replaceExpectedType(TypeUtils.NO_EXPECTED_TYPE).replaceContextDependency(
ContextDependency.DEPENDENT); ContextDependency.DEPENDENT);
return expressionTypingServices.getTypeInfo(expression, newContext); 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 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 final JetType UNIT_EXPECTED_TYPE = new SpecialType("UNIT_EXPECTED_TYPE");
public static boolean noExpectedType(@NotNull JetType 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 @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.calls.context.ContextDependency.INDEPENDENT;
import static org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue.NO_RECEIVER; 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.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.TypeUtils.noExpectedType;
import static org.jetbrains.jet.lang.types.expressions.ControlStructureTypingUtils.*; import static org.jetbrains.jet.lang.types.expressions.ControlStructureTypingUtils.*;
import static org.jetbrains.jet.lang.types.expressions.ExpressionTypingUtils.*; import static org.jetbrains.jet.lang.types.expressions.ExpressionTypingUtils.*;
@@ -124,7 +123,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance(); KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance();
CompileTimeConstantResolver compileTimeConstantResolver = context.getCompileTimeConstantResolver(); CompileTimeConstantResolver compileTimeConstantResolver = context.getCompileTimeConstantResolver();
if (context.expectedType == UNKNOWN_EXPECTED_TYPE) { if (noExpectedType(context.expectedType) && context.contextDependency == DEPENDENT) {
if (elementType == JetNodeTypes.INTEGER_CONSTANT) { if (elementType == JetNodeTypes.INTEGER_CONSTANT) {
Long longValue = CompileTimeConstantResolver.parseLongValue(text); Long longValue = CompileTimeConstantResolver.parseLongValue(text);
if (longValue != null) { if (longValue != null) {
@@ -141,8 +140,8 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
CompileTimeConstant<?> value = compileTimeConstantResolver.getCompileTimeConstant(expression, context.expectedType); CompileTimeConstant<?> value = compileTimeConstantResolver.getCompileTimeConstant(expression, context.expectedType);
if (value instanceof ErrorValue) { if (value instanceof ErrorValue) {
// 'checkType' for 'UNKNOWN_EXPECTED_TYPE' will take place in 'completeInferenceForArgument' // 'checkType' for 'ContextDependency.DEPENDENT' will take place in 'completeInferenceForArgument'
if (context.expectedType != UNKNOWN_EXPECTED_TYPE) { if (context.contextDependency == INDEPENDENT) {
context.trace.report(ERROR_COMPILE_TIME_VALUE.on(expression, ((ErrorValue) value).getMessage())); context.trace.report(ERROR_COMPILE_TIME_VALUE.on(expression, ((ErrorValue) value).getMessage()));
} }
return JetTypeInfo.create(getDefaultType(elementType), context.dataFlowInfo); 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.diagnostics.Errors.*;
import static org.jetbrains.jet.lang.resolve.BindingContext.AUTOCAST; 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.NO_EXPECTED_TYPE;
import static org.jetbrains.jet.lang.types.TypeUtils.noExpectedType; import static org.jetbrains.jet.lang.types.TypeUtils.noExpectedType;
@@ -196,10 +197,9 @@ public class DataFlowUtils {
@Nullable @Nullable
public static JetType checkImplicitCast(@Nullable JetType expressionType, @NotNull JetExpression expression, @NotNull ExpressionTypingContext context, boolean isStatement) { public static JetType checkImplicitCast(@Nullable JetType expressionType, @NotNull JetExpression expression, @NotNull ExpressionTypingContext context, boolean isStatement) {
if (expressionType != null && context.expectedType == NO_EXPECTED_TYPE && !isStatement && if (expressionType != null && context.expectedType == NO_EXPECTED_TYPE && context.contextDependency == INDEPENDENT && !isStatement
(KotlinBuiltIns.getInstance().isUnit(expressionType) || KotlinBuiltIns.getInstance().isAny(expressionType))) { && (KotlinBuiltIns.getInstance().isUnit(expressionType) || KotlinBuiltIns.getInstance().isAny(expressionType))) {
context.trace.report(IMPLICIT_CAST_TO_UNIT_OR_ANY.on(expression, expressionType)); context.trace.report(IMPLICIT_CAST_TO_UNIT_OR_ANY.on(expression, expressionType));
} }
return expressionType; return expressionType;
} }
@@ -207,7 +207,7 @@ public class DataFlowUtils {
@NotNull @NotNull
public static JetTypeInfo illegalStatementType(@NotNull JetExpression expression, @NotNull ExpressionTypingContext context, @NotNull ExpressionTypingInternals facade) { public static JetTypeInfo illegalStatementType(@NotNull JetExpression expression, @NotNull ExpressionTypingContext context, @NotNull ExpressionTypingInternals facade) {
facade.checkStatementType( 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)); context.trace.report(EXPRESSION_EXPECTED.on(expression, expression));
return JetTypeInfo.create(null, context.dataFlowInfo); return JetTypeInfo.create(null, context.dataFlowInfo);
} }