KT-175: infer nullability in then block from if condition
if (x != null) {
// x is non-null here
}
This commit is contained in:
@@ -652,7 +652,7 @@ public class CallResolver {
|
|||||||
List<JetExpression> argumentExpressions = resolvedArgument.getArgumentExpressions();
|
List<JetExpression> argumentExpressions = resolvedArgument.getArgumentExpressions();
|
||||||
for (JetExpression argumentExpression : argumentExpressions) {
|
for (JetExpression argumentExpression : argumentExpressions) {
|
||||||
ExpressionTypingServices temporaryServices = new ExpressionTypingServices(semanticServices, candidateCall.getTrace());
|
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) {
|
if (type == null) {
|
||||||
candidateCall.argumentHasNoType();
|
candidateCall.argumentHasNoType();
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-1
@@ -53,10 +53,15 @@ public class ExpressionTypingServices {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public JetType getType(@NotNull final JetScope scope, @NotNull JetExpression expression, @NotNull JetType expectedType) {
|
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(
|
ExpressionTypingContext context = ExpressionTypingContext.newContext(
|
||||||
semanticServices,
|
semanticServices,
|
||||||
new HashMap<JetPattern, DataFlowInfo>(), new HashMap<JetPattern, List<VariableDescriptor>>(), new LabelResolver(),
|
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);
|
return expressionTypingFacade.getType(expression, context);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
fun ff(a: String) = 1
|
||||||
|
|
||||||
|
fun gg() {
|
||||||
|
val a: String? = ""
|
||||||
|
|
||||||
|
if (a != null) {
|
||||||
|
ff(a)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user