mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-08 15:53:19 +00:00
Do not generate not-null assertion for argument of Collection.contains
Of course not only for contains but for other methods having INSTANCEOF bar.rier
Otherwise using platform null values becomes for such methods becomes
dangerous in cases like `platformString in setOf("", "")`
This commit is contained in:
7
compiler/testData/codegen/boxWithJava/collections/platformValueContains/J.java
vendored
Normal file
7
compiler/testData/codegen/boxWithJava/collections/platformValueContains/J.java
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import java.util.*;
|
||||
|
||||
public class J {
|
||||
public static String nullValue() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
40
compiler/testData/codegen/boxWithJava/collections/platformValueContains/platformValueContains.kt
vendored
Normal file
40
compiler/testData/codegen/boxWithJava/collections/platformValueContains/platformValueContains.kt
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
class MySet : Set<String> {
|
||||
override val size: Int
|
||||
get() = throw UnsupportedOperationException()
|
||||
|
||||
override fun isEmpty(): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun contains(o: String): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun iterator(): Iterator<String> {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun containsAll(c: Collection<String>): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val mySet = MySet()
|
||||
|
||||
// no UnsupportedOperationException thrown
|
||||
mySet.contains(J.nullValue())
|
||||
J.nullValue() in mySet
|
||||
|
||||
val set: Set<String> = mySet
|
||||
set.contains(J.nullValue())
|
||||
J.nullValue() in set
|
||||
|
||||
val anySet: Set<Any?> = mySet as Set<Any?>
|
||||
anySet.contains(J.nullValue())
|
||||
anySet.contains(null)
|
||||
J.nullValue() in anySet
|
||||
null in anySet
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user