USELESS_ELVIS_RIGHT_IS_NULL : build fix (add to different files in DiagnosticsTestGenerated), do not report if USELESS_ELVIS already exists

(cherry picked from commit c71b656)
This commit is contained in:
Mikhail Glukhikh
2016-08-23 16:25:04 +03:00
committed by Mikhail Glukhikh
parent df86840515
commit d08d8af407
4 changed files with 7 additions and 7 deletions
@@ -1190,6 +1190,9 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
if (leftType != null && isKnownToBeNotNull(left, leftType, context)) {
context.trace.report(USELESS_ELVIS.on(expression, leftType));
}
else if (KtPsiUtil.isNullConstant(right)) {
context.trace.report(USELESS_ELVIS_RIGHT_IS_NULL.on(expression));
}
KotlinTypeInfo rightTypeInfo = BindingContextUtils.getRecordedTypeInfo(right, context.trace.getBindingContext());
if (rightTypeInfo == null && ArgumentTypeResolver.isFunctionLiteralArgument(right, context)) {
// the type is computed later in call completer according to the '?:' semantics as a function
@@ -1198,9 +1201,6 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
assert rightTypeInfo != null : "Right expression was not processed: " + expression;
boolean loopBreakContinuePossible = leftTypeInfo.getJumpOutPossible() || rightTypeInfo.getJumpOutPossible();
KotlinType rightType = rightTypeInfo.getType();
if (rightType != null && KtPsiUtil.isNullConstant(right)) {
context.trace.report(USELESS_ELVIS_RIGHT_IS_NULL.on(expression));
}
// Only left argument DFA is taken into account here: we cannot be sure that right argument is joined
// (we merge it with right DFA if right argument contains no jump outside)
@@ -27,9 +27,9 @@ val b = null ?: ( l() ?: false)
val bb = null ?: ( l() ?: null!!)
val bbb = null ?: ( l() ?: null)
val bbb = null ?: ( l() <!USELESS_ELVIS_RIGHT_IS_NULL!>?: null<!>)
val bbbb = ( l() ?: null) ?: ( l() ?: null)
val bbbb = ( l() <!USELESS_ELVIS_RIGHT_IS_NULL!>?: null<!>) ?: ( l() <!USELESS_ELVIS_RIGHT_IS_NULL!>?: null<!>)
fun f(x : Long?): Long {
var a = x ?: (<!TYPE_MISMATCH!>fun() {}<!> <!USELESS_ELVIS!><!USELESS_ELVIS_ON_LAMBDA_EXPRESSION!>?:<!> <!TYPE_MISMATCH!>fun() {}<!><!>)
@@ -5,5 +5,5 @@ operator fun String.invoke(i: Int) {}
fun foo(s: String?) {
<!UNSAFE_CALL!>s<!>(1)
<!UNSAFE_CALL!>(s ?: null)<!>(1)
<!UNSAFE_CALL!>(s <!USELESS_ELVIS_RIGHT_IS_NULL!>?: null<!>)<!>(1)
}
@@ -30,7 +30,7 @@ fun baz(s: String?, r: String?): String {
}
fun withNull(s: String?): String {
val t = s ?: null
val t = s <!USELESS_ELVIS_RIGHT_IS_NULL!>?: null<!>
// Error: nullable
return <!TYPE_MISMATCH!>t<!>
}