Files
kotlin/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/arrayListNullable.kt
Denis Zharkov 8b49a1d660 Add PurelyImplements annotation
It's parameter is FQ-name of class (currently only from builtins) that added as supertype to annotated Java class.

Parameters of annotated class used as non-flexible arguments of added supertype, that helps to propagate more precise types when using in Kotlin.
Some standard JDK collections loaded as they annotated with PurelyImplements.

See tests for clarification.
Before: ArrayList<Int>.add(x: Int!) // possible to add null
After: ArrayList<Int>.add(x: Int)   // impossible to add null

 #KT-7628 Fixed
 #KT-7835 Fixed
2015-07-09 16:36:47 +03:00

23 lines
427 B
Kotlin
Vendored

// !DIAGNOSTICS: -UNUSED_VARIABLE
import java.util.*
fun bar(): String? = null
fun foo() {
var x = ArrayList<String?>()
x.add(null)
x.add(bar())
x.add("")
x[0] = null
x[0] = bar()
x[0] = ""
val b1: MutableList<String?> = x
val b2: MutableList<String> = <!TYPE_MISMATCH!>x<!>
val b3: List<String?> = x
val b4: Collection<String?> = x
val b6: MutableCollection<String?> = x
}