diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ControlStructureTypingVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ControlStructureTypingVisitor.java index 7c729f3a22b..ce6428f7ee3 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ControlStructureTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ControlStructureTypingVisitor.java @@ -332,18 +332,6 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor { Call iteratorCall = calls.getFirst(); OverloadResolutionResults iteratorResolutionResults = calls.getSecond(); - // We allow the loop range to be null (nothing happens), so we make the receiver type non-null - if (!iteratorResolutionResults.isSuccess()) { - ExpressionReceiver nonNullReceiver = new ExpressionReceiver(loopRange.getExpression(), TypeUtils.makeNotNullable(loopRange.getType())); - Pair> callsNonNull = makeAndResolveFakeCall(nonNullReceiver, context, iterator); - Call iteratorCallWithNonNullReceiver = callsNonNull.getFirst(); - OverloadResolutionResults iteratorResolutionResultsWithNonNullReceiver = callsNonNull.getSecond(); - if (iteratorResolutionResultsWithNonNullReceiver.isSuccess()) { - iteratorResolutionResults = iteratorResolutionResultsWithNonNullReceiver; - iteratorCall = iteratorCallWithNonNullReceiver; - } - } - if (iteratorResolutionResults.isSuccess()) { ResolvedCall iteratorResolvedCall = iteratorResolutionResults.getResultingCall(); context.trace.record(LOOP_RANGE_ITERATOR_RESOLVED_CALL, loopRangeExpression, iteratorResolvedCall); diff --git a/compiler/testData/codegen/controlStructures/forNullableIntArray.jet b/compiler/testData/codegen/controlStructures/forNullableIntArray.jet index 0b30bc8224f..9f3749aa08d 100644 --- a/compiler/testData/codegen/controlStructures/forNullableIntArray.jet +++ b/compiler/testData/codegen/controlStructures/forNullableIntArray.jet @@ -12,10 +12,5 @@ fun box() : String { System.out?.println(sum) if(sum != 10) return "b failed" - val d : Array? = null - for (el in d) { - sum = sum + (el ?: 7) - } - return "OK" } \ No newline at end of file diff --git a/compiler/testData/codegen/controlStructures/forPrimitiveIntArray.jet b/compiler/testData/codegen/controlStructures/forPrimitiveIntArray.jet index b03fc06176d..0822b4f6aac 100644 --- a/compiler/testData/codegen/controlStructures/forPrimitiveIntArray.jet +++ b/compiler/testData/codegen/controlStructures/forPrimitiveIntArray.jet @@ -10,10 +10,5 @@ fun box() : String { } if(sum != 10) return "a failed" - val b : IntArray? = null - for (el in b) { - sum = sum + el - } - return "OK" } \ No newline at end of file diff --git a/compiler/testData/codegen/regressions/kt1482_2279.kt b/compiler/testData/codegen/regressions/kt1482_2279.kt index 18e476bf63d..bed64b91282 100644 --- a/compiler/testData/codegen/regressions/kt1482_2279.kt +++ b/compiler/testData/codegen/regressions/kt1482_2279.kt @@ -2,7 +2,7 @@ abstract class ClassValAbstract { abstract var a: Int class object { - val methods = (this as java.lang.Object).getClass()?.getClassLoader()?.loadClass("ClassValAbstract")?.getMethods() + val methods = (this as java.lang.Object).getClass()?.getClassLoader()?.loadClass("ClassValAbstract")?.getMethods()!! } } diff --git a/compiler/testData/codegen/regressions/kt1932.kt b/compiler/testData/codegen/regressions/kt1932.kt index 5a83165a102..b8040c69354 100644 --- a/compiler/testData/codegen/regressions/kt1932.kt +++ b/compiler/testData/codegen/regressions/kt1932.kt @@ -11,7 +11,7 @@ class Test() { fun box(): String { val test = Test() - for (method in javaClass().getMethods()) { + for (method in javaClass().getMethods()!!) { val anns = method?.getAnnotations() as Array if (!anns.isEmpty()) { for (ann in anns) { diff --git a/compiler/testData/codegen/regressions/kt237.jet b/compiler/testData/codegen/regressions/kt237.jet index c82ae4277a9..c2867130740 100644 --- a/compiler/testData/codegen/regressions/kt237.jet +++ b/compiler/testData/codegen/regressions/kt237.jet @@ -17,7 +17,7 @@ fun fff(x: T) : T { return x } fun id(value: T): T = value -fun foreach(array: Array?, action: (Int)-> Unit) { +fun foreach(array: Array, action: (Int)-> Unit) { for (el in array) { action(el) //exception through compilation (see below) } diff --git a/compiler/testData/codegen/regressions/kt903.jet b/compiler/testData/codegen/regressions/kt903.jet index e67b42612d7..4e7a8e0410b 100644 --- a/compiler/testData/codegen/regressions/kt903.jet +++ b/compiler/testData/codegen/regressions/kt903.jet @@ -5,7 +5,7 @@ fun Int.plus(a: Int?) = this + a.sure() public open class PerfectNumberFinder() { open public fun isPerfect(number : Int) : Boolean { - var factors : List? = ArrayList() + var factors : List = ArrayList() factors?.add(1) factors?.add(number) for (i in 2..(Math.sqrt((number).toDouble()) - 1).toInt()) diff --git a/compiler/testData/diagnostics/tests/controlStructures/forLoopWithNullableRange.kt b/compiler/testData/diagnostics/tests/controlStructures/forLoopWithNullableRange.kt new file mode 100644 index 00000000000..8482ed6bbbf --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/forLoopWithNullableRange.kt @@ -0,0 +1,16 @@ +class Coll { + fun iterator(): It = It() +} + +class It { + fun next() = 1 + fun hasNext() = false +} + +fun test(c: Coll?) { + for (x in c) {} + + if (c != null) { + for(x in c) {} + } +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index baefd98e7f1..ae878e22f1b 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -874,6 +874,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.checkers.AbstractDiagnosticsTestWithEagerResolve", new File("compiler/testData/diagnostics/tests/controlStructures"), "kt", false); } + @TestMetadata("forLoopWithNullableRange.kt") + public void testForLoopWithNullableRange() throws Exception { + doTest("compiler/testData/diagnostics/tests/controlStructures/forLoopWithNullableRange.kt"); + } + @TestMetadata("ForWithoutBraces.kt") public void testForWithoutBraces() throws Exception { doTest("compiler/testData/diagnostics/tests/controlStructures/ForWithoutBraces.kt"); diff --git a/libraries/stdlib/src/generated/ArraysFromJLangIterablesLazy.kt b/libraries/stdlib/src/generated/ArraysFromJLangIterablesLazy.kt index 56ff531f204..6a5fd05a52d 100644 --- a/libraries/stdlib/src/generated/ArraysFromJLangIterablesLazy.kt +++ b/libraries/stdlib/src/generated/ArraysFromJLangIterablesLazy.kt @@ -76,7 +76,7 @@ public inline fun Array.plus(elements: Array): List { * * @includeFunctionBody ../../test/CollectionTest.kt requireNoNulls */ -public inline fun Array?.requireNoNulls() : List { +public inline fun Array.requireNoNulls() : List { val list = ArrayList() for (element in this) { if (element == null) { diff --git a/libraries/stdlib/src/generated/BooleanArraysFromJLangIterablesLazy.kt b/libraries/stdlib/src/generated/BooleanArraysFromJLangIterablesLazy.kt index 21b688bd29d..ea05ed38721 100644 --- a/libraries/stdlib/src/generated/BooleanArraysFromJLangIterablesLazy.kt +++ b/libraries/stdlib/src/generated/BooleanArraysFromJLangIterablesLazy.kt @@ -76,7 +76,7 @@ public inline fun BooleanArray.plus(elements: BooleanArray): List { * * @includeFunctionBody ../../test/CollectionTest.kt requireNoNulls */ -public inline fun BooleanArray?.requireNoNulls() : List { +public inline fun BooleanArray.requireNoNulls() : List { val list = ArrayList() for (element in this) { if (element == null) { diff --git a/libraries/stdlib/src/generated/ByteArraysFromJLangIterablesLazy.kt b/libraries/stdlib/src/generated/ByteArraysFromJLangIterablesLazy.kt index deb5732d2e7..c819c1f0d19 100644 --- a/libraries/stdlib/src/generated/ByteArraysFromJLangIterablesLazy.kt +++ b/libraries/stdlib/src/generated/ByteArraysFromJLangIterablesLazy.kt @@ -76,7 +76,7 @@ public inline fun ByteArray.plus(elements: ByteArray): List { * * @includeFunctionBody ../../test/CollectionTest.kt requireNoNulls */ -public inline fun ByteArray?.requireNoNulls() : List { +public inline fun ByteArray.requireNoNulls() : List { val list = ArrayList() for (element in this) { if (element == null) { diff --git a/libraries/stdlib/src/generated/CharArraysFromJLangIterablesLazy.kt b/libraries/stdlib/src/generated/CharArraysFromJLangIterablesLazy.kt index 6e4c9d0d59d..ddc3a784194 100644 --- a/libraries/stdlib/src/generated/CharArraysFromJLangIterablesLazy.kt +++ b/libraries/stdlib/src/generated/CharArraysFromJLangIterablesLazy.kt @@ -76,7 +76,7 @@ public inline fun CharArray.plus(elements: CharArray): List { * * @includeFunctionBody ../../test/CollectionTest.kt requireNoNulls */ -public inline fun CharArray?.requireNoNulls() : List { +public inline fun CharArray.requireNoNulls() : List { val list = ArrayList() for (element in this) { if (element == null) { diff --git a/libraries/stdlib/src/generated/DoubleArraysFromJLangIterablesLazy.kt b/libraries/stdlib/src/generated/DoubleArraysFromJLangIterablesLazy.kt index 1210e6c33f4..f0d91ef916e 100644 --- a/libraries/stdlib/src/generated/DoubleArraysFromJLangIterablesLazy.kt +++ b/libraries/stdlib/src/generated/DoubleArraysFromJLangIterablesLazy.kt @@ -76,7 +76,7 @@ public inline fun DoubleArray.plus(elements: DoubleArray): List { * * @includeFunctionBody ../../test/CollectionTest.kt requireNoNulls */ -public inline fun DoubleArray?.requireNoNulls() : List { +public inline fun DoubleArray.requireNoNulls() : List { val list = ArrayList() for (element in this) { if (element == null) { diff --git a/libraries/stdlib/src/generated/FloatArraysFromJLangIterablesLazy.kt b/libraries/stdlib/src/generated/FloatArraysFromJLangIterablesLazy.kt index 4f71ad6cb37..fd57b86114c 100644 --- a/libraries/stdlib/src/generated/FloatArraysFromJLangIterablesLazy.kt +++ b/libraries/stdlib/src/generated/FloatArraysFromJLangIterablesLazy.kt @@ -76,7 +76,7 @@ public inline fun FloatArray.plus(elements: FloatArray): List { * * @includeFunctionBody ../../test/CollectionTest.kt requireNoNulls */ -public inline fun FloatArray?.requireNoNulls() : List { +public inline fun FloatArray.requireNoNulls() : List { val list = ArrayList() for (element in this) { if (element == null) { diff --git a/libraries/stdlib/src/generated/IntArraysFromJLangIterablesLazy.kt b/libraries/stdlib/src/generated/IntArraysFromJLangIterablesLazy.kt index e82ea902947..50ef61a5818 100644 --- a/libraries/stdlib/src/generated/IntArraysFromJLangIterablesLazy.kt +++ b/libraries/stdlib/src/generated/IntArraysFromJLangIterablesLazy.kt @@ -76,7 +76,7 @@ public inline fun IntArray.plus(elements: IntArray): List { * * @includeFunctionBody ../../test/CollectionTest.kt requireNoNulls */ -public inline fun IntArray?.requireNoNulls() : List { +public inline fun IntArray.requireNoNulls() : List { val list = ArrayList() for (element in this) { if (element == null) { diff --git a/libraries/stdlib/src/generated/LongArraysFromJLangIterablesLazy.kt b/libraries/stdlib/src/generated/LongArraysFromJLangIterablesLazy.kt index ff04120eeb0..a4f7cf15ec7 100644 --- a/libraries/stdlib/src/generated/LongArraysFromJLangIterablesLazy.kt +++ b/libraries/stdlib/src/generated/LongArraysFromJLangIterablesLazy.kt @@ -76,7 +76,7 @@ public inline fun LongArray.plus(elements: LongArray): List { * * @includeFunctionBody ../../test/CollectionTest.kt requireNoNulls */ -public inline fun LongArray?.requireNoNulls() : List { +public inline fun LongArray.requireNoNulls() : List { val list = ArrayList() for (element in this) { if (element == null) { diff --git a/libraries/stdlib/src/generated/ShortArraysFromJLangIterablesLazy.kt b/libraries/stdlib/src/generated/ShortArraysFromJLangIterablesLazy.kt index deca3f1acf2..1f8752be700 100644 --- a/libraries/stdlib/src/generated/ShortArraysFromJLangIterablesLazy.kt +++ b/libraries/stdlib/src/generated/ShortArraysFromJLangIterablesLazy.kt @@ -76,7 +76,7 @@ public inline fun ShortArray.plus(elements: ShortArray): List { * * @includeFunctionBody ../../test/CollectionTest.kt requireNoNulls */ -public inline fun ShortArray?.requireNoNulls() : List { +public inline fun ShortArray.requireNoNulls() : List { val list = ArrayList() for (element in this) { if (element == null) { diff --git a/libraries/stdlib/src/kotlin/JLangIterablesLazy.kt b/libraries/stdlib/src/kotlin/JLangIterablesLazy.kt index 380d88c582a..e178bc110ef 100644 --- a/libraries/stdlib/src/kotlin/JLangIterablesLazy.kt +++ b/libraries/stdlib/src/kotlin/JLangIterablesLazy.kt @@ -67,7 +67,7 @@ public inline fun Iterable.plus(elements: Iterable): List { * * @includeFunctionBody ../../test/CollectionTest.kt requireNoNulls */ -public inline fun Iterable?.requireNoNulls() : List { +public inline fun Iterable.requireNoNulls() : List { val list = ArrayList() for (element in this) { if (element == null) { diff --git a/libraries/stdlib/src/kotlin/io/Files.kt b/libraries/stdlib/src/kotlin/io/Files.kt index 8b46f8ccf76..fc996398bd0 100644 --- a/libraries/stdlib/src/kotlin/io/Files.kt +++ b/libraries/stdlib/src/kotlin/io/Files.kt @@ -14,7 +14,7 @@ import java.net.URL public fun File.recurse(block: (File) -> Unit): Unit { block(this) if (this.isDirectory()) { - for (child in this.listFiles()) { + for (child in this.listFiles()!!) { if (child != null) { child.recurse(block) } diff --git a/libraries/stdlib/src/kotlin/properties/Properties.kt b/libraries/stdlib/src/kotlin/properties/Properties.kt index afd65027ac3..7138e0ed14b 100644 --- a/libraries/stdlib/src/kotlin/properties/Properties.kt +++ b/libraries/stdlib/src/kotlin/properties/Properties.kt @@ -62,7 +62,7 @@ public abstract class ChangeSupport { } } if (allListeners != null) { - for (listener in allListeners) { + for (listener in allListeners!!) { listener.onPropertyChange(event) } } diff --git a/libraries/stdlib/src/kotlin/test/TestJVM.kt b/libraries/stdlib/src/kotlin/test/TestJVM.kt index 3229b72ee1a..b960c8ba865 100644 --- a/libraries/stdlib/src/kotlin/test/TestJVM.kt +++ b/libraries/stdlib/src/kotlin/test/TestJVM.kt @@ -16,7 +16,7 @@ public var asserter: Asserter get() { if (_asserter == null) { val klass = javaClass() - val loader = ServiceLoader.load(klass) + val loader = ServiceLoader.load(klass)!! for (a in loader) { if (a != null) { _asserter = a diff --git a/libraries/stdlib/test/language/NullableCollectionsTest.kt b/libraries/stdlib/test/language/NullableCollectionsTest.kt deleted file mode 100644 index f81e02624a8..00000000000 --- a/libraries/stdlib/test/language/NullableCollectionsTest.kt +++ /dev/null @@ -1,20 +0,0 @@ -package test.language - -import junit.framework.TestCase -import java.util.Collection -import kotlin.test.* - -class NullableCollectionsTest : TestCase() { - - fun testIterateOverNullCollectionsThrowsNPE() { - val c: Collection? = null - - // TODO currently this will throw a NPE - // should it either be a compile error or handle nulls gracefully? - failsWith { - for (e in c) { - println("Hey got $e") - } - } - } -} diff --git a/libraries/stdlib/test/org/jetbrains/kotlin/tools/GenerateJavaScriptStubs.kt b/libraries/stdlib/test/org/jetbrains/kotlin/tools/GenerateJavaScriptStubs.kt index a6759483829..8c2ca3b4561 100644 --- a/libraries/stdlib/test/org/jetbrains/kotlin/tools/GenerateJavaScriptStubs.kt +++ b/libraries/stdlib/test/org/jetbrains/kotlin/tools/GenerateJavaScriptStubs.kt @@ -128,7 +128,7 @@ import js.noImpl } } - for (pk in properties.values()) { + for (pk in properties.values()!!) { // some properties might not have a getter defined // so lets ignore those