fixed result type for elvis operator

return type for special call for elvis operator might be nullable
but result is not nullable if the right type is not nullable
This commit is contained in:
Svetlana Isakova
2013-08-08 20:28:23 +04:00
parent 656597e0e2
commit c0f7a82b15
@@ -1032,8 +1032,15 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
if (leftType != null && isKnownToBeNotNull(left, leftType, context)) {
context.trace.report(USELESS_ELVIS.on(left, leftType));
}
return JetTypeInfo.create(resolvedCall.getResultingDescriptor().getReturnType(),
resolvedCall.getDataFlowInfoForArguments().getResultInfo());
JetTypeInfo rightTypeInfo = BindingContextUtils.getRecordedTypeInfo(right, context.trace.getBindingContext());
assert rightTypeInfo != null : "Right expression was not processed: " + expression;
JetType rightType = rightTypeInfo.getType();
DataFlowInfo dataFlowInfo = resolvedCall.getDataFlowInfoForArguments().getResultInfo();
JetType type = resolvedCall.getResultingDescriptor().getReturnType();
if (type == null || rightType == null) return JetTypeInfo.create(null, dataFlowInfo);
return JetTypeInfo.create(TypeUtils.makeNullableAsSpecified(type, rightType.isNullable()), dataFlowInfo);
}
@NotNull