Minor. Add tests checking not-null assertions
More precisely these tests check cases when expected type was somehow obtained from captured type (in member scope with projections)
This commit is contained in:
@@ -27,10 +27,8 @@ import org.jetbrains.kotlin.resolve.calls.context.CallResolutionContext
|
||||
import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||
import org.jetbrains.kotlin.types.upperIfFlexible
|
||||
|
||||
public class RuntimeAssertionInfo(public val needNotNullAssertion: Boolean, public val message: String) {
|
||||
public interface DataFlowExtras {
|
||||
@@ -53,7 +51,7 @@ public class RuntimeAssertionInfo(public val needNotNullAssertion: Boolean, publ
|
||||
dataFlowExtras: DataFlowExtras
|
||||
): RuntimeAssertionInfo? {
|
||||
fun assertNotNull(): Boolean {
|
||||
if (expectedType.isError() || expressionType.isError()) return false
|
||||
if (expectedType.isError || expressionType.isError) return false
|
||||
|
||||
// T : Any, T! = T..T?
|
||||
// Let T$ will be copy of T! with enhanced nullability.
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
class A<T> {
|
||||
fun add(element: T) {}
|
||||
}
|
||||
|
||||
public fun <R : Any> foo(x: MutableCollection<in R>, block: java.util.AbstractList<R>) {
|
||||
x.add(block.get(0))
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
class A<T> {
|
||||
fun add(element: T) {}
|
||||
}
|
||||
|
||||
public fun <R> foo(x: MutableCollection<in R>, block: () -> R) {
|
||||
x.add(block())
|
||||
}
|
||||
@@ -157,6 +157,22 @@ public class GenerateNotNullAssertionsTest extends CodegenTestCase {
|
||||
assertNoIntrinsicsMethodIsCalledInMyClasses(true);
|
||||
}
|
||||
|
||||
public void testNoAssertionForNullableCaptured() {
|
||||
setUpEnvironment(false, true);
|
||||
|
||||
loadFile("notNullAssertions/noAssertionForNullableCaptured.kt");
|
||||
|
||||
assertNoIntrinsicsMethodIsCalledInMyClasses(true);
|
||||
}
|
||||
|
||||
public void testAssertionForNotNullCaptured() {
|
||||
setUpEnvironment(false, true);
|
||||
|
||||
loadFile("notNullAssertions/assertionForNotNullCaptured.kt");
|
||||
|
||||
assertTrue(generateToText().contains("checkExpressionValueIsNotNull"));
|
||||
}
|
||||
|
||||
public void testNoAssertionForNullableGenericMethodCall() {
|
||||
setUpEnvironment(false, true);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user