diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index a1de06e566a..efa185d4f51 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -657,6 +657,7 @@ public interface Errors { DiagnosticFactory1 IMPLICIT_CAST_TO_UNIT_OR_ANY = DiagnosticFactory1.create(WARNING); DiagnosticFactory3 SMARTCAST_IMPOSSIBLE = DiagnosticFactory3.create(ERROR); + DiagnosticFactory0 ALWAYS_NULL = DiagnosticFactory0.create(WARNING); DiagnosticFactory0 USELESS_NULLABLE_CHECK = DiagnosticFactory0.create(WARNING, NULLABLE_TYPE); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java index 0ee0704478d..2a56df2b818 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -481,6 +481,7 @@ public class DefaultErrorMessages { }, DECLARATION_NAME); MAP.put(SMARTCAST_IMPOSSIBLE, "Smart cast to ''{0}'' is impossible, because ''{1}'' is a {2}", RENDER_TYPE, STRING, STRING); + MAP.put(ALWAYS_NULL, "The result of the expression is always null"); MAP.put(MISSING_CONSTRUCTOR_KEYWORD, "Use 'constructor' keyword after modifiers of primary constructor"); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java index a72bbe9d2ad..3c821532588 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java @@ -97,12 +97,28 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { super(facade); } + private static boolean isLValue(@NotNull KtSimpleNameExpression expression) { + PsiElement parent = PsiTreeUtil.skipParentsOfType(expression, KtParenthesizedExpression.class); + if (!(parent instanceof KtBinaryExpression)) return false; + KtBinaryExpression binaryExpression = (KtBinaryExpression) parent; + if (!KtTokens.ALL_ASSIGNMENTS.contains(binaryExpression.getOperationToken())) return false; + return PsiTreeUtil.isAncestor(binaryExpression.getLeft(), expression, false); + } + @Override public KotlinTypeInfo visitSimpleNameExpression(@NotNull KtSimpleNameExpression expression, ExpressionTypingContext context) { // TODO : other members // TODO : type substitutions??? CallExpressionResolver callExpressionResolver = components.callExpressionResolver; KotlinTypeInfo typeInfo = callExpressionResolver.getSimpleNameExpressionTypeInfo(expression, NO_RECEIVER, null, context); + if (typeInfo.getType() != null && !typeInfo.getType().isError() && !isLValue(expression)) { + DataFlowValue dataFlowValue = DataFlowValueFactory.createDataFlowValue(expression, typeInfo.getType(), context); + Nullability nullability = context.dataFlowInfo.getPredictableNullability(dataFlowValue); + if (!nullability.canBeNonNull() && nullability.canBeNull()) { + context.trace.report(ALWAYS_NULL.on(expression)); + } + } + return components.dataFlowAnalyzer.checkType(typeInfo, expression, context); // TODO : Extensions to this } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/SenselessComparisonChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/SenselessComparisonChecker.kt index 3e782865f2a..62852b3153b 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/SenselessComparisonChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/SenselessComparisonChecker.kt @@ -50,7 +50,7 @@ object SenselessComparisonChecker { val nullability = getNullability(value) val expressionIsAlways = - if (nullability == Nullability.NULL) equality + if (nullability == Nullability.NULL) return else if (nullability == Nullability.NOT_NULL) !equality else if (nullability == Nullability.IMPOSSIBLE) false else return diff --git a/compiler/testData/diagnostics/tests/BinaryCallsOnNullableValues.kt b/compiler/testData/diagnostics/tests/BinaryCallsOnNullableValues.kt index 97a6a39012f..625b3d7aa61 100644 --- a/compiler/testData/diagnostics/tests/BinaryCallsOnNullableValues.kt +++ b/compiler/testData/diagnostics/tests/BinaryCallsOnNullableValues.kt @@ -5,24 +5,24 @@ class A() { fun f(): Unit { var x: Int? = 1 x = null - x + 1 - x plus 1 - x < 1 + x + 1 + x plus 1 + x < 1 x += 1 - x == 1 - x != 1 + x == 1 + x != 1 A() == 1 - x === "1" - x !== "1" + x === "1" + x !== "1" - x === 1 - x !== 1 + x === 1 + x !== 1 - x..2 - x in 1..2 + x..2 + x in 1..2 val y : Boolean? = true false || y diff --git a/compiler/testData/diagnostics/tests/Nullability.kt b/compiler/testData/diagnostics/tests/Nullability.kt index 4f0d2c72a59..173bad78d23 100644 --- a/compiler/testData/diagnostics/tests/Nullability.kt +++ b/compiler/testData/diagnostics/tests/Nullability.kt @@ -4,7 +4,7 @@ fun test() { a.plus(1) } else { - a?.plus(1) + a?.plus(1) } val out : java.io.PrintStream? = null @@ -28,7 +28,7 @@ fun test() { } if (out == null) { - out?.println() + out?.println() } else { out.println() } @@ -88,7 +88,7 @@ fun test() { } if (out == null) { - out?.println() + out?.println() } else { out.println() } @@ -140,13 +140,13 @@ fun test() { while (out != null) { out.println(); } - out?.println(); + out?.println(); val out2 : java.io.PrintStream? = null while (out2 == null) { - out2?.println(); - out2.println(); + out2?.println(); + out2.println(); } out2.println() @@ -235,7 +235,7 @@ fun f7(s : String?, t : String?) { } s?.get(0) if (!(s != null)) { - s?.get(0) + s?.get(0) } else { s.get(0) @@ -245,7 +245,7 @@ fun f7(s : String?, t : String?) { s.get(0) } else { - s?.get(0) + s?.get(0) } s?.get(0) t?.get(0) @@ -264,7 +264,7 @@ fun f7(s : String?, t : String?) { t?.get(0) } else { - s?.get(0) + s?.get(0) t?.get(0) } } diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ArrayAccess.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ArrayAccess.kt index 8c2964c1f5e..a40c8c33504 100644 --- a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ArrayAccess.kt +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ArrayAccess.kt @@ -7,7 +7,7 @@ fun foo() { val x: Int? = null val a = Array(3, {0}) - if (x != null) bar(a[x]) else bar(a[x]) + if (x != null) bar(a[x]) else bar(a[x]) bar(a[if (x == null) 0 else x]) bar(a[x]) diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/BinaryExpression.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/BinaryExpression.kt index 0cff17fbe62..c319f861534 100644 --- a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/BinaryExpression.kt +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/BinaryExpression.kt @@ -5,6 +5,6 @@ fun foo() { val x: Int? = null bar(1 + (if (x == null) 0 else x)) - bar(if (x == null) x else x) + bar(if (x == null) x else x) if (x != null) bar(x + x/(x-x*x)) } diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/DeepIf.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/DeepIf.kt index 94245db3a22..0aafb99c7c2 100644 --- a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/DeepIf.kt +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/DeepIf.kt @@ -16,15 +16,15 @@ fun foo() { } if (x == null) bar(x) else bar(x) bar(bar(x)) - } else if (x == null) { - bar(x) - if (x != null) { + } else if (x == null) { + bar(x) + if (x != null) { bar(x) if (x == null) bar(x) if (x == null) bar(x) else bar(x) bar(bar(x) + bar(x)) - } else if (x == null) { - bar(x) + } else if (x == null) { + bar(x) } } diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/DoWhile.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/DoWhile.kt index a45b9bfc4e0..44ed60af0c5 100644 --- a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/DoWhile.kt +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/DoWhile.kt @@ -12,5 +12,5 @@ fun foo() { do { bar(y) } while (y != null) - bar(y) + bar(y) } diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ExclExcl.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ExclExcl.kt index 6dd93c9633a..b3a7f0c26c7 100644 --- a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ExclExcl.kt +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ExclExcl.kt @@ -3,19 +3,19 @@ fun bar(x: Int) = x + 1 fun f1(x: Int?) { bar(x) if (x != null) bar(x!!) - if (x == null) bar(x!!) + if (x == null) bar(x!!) } fun f2(x: Int?) { - if (x != null) else x!! + if (x != null) else x!! } fun f3(x: Int?) { - if (x != null) bar(x!!) else x!! + if (x != null) bar(x!!) else x!! } fun f4(x: Int?) { - if (x == null) x!! else bar(x!!) + if (x == null) x!! else bar(x!!) } fun f5(x: Int?) { diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/IfThenElse.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/IfThenElse.kt index eacba197ebd..9a1a0403b94 100644 --- a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/IfThenElse.kt +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/IfThenElse.kt @@ -6,7 +6,7 @@ fun foo() { bar(if (x == null) 0 else x) if (x == null) { - bar(x) + bar(x) return } else { bar(x) diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ObjectExpression.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ObjectExpression.kt index 03f3dd509dc..e0b3cab94f9 100644 --- a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ObjectExpression.kt +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ObjectExpression.kt @@ -5,6 +5,6 @@ fun foo() { val a = object { fun baz() = bar(if (x == null) 0 else x) - fun quux(): Int = if (x == null) x else x + fun quux(): Int = if (x == null) x else x } } diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/Return.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/Return.kt index 9def383c3bf..a427ab81e36 100644 --- a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/Return.kt +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/Return.kt @@ -8,10 +8,10 @@ fun foo(): Int { if (x != null) return x val y: Int? = null - if (y == null) return if (y != null) y else y + if (y == null) return if (y != null) y else y val z: Int? = null if (z != null) return if (z == null) z else z - return z + return z } diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ThisSuper.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ThisSuper.kt index 59b56966250..b758b6a3dcc 100644 --- a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ThisSuper.kt +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ThisSuper.kt @@ -16,6 +16,6 @@ class Derived : Base() { val y: Int? = null if (y != null) super.bar(this.baz(y)) - else this.baz(super.bar(y)) + else this.baz(super.bar(y)) } } diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/Throw.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/Throw.kt index 4b62baeab9c..b5d0b0051fd 100644 --- a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/Throw.kt +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/Throw.kt @@ -3,7 +3,7 @@ fun bar(x: Int): RuntimeException = RuntimeException(x.toString()) fun foo() { val x: Int? = null - if (x == null) throw bar(x) + if (x == null) throw bar(x) throw bar(x) throw bar(x) } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/While.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/While.kt index d1e9886edb0..527ad28bc46 100644 --- a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/While.kt +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/While.kt @@ -3,7 +3,7 @@ fun bar(x: Int): Int = x + 1 fun foo() { val x: Int? = null while (x == null) { - bar(x) + bar(x) } bar(x) @@ -11,11 +11,11 @@ fun foo() { while (y != null) { bar(y) } - bar(y) + bar(y) val z: Int? = null while (z == null) { - bar(z) + bar(z) break } bar(z) diff --git a/compiler/testData/diagnostics/tests/incompleteCode/checkNothingIsSubtype.kt b/compiler/testData/diagnostics/tests/incompleteCode/checkNothingIsSubtype.kt index 93be2ea5826..5fb3ce03e0b 100644 --- a/compiler/testData/diagnostics/tests/incompleteCode/checkNothingIsSubtype.kt +++ b/compiler/testData/diagnostics/tests/incompleteCode/checkNothingIsSubtype.kt @@ -6,7 +6,7 @@ interface A fun infer(a: A) : T {} fun test(nothing: Nothing?) { - val i = infer(nothing) + val i = infer(nothing) } fun sum(a : IntArray) : Int { diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/NullableNothingIsExactlyNull.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/NullableNothingIsExactlyNull.kt index 0dc63a98c3d..f493f14fb93 100644 --- a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/NullableNothingIsExactlyNull.kt +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/NullableNothingIsExactlyNull.kt @@ -1,8 +1,8 @@ fun test() { val out : Int? = null val x : Nothing? = null - if (out != x) + if (out != x) out.plus(1) - if (out == x) return + if (out == x) return out.plus(1) } diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2146.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2146.kt index 8c720b29589..feaf1ca1e37 100644 --- a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2146.kt +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2146.kt @@ -25,7 +25,7 @@ fun f3(s: Int?): Int { fun f4(s: Int?): Int { return when { s == 4 -> s - s == null -> s + s == null -> s else -> s } } diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2164.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2164.kt index 7e5dba858fd..2517fbddc36 100644 --- a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2164.kt +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2164.kt @@ -21,8 +21,8 @@ fun main(args : Array) { foo(x!!) foo(x) } else { - foo(x) - foo(x!!) + foo(x) + foo(x!!) foo(x) } diff --git a/compiler/testData/diagnostics/tests/nullableTypes/nullAssertOnTypeWithNullableUpperBound.kt b/compiler/testData/diagnostics/tests/nullableTypes/nullAssertOnTypeWithNullableUpperBound.kt index 63e01551ff4..205d234acca 100644 --- a/compiler/testData/diagnostics/tests/nullableTypes/nullAssertOnTypeWithNullableUpperBound.kt +++ b/compiler/testData/diagnostics/tests/nullableTypes/nullAssertOnTypeWithNullableUpperBound.kt @@ -2,7 +2,7 @@ fun test(t: T): T { if (t != null) { return t!! } - return t!! + return t!! } fun T.testThis(): String { diff --git a/compiler/testData/diagnostics/tests/nullableTypes/safeCallOnTypeWithNullableUpperBound.kt b/compiler/testData/diagnostics/tests/nullableTypes/safeCallOnTypeWithNullableUpperBound.kt index cd310a55280..f06cb65d206 100644 --- a/compiler/testData/diagnostics/tests/nullableTypes/safeCallOnTypeWithNullableUpperBound.kt +++ b/compiler/testData/diagnostics/tests/nullableTypes/safeCallOnTypeWithNullableUpperBound.kt @@ -2,7 +2,7 @@ fun test(t: T): String? { if (t != null) { return t?.toString() } - return t?.toString() + return t?.toString() } fun T.testThis(): String? { diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/senselessComparisonEquals.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/senselessComparisonEquals.kt index 3e16583b802..014518122fd 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/senselessComparisonEquals.kt +++ b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/senselessComparisonEquals.kt @@ -33,10 +33,10 @@ fun test() { if (platformN != null) {} if (platformN == null) {} - if (a == null && platformN == a) {} + if (a == null && platformN == a) {} if (platformJ != null) {} if (platformJ == null) {} - if (a == null && platformJ == a) {} + if (a == null && platformJ == a) {} } diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/senselessComparisonIdentityEquals.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/senselessComparisonIdentityEquals.kt index ee64b8d261e..f2e0bb3d835 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/senselessComparisonIdentityEquals.kt +++ b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/senselessComparisonIdentityEquals.kt @@ -31,10 +31,10 @@ fun test() { if (platformN !== null) {} if (platformN === null) {} - if (a === null && platformN === a) {} + if (a === null && platformN === a) {} if (platformJ !== null) {} if (platformJ === null) {} - if (a === null && platformJ === a) {} + if (a === null && platformJ === a) {} } diff --git a/compiler/testData/diagnostics/tests/smartCasts/alwaysNull.kt b/compiler/testData/diagnostics/tests/smartCasts/alwaysNull.kt new file mode 100644 index 00000000000..d3c642bcf90 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/alwaysNull.kt @@ -0,0 +1,11 @@ +fun foo(): String { + var s: String? + s = null + s?.length + if (s == null) s = "z" + var t: String? = "y" + if (t == null) t = "x" + var x: Int? = null + if (x == null) x += null + return t + s +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/alwaysNull.txt b/compiler/testData/diagnostics/tests/smartCasts/alwaysNull.txt new file mode 100644 index 00000000000..3f9a1d7fdfe --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/alwaysNull.txt @@ -0,0 +1,3 @@ +package + +public fun foo(): kotlin.String diff --git a/compiler/testData/diagnostics/tests/smartCasts/comparisonUnderAnd.kt b/compiler/testData/diagnostics/tests/smartCasts/comparisonUnderAnd.kt index c797a019214..ac7a34246d1 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/comparisonUnderAnd.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/comparisonUnderAnd.kt @@ -8,19 +8,19 @@ fun foo(x : String?, y : String?) { x.length y.length } - if (y != null || x == y) { + if (y != null || x == y) { x.length y.length } else { // y == null but x != y x.length - y.length + y.length } - if (y == null && x != y) { + if (y == null && x != y) { // y == null but x != y x.length - y.length + y.length } else { x.length diff --git a/compiler/testData/diagnostics/tests/smartCasts/complexComparison.kt b/compiler/testData/diagnostics/tests/smartCasts/complexComparison.kt index f9d0d54bc81..e10a04691ce 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/complexComparison.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/complexComparison.kt @@ -3,10 +3,10 @@ fun foo(x: String?, y: String?, z: String?, w: String?) { z.length else z.length - if (x != null || y != null || (x != z && y != z)) + if (x != null || y != null || (x != z && y != z)) z.length else - z.length + z.length if (x == null || y == null || (x != z && y != z)) z.length else diff --git a/compiler/testData/diagnostics/tests/smartCasts/incDecToNull.kt b/compiler/testData/diagnostics/tests/smartCasts/incDecToNull.kt new file mode 100644 index 00000000000..7e849803919 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/incDecToNull.kt @@ -0,0 +1,10 @@ +class IncDec { + operator fun inc(): Unit {} +} + +fun foo(): IncDec { + var x = IncDec() + x = x++ + x++ + return x +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/incDecToNull.txt b/compiler/testData/diagnostics/tests/smartCasts/incDecToNull.txt new file mode 100644 index 00000000000..ff8c885ae59 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/incDecToNull.txt @@ -0,0 +1,11 @@ +package + +public fun foo(): IncDec + +public final class IncDec { + public constructor IncDec() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final operator fun inc(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/notNullorNotNull.kt b/compiler/testData/diagnostics/tests/smartCasts/notNullorNotNull.kt index 9dac31ac47e..8d45f94b243 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/notNullorNotNull.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/notNullorNotNull.kt @@ -1,6 +1,6 @@ fun bar(x: Int?): Int { if (x != null) return -1 - if (x == null) return -2 + if (x == null) return -2 // Should be unreachable return 2 + 2 } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/assignment.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/assignment.kt index 1515296a1e4..32a19e9b3b1 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/assignment.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/assignment.kt @@ -4,7 +4,7 @@ fun foo() { v = "abc" v.length v = null - v.length + v.length v = "abc" v.length } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/initialization.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/initialization.kt index 40e3476b7b0..30caa4b7066 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/initialization.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/initialization.kt @@ -3,5 +3,5 @@ fun foo() { // It is possible in principle to provide smart cast here v.length v = null - v.length + v.length } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varIntNull.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varIntNull.kt index adccbb76fc1..a3b90e83445 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varIntNull.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varIntNull.kt @@ -1,5 +1,5 @@ fun foo(): Int { var i: Int? = 42 i = null - return i + 1 + return i + 1 } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varNull.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varNull.kt index db479c7c1cc..e0493bea139 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varNull.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varNull.kt @@ -1,5 +1,5 @@ fun foo(): Int { var s: String? = "abc" s = null - return s.length + return s.length } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/ElseOnNullableEnumWithSmartCast.kt b/compiler/testData/diagnostics/tests/when/ElseOnNullableEnumWithSmartCast.kt index f0f8219837f..9bd8f3fe69b 100644 --- a/compiler/testData/diagnostics/tests/when/ElseOnNullableEnumWithSmartCast.kt +++ b/compiler/testData/diagnostics/tests/when/ElseOnNullableEnumWithSmartCast.kt @@ -6,6 +6,6 @@ fun foo(e: E, something: Any?): Int { return when (e) { E.A -> 1 E.B -> 2 - something -> 3 + something -> 3 } } diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/block.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/block.kt index b596dadb1bd..c40be6d576a 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/block.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/block.kt @@ -9,5 +9,5 @@ fun test() { fun dynamic(body: dynamic.() -> T): T { val topLevel = null - return topLevel.body() + return topLevel.body() } \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 87aa674afb9..59b6ecb7242 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -14367,6 +14367,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/smartCasts"), Pattern.compile("^(.+)\\.kt$"), true); } + @TestMetadata("alwaysNull.kt") + public void testAlwaysNull() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/alwaysNull.kt"); + doTest(fileName); + } + @TestMetadata("classObjectMember.kt") public void testClassObjectMember() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/classObjectMember.kt"); @@ -14463,6 +14469,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("incDecToNull.kt") + public void testIncDecToNull() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/incDecToNull.kt"); + doTest(fileName); + } + @TestMetadata("kt1461.kt") public void testKt1461() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/kt1461.kt"); diff --git a/idea/testData/checker/Nullability.kt b/idea/testData/checker/Nullability.kt index b2c32fb7e98..e47dc69aa7e 100644 --- a/idea/testData/checker/Nullability.kt +++ b/idea/testData/checker/Nullability.kt @@ -4,7 +4,7 @@ fun test() { a.plus(1) } else { - a?.plus(1) + a?.plus(1) } val out : java.io.PrintStream? = null @@ -28,7 +28,7 @@ fun test() { } if (out == null) { - out?.println() + out?.println() } else { out.println() } @@ -84,7 +84,7 @@ fun test() { } if (out == null) { - out?.println() + out?.println() } else { out.println() } @@ -131,12 +131,12 @@ fun test() { while (out != null) { out.println(); } - out?.println(); + out?.println(); val out2 : java.io.PrintStream? = null while (out2 == null) { - out2?.println(); + out2?.println(); } out2.println() @@ -224,7 +224,7 @@ fun f7(s : String?, t : String?) { } s?.get(0) if (!(s != null)) { - s?.get(0) + s?.get(0) } else { s.get(0) @@ -234,7 +234,7 @@ fun f7(s : String?, t : String?) { s.get(0) } else { - s?.get(0) + s?.get(0) } s?.get(0) t?.get(0) @@ -253,7 +253,7 @@ fun f7(s : String?, t : String?) { t?.get(0) } else { - s?.get(0) + s?.get(0) t?.get(0) } }