little fixes

This commit is contained in:
svtk
2011-08-31 14:49:42 +04:00
parent 6bbcc281ce
commit bda26a18ff
2 changed files with 23 additions and 22 deletions
@@ -832,32 +832,31 @@ public class JetTypeInferrer {
return expressionType;
}
VariableDescriptor variableDescriptor = getVariableDescriptorFromSimpleName(expression, context);
if (variableDescriptor == null) return expressionType;
JetType enrichedType = null;
List<JetType> possibleTypes = Lists.newArrayList(context.dataFlowInfo.getPossibleTypes(variableDescriptor));
Collections.reverse(possibleTypes);
for (JetType possibleType: possibleTypes) {
if (semanticServices.getTypeChecker().isSubtypeOf(possibleType, context.expectedType)) {
enrichedType = possibleType;
break;
boolean appropriateTypeFound = false;
if (variableDescriptor != null) {
List<JetType> possibleTypes = Lists.newArrayList(context.dataFlowInfo.getPossibleTypes(variableDescriptor));
Collections.reverse(possibleTypes);
for (JetType possibleType : possibleTypes) {
if (semanticServices.getTypeChecker().isSubtypeOf(possibleType, context.expectedType)) {
appropriateTypeFound = true;
break;
}
}
if (!appropriateTypeFound) {
JetType notnullType = context.dataFlowInfo.getOutType(variableDescriptor);
if (notnullType != null && semanticServices.getTypeChecker().isSubtypeOf(notnullType, context.expectedType)) {
appropriateTypeFound = true;
}
}
}
if (enrichedType == null) {
enrichedType = context.dataFlowInfo.getOutType(variableDescriptor);
}
if (enrichedType == null) {
enrichedType = expressionType;
}
if (!semanticServices.getTypeChecker().isSubtypeOf(enrichedType, context.expectedType)) {
if (!appropriateTypeFound) {
context.trace.getErrorHandler().typeMismatch(expression, context.expectedType, expressionType);
} else {
checkAutoCast(expression, context.expectedType, variableDescriptor, context.trace);
return expressionType;
}
return enrichedType;
checkAutoCast(expression, context.expectedType, variableDescriptor, context.trace);
return context.expectedType;
}
private void checkAutoCast(JetExpression expression, JetType type, VariableDescriptor variableDescriptor, BindingTrace trace) {
if (variableDescriptor.isVar()) {
trace.getErrorHandler().genericError(expression.getNode(), "Automatic cast to " + type + " is impossible, because variable " + variableDescriptor.getName() + " is mutable");
@@ -1470,7 +1469,7 @@ public class JetTypeInferrer {
@Override
public JetType visitBlockExpression(JetBlockExpression expression, TypeInferenceContext context) {
return context.services.checkType(getBlockReturnedType(context.scope, expression, context), expression, context);
return getBlockReturnedType(context.scope, expression, context);
}
@Override
@@ -231,6 +231,8 @@ fun mergeAutocasts(a: Any?) {
if (a is String && a is Any) {
val i: Int = <info descr="Automatically cast to String">a</info>.compareTo("")
}
if (a is String && <info descr="Automatically cast to String">a</info>.compareTo("") == 0) {}
if (a is String || a.<error>compareTo</error>("") == 0) {}
}
//mutability