KT-175: infer nullability in then block from if condition

if (x != null) {
    // x is non-null here
}
This commit is contained in:
Stepan Koltsov
2011-11-03 21:11:03 +04:00
parent 84b216b88c
commit 019ccae7f6
3 changed files with 18 additions and 2 deletions
@@ -652,7 +652,7 @@ public class CallResolver {
List<JetExpression> argumentExpressions = resolvedArgument.getArgumentExpressions();
for (JetExpression argumentExpression : argumentExpressions) {
ExpressionTypingServices temporaryServices = new ExpressionTypingServices(semanticServices, candidateCall.getTrace());
JetType type = temporaryServices.getType(scope, argumentExpression, parameterType);
JetType type = temporaryServices.getType(scope, argumentExpression, parameterType, dataFlowInfo);
if (type == null) {
candidateCall.argumentHasNoType();
}
@@ -53,10 +53,15 @@ public class ExpressionTypingServices {
@Nullable
public JetType getType(@NotNull final JetScope scope, @NotNull JetExpression expression, @NotNull JetType expectedType) {
return getType(scope, expression, expectedType, DataFlowInfo.EMPTY);
}
@Nullable
public JetType getType(@NotNull final JetScope scope, @NotNull JetExpression expression, @NotNull JetType expectedType, DataFlowInfo dataFlowInfo) {
ExpressionTypingContext context = ExpressionTypingContext.newContext(
semanticServices,
new HashMap<JetPattern, DataFlowInfo>(), new HashMap<JetPattern, List<VariableDescriptor>>(), new LabelResolver(),
trace, scope, DataFlowInfo.EMPTY, expectedType, FORBIDDEN, false
trace, scope, dataFlowInfo, expectedType, FORBIDDEN, false
);
return expressionTypingFacade.getType(expression, context);
}
@@ -0,0 +1,11 @@
fun ff(a: String) = 1
fun gg() {
val a: String? = ""
if (a != null) {
ff(a)
}
}