little fixes
This commit is contained in:
@@ -832,32 +832,31 @@ public class JetTypeInferrer {
|
|||||||
return expressionType;
|
return expressionType;
|
||||||
}
|
}
|
||||||
VariableDescriptor variableDescriptor = getVariableDescriptorFromSimpleName(expression, context);
|
VariableDescriptor variableDescriptor = getVariableDescriptorFromSimpleName(expression, context);
|
||||||
if (variableDescriptor == null) return expressionType;
|
boolean appropriateTypeFound = false;
|
||||||
|
if (variableDescriptor != null) {
|
||||||
JetType enrichedType = null;
|
List<JetType> possibleTypes = Lists.newArrayList(context.dataFlowInfo.getPossibleTypes(variableDescriptor));
|
||||||
List<JetType> possibleTypes = Lists.newArrayList(context.dataFlowInfo.getPossibleTypes(variableDescriptor));
|
Collections.reverse(possibleTypes);
|
||||||
Collections.reverse(possibleTypes);
|
for (JetType possibleType : possibleTypes) {
|
||||||
for (JetType possibleType: possibleTypes) {
|
if (semanticServices.getTypeChecker().isSubtypeOf(possibleType, context.expectedType)) {
|
||||||
if (semanticServices.getTypeChecker().isSubtypeOf(possibleType, context.expectedType)) {
|
appropriateTypeFound = true;
|
||||||
enrichedType = possibleType;
|
break;
|
||||||
break;
|
}
|
||||||
|
}
|
||||||
|
if (!appropriateTypeFound) {
|
||||||
|
JetType notnullType = context.dataFlowInfo.getOutType(variableDescriptor);
|
||||||
|
if (notnullType != null && semanticServices.getTypeChecker().isSubtypeOf(notnullType, context.expectedType)) {
|
||||||
|
appropriateTypeFound = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (enrichedType == null) {
|
if (!appropriateTypeFound) {
|
||||||
enrichedType = context.dataFlowInfo.getOutType(variableDescriptor);
|
|
||||||
}
|
|
||||||
if (enrichedType == null) {
|
|
||||||
enrichedType = expressionType;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!semanticServices.getTypeChecker().isSubtypeOf(enrichedType, context.expectedType)) {
|
|
||||||
context.trace.getErrorHandler().typeMismatch(expression, context.expectedType, expressionType);
|
context.trace.getErrorHandler().typeMismatch(expression, context.expectedType, expressionType);
|
||||||
} else {
|
return expressionType;
|
||||||
checkAutoCast(expression, context.expectedType, variableDescriptor, context.trace);
|
|
||||||
}
|
}
|
||||||
return enrichedType;
|
checkAutoCast(expression, context.expectedType, variableDescriptor, context.trace);
|
||||||
|
return context.expectedType;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkAutoCast(JetExpression expression, JetType type, VariableDescriptor variableDescriptor, BindingTrace trace) {
|
private void checkAutoCast(JetExpression expression, JetType type, VariableDescriptor variableDescriptor, BindingTrace trace) {
|
||||||
if (variableDescriptor.isVar()) {
|
if (variableDescriptor.isVar()) {
|
||||||
trace.getErrorHandler().genericError(expression.getNode(), "Automatic cast to " + type + " is impossible, because variable " + variableDescriptor.getName() + " is mutable");
|
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
|
@Override
|
||||||
public JetType visitBlockExpression(JetBlockExpression expression, TypeInferenceContext context) {
|
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
|
@Override
|
||||||
|
|||||||
@@ -231,6 +231,8 @@ fun mergeAutocasts(a: Any?) {
|
|||||||
if (a is String && a is Any) {
|
if (a is String && a is Any) {
|
||||||
val i: Int = <info descr="Automatically cast to String">a</info>.compareTo("")
|
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
|
//mutability
|
||||||
|
|||||||
Reference in New Issue
Block a user