if (a != null) return a // nullability info considered

This commit is contained in:
Andrey Breslav
2011-07-05 16:08:25 +04:00
parent 4121aed773
commit 0c5eca16d5
2 changed files with 15 additions and 5 deletions
@@ -539,7 +539,7 @@ public class JetTypeInferrer {
if (someNamed) {
// TODO : check that all are named
throw new UnsupportedOperationException(); // TODO
trace.getErrorHandler().genericError(call.asElement().getNode(), "Named arguments are not supported"); // TODO
// result = overloadDomain.getFunctionDescriptorForNamedArguments(typeArguments, valueArguments, functionLiteralArgument);
} else {
@@ -1093,7 +1093,10 @@ public class JetTypeInferrer {
if (context.expectedReturnType != null && returnedType != null) {
if (!semanticServices.getTypeChecker().isSubtypeOf(returnedType, context.expectedReturnType)) {
context.trace.getErrorHandler().typeMismatch(returnedExpression == null ? expression : returnedExpression, context.expectedReturnType, returnedType);
JetType enrichedType = enrichOutType(returnedExpression, returnedType);
if (!semanticServices.getTypeChecker().isSubtypeOf(enrichedType, context.expectedReturnType)) {
context.trace.getErrorHandler().typeMismatch(returnedExpression == null ? expression : returnedExpression, context.expectedReturnType, returnedType);
}
}
}
@@ -2015,12 +2018,13 @@ public class JetTypeInferrer {
}
}
private JetType enrichOutType(JetExpression receiverExpression, JetType receiverType) {
VariableDescriptor variableDescriptor = getVariableDescriptorFromSimpleName(receiverExpression);
private JetType enrichOutType(JetExpression expression, JetType initialType) {
if (expression == null) return initialType;
VariableDescriptor variableDescriptor = getVariableDescriptorFromSimpleName(expression);
if (variableDescriptor != null) {
return context.dataFlowInfo.getOutType(variableDescriptor);
}
return receiverType;
return initialType;
}
@Nullable
+6
View File
@@ -272,3 +272,9 @@ fun f8(b : String?, a : String) {
b.get(0)
}
}
fun f9(a : Int?) : Int {
if (a != null)
return a
return 1
}