[FIR-TEST] Add new testdata generated after changes in previous commit
This commit is contained in:
+39
@@ -0,0 +1,39 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !CHECK_TYPE
|
||||
|
||||
fun main() {
|
||||
val a : Int? = null
|
||||
val b : Int? = null
|
||||
checkSubtype<Int>(a!!)
|
||||
a!! + 2
|
||||
a!!.plus(2)
|
||||
a!!.plus(b!!)
|
||||
2.plus(b!!)
|
||||
2 + b!!
|
||||
|
||||
val c = 1
|
||||
c!!
|
||||
|
||||
val d : Any? = null
|
||||
|
||||
if (d != null) {
|
||||
d!!
|
||||
}
|
||||
|
||||
// smart cast isn't needed, but is reported due to KT-4294
|
||||
if (d is String) {
|
||||
d!!
|
||||
}
|
||||
|
||||
if (d is String?) {
|
||||
if (d != null) {
|
||||
d!!
|
||||
}
|
||||
if (d is String) {
|
||||
d!!
|
||||
}
|
||||
}
|
||||
|
||||
val f : String = a!!
|
||||
<!INAPPLICABLE_CANDIDATE!>checkSubtype<!><String>(a!!)
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
class A() {
|
||||
<!INAPPLICABLE_INFIX_MODIFIER!>operator infix fun plus(i : Int) {}<!>
|
||||
operator fun unaryMinus() {}
|
||||
<!INAPPLICABLE_INFIX_MODIFIER!>operator infix fun contains(a : Any?) : Boolean = true<!>
|
||||
}
|
||||
|
||||
operator infix fun A.div(i : Int) {}
|
||||
operator infix fun A?.times(i : Int) {}
|
||||
|
||||
fun test(x : Int?, a : A?) {
|
||||
x.<!INAPPLICABLE_CANDIDATE!>plus<!>(1)
|
||||
x?.plus(1)
|
||||
x <!INAPPLICABLE_CANDIDATE!>+<!> 1
|
||||
<!INAPPLICABLE_CANDIDATE!>-<!>x
|
||||
x.<!INAPPLICABLE_CANDIDATE!>unaryMinus<!>()
|
||||
x?.unaryMinus()
|
||||
|
||||
a.<!INAPPLICABLE_CANDIDATE!>plus<!>(1)
|
||||
a?.plus(1)
|
||||
a <!INAPPLICABLE_CANDIDATE!>plus<!> 1
|
||||
a <!INAPPLICABLE_CANDIDATE!>+<!> 1
|
||||
<!INAPPLICABLE_CANDIDATE!>-<!>a
|
||||
a.<!INAPPLICABLE_CANDIDATE!>unaryMinus<!>()
|
||||
a?.unaryMinus()
|
||||
|
||||
a.<!INAPPLICABLE_CANDIDATE!>div<!>(1)
|
||||
a <!INAPPLICABLE_CANDIDATE!>/<!> 1
|
||||
a <!INAPPLICABLE_CANDIDATE!>div<!> 1
|
||||
a?.div(1)
|
||||
|
||||
a.times(1)
|
||||
a * 1
|
||||
a times 1
|
||||
a?.times(1)
|
||||
|
||||
1 <!INAPPLICABLE_CANDIDATE!>in<!> a
|
||||
a <!INAPPLICABLE_CANDIDATE!>contains<!> 1
|
||||
a.<!INAPPLICABLE_CANDIDATE!>contains<!>(1)
|
||||
a?.contains(1)
|
||||
}
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
fun test() {
|
||||
val out : Int? = null
|
||||
val x : Nothing? = null
|
||||
if (out != x)
|
||||
out.<!INAPPLICABLE_CANDIDATE!>plus<!>(1)
|
||||
if (out == x) return
|
||||
out.<!INAPPLICABLE_CANDIDATE!>plus<!>(1)
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
class Foo {
|
||||
fun foo() {}
|
||||
}
|
||||
|
||||
fun Any?.foo() {}
|
||||
|
||||
fun test(f : Foo?) {
|
||||
f.foo()
|
||||
}
|
||||
Vendored
+30
@@ -0,0 +1,30 @@
|
||||
// !DIAGNOSTICS: -DEBUG_INFO_SMARTCAST
|
||||
class Foo {
|
||||
fun foo(a: Foo): Foo = a
|
||||
}
|
||||
|
||||
fun main() {
|
||||
val x: Foo? = null
|
||||
val y: Foo? = null
|
||||
|
||||
x.<!INAPPLICABLE_CANDIDATE!>foo<!>(y)
|
||||
x!!.foo(y)
|
||||
x.foo(y!!)
|
||||
x!!.foo(y!!)
|
||||
|
||||
val a: Foo? = null
|
||||
val b: Foo? = null
|
||||
val c: Foo? = null
|
||||
|
||||
a.<!INAPPLICABLE_CANDIDATE!>foo<!>(b.<!INAPPLICABLE_CANDIDATE!>foo<!>(c))
|
||||
a!!.foo(b.<!INAPPLICABLE_CANDIDATE!>foo<!>(c))
|
||||
a.foo(b!!.foo(c))
|
||||
a!!.foo(b!!.foo(c))
|
||||
a.foo(b.foo(c!!))
|
||||
a!!.foo(b.foo(c!!))
|
||||
a.foo(b!!.foo(c!!))
|
||||
a!!.foo(b!!.foo(c!!))
|
||||
|
||||
val z: Foo? = null
|
||||
z!!.foo(z!!)
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
class A {
|
||||
fun foo() {}
|
||||
}
|
||||
|
||||
fun A.bar() {}
|
||||
fun A?.buzz() {}
|
||||
|
||||
fun test(a : A?) {
|
||||
a.<!INAPPLICABLE_CANDIDATE!>foo<!>() // error
|
||||
a.<!INAPPLICABLE_CANDIDATE!>bar<!>() // error
|
||||
a.buzz()
|
||||
|
||||
a?.foo()
|
||||
a?.bar()
|
||||
a?.buzz()
|
||||
}
|
||||
|
||||
fun A.test2() {
|
||||
foo()
|
||||
bar()
|
||||
buzz()
|
||||
|
||||
this.foo()
|
||||
this.bar()
|
||||
this.buzz()
|
||||
|
||||
this?.foo() // warning
|
||||
this?.bar() // warning
|
||||
this?.buzz() // warning
|
||||
}
|
||||
|
||||
fun A?.test3() {
|
||||
foo() // error
|
||||
<!INAPPLICABLE_CANDIDATE!>bar<!>() // error
|
||||
buzz()
|
||||
|
||||
this.<!INAPPLICABLE_CANDIDATE!>foo<!>() // error
|
||||
this.<!INAPPLICABLE_CANDIDATE!>bar<!>() // error
|
||||
this.buzz()
|
||||
|
||||
this?.foo()
|
||||
this?.bar()
|
||||
this?.buzz()
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
//KT-2457 Verify error when comparing not null value with null in when
|
||||
|
||||
package kt2457
|
||||
|
||||
fun foo(i: Int) : Int =
|
||||
when (i) {
|
||||
1 -> 1
|
||||
null -> 1
|
||||
else -> 1
|
||||
}
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
fun foo(d: Any?) {
|
||||
if (d is String?) {
|
||||
d!!
|
||||
doString(d)
|
||||
}
|
||||
}
|
||||
|
||||
fun doString(s: String) = s
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
fun test(a: Any?) {
|
||||
if (a is String) {
|
||||
a == ""
|
||||
}
|
||||
}
|
||||
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
|
||||
package d
|
||||
|
||||
fun bar() {
|
||||
val i: Int? = 42
|
||||
if (i != null) {
|
||||
<!AMBIGUITY!>doSmth1<!> {
|
||||
val x = i + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun doSmth1(f: ()->Unit) {}
|
||||
fun doSmth1(g: (Int)->Unit) {}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package a
|
||||
|
||||
fun foo() {
|
||||
val i : Int? = 42
|
||||
if (i != null) {
|
||||
<!UNRESOLVED_REFERENCE!>doSmth<!> {
|
||||
val x = i + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
//KT-1270 Poor highlighting when trying to dereference a nullable reference
|
||||
|
||||
package kt1270
|
||||
|
||||
fun foo() {
|
||||
val sc = <!UNRESOLVED_REFERENCE!>java.util.<!UNRESOLVED_REFERENCE!>HashMap<!><String, SomeClass>()[""]<!>
|
||||
val value = sc.<!UNRESOLVED_REFERENCE!>value<!>
|
||||
}
|
||||
|
||||
private class SomeClass() {
|
||||
val value : Int = 5
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
//KT-1680 Warn if non-null variable is compared to null
|
||||
package kt1680
|
||||
|
||||
fun foo() {
|
||||
val x = 1
|
||||
if (x != null) {} // <-- need a warning here!
|
||||
if (x == null) {}
|
||||
if (null != x) {}
|
||||
if (null == x) {}
|
||||
|
||||
val y : Int? = 1
|
||||
if (y != null) {}
|
||||
if (y == null) {}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// !CHECK_TYPE
|
||||
//KT-1778 Automatically cast error
|
||||
package kt1778
|
||||
|
||||
fun main(args : Array<String>) {
|
||||
val x = checkSubtype<Any>(args[0])
|
||||
if(x is java.lang.CharSequence) {
|
||||
if ("a" == x) x.<!UNRESOLVED_REFERENCE!>length<!> else x.length() // OK
|
||||
if ("a" == x || "b" == x) x.<!UNRESOLVED_REFERENCE!>length<!> else x.length() // <– THEN ERROR
|
||||
if ("a" == x && "a" == x) x.<!UNRESOLVED_REFERENCE!>length<!> else x.length() // <– ELSE ERROR
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
//KT-2109 Nullability inference fails in extension function
|
||||
package kt2109
|
||||
|
||||
class A {
|
||||
fun foo() {}
|
||||
}
|
||||
|
||||
fun A?.bar() {
|
||||
if (this == null) {
|
||||
return
|
||||
}
|
||||
foo()
|
||||
}
|
||||
|
||||
fun A.baz() {
|
||||
if (this == null) {
|
||||
return
|
||||
}
|
||||
foo()
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
//KT-2125 Inconsistent error message on UNSAFE_CALL
|
||||
|
||||
package e
|
||||
|
||||
fun main() {
|
||||
val compareTo = 1
|
||||
val s: String? = null
|
||||
s.<!INAPPLICABLE_CANDIDATE!>compareTo<!>("")
|
||||
|
||||
val bar = 2
|
||||
s.<!UNRESOLVED_REFERENCE!>bar<!>()
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
//KT-2146 Nullability casts in when.
|
||||
package kt2146
|
||||
|
||||
fun f1(s: Int?): Int {
|
||||
return when (s) {
|
||||
null -> 3
|
||||
else -> s
|
||||
}
|
||||
}
|
||||
|
||||
fun f2(s: Int?): Int {
|
||||
return when (s) {
|
||||
!is Int -> s
|
||||
else -> s
|
||||
}
|
||||
}
|
||||
|
||||
fun f3(s: Int?): Int {
|
||||
return when (s) {
|
||||
is Int -> s
|
||||
else -> s
|
||||
}
|
||||
}
|
||||
|
||||
fun f4(s: Int?): Int {
|
||||
return when {
|
||||
s == 4 -> s
|
||||
s == null -> s
|
||||
else -> s
|
||||
}
|
||||
}
|
||||
|
||||
fun f5(s: Int?): Int {
|
||||
return when (s) {
|
||||
s -> s
|
||||
s!! -> s
|
||||
s -> s
|
||||
else -> 0
|
||||
}
|
||||
}
|
||||
|
||||
fun f6(s: Int?): Int {
|
||||
return when {
|
||||
s is Int -> s
|
||||
else -> s
|
||||
}
|
||||
}
|
||||
|
||||
fun f7(s: Int?): Int {
|
||||
return when {
|
||||
s !is Int -> s
|
||||
else -> s
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
//KT-2164 !! does not propagate nullability information
|
||||
package kt2164
|
||||
|
||||
fun foo(x: Int): Int = x + 1
|
||||
|
||||
fun main() {
|
||||
val x: Int? = null
|
||||
|
||||
foo(x)
|
||||
|
||||
if (x != null) {
|
||||
foo(x)
|
||||
foo(x!!)
|
||||
foo(x)
|
||||
}
|
||||
|
||||
foo(x)
|
||||
|
||||
if (x != null) {
|
||||
foo(x)
|
||||
foo(x!!)
|
||||
foo(x)
|
||||
} else {
|
||||
foo(x)
|
||||
foo(x!!)
|
||||
foo(x)
|
||||
}
|
||||
|
||||
foo(x)
|
||||
foo(x!!)
|
||||
foo(x)
|
||||
|
||||
val y: Int? = null
|
||||
y!!
|
||||
y!!
|
||||
foo(y)
|
||||
foo(y!!)
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
//KT-2176 non-nullability is not inferred after !! or "as"
|
||||
package kt2176
|
||||
|
||||
fun f1(a: String?) {
|
||||
a!!
|
||||
checkSubtype<String>(a)
|
||||
}
|
||||
|
||||
fun f2(a: String) {
|
||||
a!!
|
||||
checkSubtype<String>(a)
|
||||
}
|
||||
|
||||
fun f3(a: Any?) {
|
||||
a as String
|
||||
checkSubtype<String>(a)
|
||||
}
|
||||
|
||||
fun f4(a: Any) {
|
||||
a as String
|
||||
checkSubtype<String>(a)
|
||||
}
|
||||
|
||||
fun f5(a: String) {
|
||||
a as Any?
|
||||
checkSubtype<String>(a)
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
//KT-2195 error "Only safe calls are allowed ..." but it is function param (val)
|
||||
package foo
|
||||
|
||||
private fun <T> sendCommand(errorCallback: (()->Unit)? = null) {
|
||||
if (errorCallback != null) {
|
||||
errorCallback()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
//KT-2212 Incomplete nullability information
|
||||
package kt2212
|
||||
|
||||
fun main() {
|
||||
val x: Int? = 1
|
||||
if (x == null) return
|
||||
System.out.println(x.plus(x!!))
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !DIAGNOSTICS: -DEBUG_INFO_SMARTCAST
|
||||
//KT-2216 Nullability of a value determined in function parameter computation doesn't pass to code following
|
||||
package kt2216
|
||||
|
||||
fun bar(y: Int, z: Int) = y + z
|
||||
fun baz(a: Int, b: Int, c: Int, d: Int) = a + b + c + d
|
||||
|
||||
fun foo() {
|
||||
val x: Int? = 0
|
||||
|
||||
bar(if (x != null) x else return, x)
|
||||
x + 2
|
||||
bar(x, x!!)
|
||||
|
||||
val y: Int? = 0
|
||||
val z: Int? = 0
|
||||
bar(if (y != null) y else z, y)
|
||||
y <!INAPPLICABLE_CANDIDATE!>+<!> 2
|
||||
baz(y, y, if (y == null) return else y, y)
|
||||
baz(y, z!!, z, y)
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
//KT-2223 Comparing non-null value with null might produce helpful warning
|
||||
package kt2223
|
||||
|
||||
fun foo() {
|
||||
val x: Int? = null
|
||||
if (x == null) return
|
||||
if (x == null) return
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
package a
|
||||
|
||||
//KT-2234 'period!!' has type Int?
|
||||
|
||||
class Pair<A, B>(val a: A, val b: B)
|
||||
|
||||
fun main() {
|
||||
val d : Long = 1
|
||||
val period : Int? = null
|
||||
if (period != null) Pair(d, checkSubtype<Int>(period!!)) else Pair(d, 1)
|
||||
if (period != null) Pair(d, checkSubtype<Int>(period)) else Pair(d, 1)
|
||||
}
|
||||
|
||||
fun foo() {
|
||||
val x : Int? = 3
|
||||
if (x != null) {
|
||||
val u = checkSubtype<Int>(x!!)
|
||||
val y = checkSubtype<Int>(x)
|
||||
val z : Int = y
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fun main() {
|
||||
val b: Boolean? = null
|
||||
if (b != null) {
|
||||
if (!b) {} // OK
|
||||
if (b) {} // Error: Condition must be of type kotlin.Boolean, but is of type kotlin.Boolean?
|
||||
if (b!!) {} // WARN: Unnecessary non-null assertion (!!) on a non-null receiver of type kotlin.Boolean?
|
||||
foo(b) // OK
|
||||
}
|
||||
}
|
||||
|
||||
fun foo(a: Boolean) = a
|
||||
@@ -0,0 +1,33 @@
|
||||
package kt244
|
||||
|
||||
|
||||
// KT-244 Use dataflow info while resolving variable initializers
|
||||
|
||||
fun f(s: String?) {
|
||||
if (s != null) {
|
||||
s.length //ok
|
||||
var i = s.length //error: Only safe calls are allowed on a nullable receiver
|
||||
System.out.println(s.length) //error
|
||||
}
|
||||
}
|
||||
|
||||
// more tests
|
||||
class A(a: String?) {
|
||||
val b = if (a != null) a.length else 1
|
||||
init {
|
||||
if (a != null) {
|
||||
val c = a.length
|
||||
}
|
||||
}
|
||||
|
||||
val i : Int
|
||||
|
||||
init {
|
||||
if (a is String) {
|
||||
i = a.length
|
||||
}
|
||||
else {
|
||||
i = 3
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !LANGUAGE: +NewInference
|
||||
// Issue: KT-30734
|
||||
|
||||
class Sample {
|
||||
fun foo(): Boolean = true
|
||||
}
|
||||
|
||||
fun test(ls: Sample?) {
|
||||
val filter: () -> Boolean = if (ls == null) {
|
||||
{ false }
|
||||
} else {
|
||||
{ ls.foo() } // OK in OI, error in NI
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// FILE: this.kt
|
||||
|
||||
// KT-362 Don't allow.smartcasts on vals that are not internal
|
||||
package example
|
||||
|
||||
fun test() {
|
||||
val p = test.Public()
|
||||
if (p.public is Int) p.public + 1
|
||||
if (p.<!INAPPLICABLE_CANDIDATE!>protected<!> is Int) p.<!INAPPLICABLE_CANDIDATE!>protected<!> + 1
|
||||
if (p.internal is Int) p.internal + 1
|
||||
val i = test.Internal()
|
||||
if (i.public is Int) i.public + 1
|
||||
if (i.<!INAPPLICABLE_CANDIDATE!>protected<!> is Int) i.<!INAPPLICABLE_CANDIDATE!>protected<!> + 1
|
||||
if (i.internal is Int) i.internal + 1
|
||||
}
|
||||
|
||||
// FILE: other.kt
|
||||
package test
|
||||
|
||||
public class Public() {
|
||||
public val public : Int? = 1;
|
||||
protected val protected : Int? = 1;
|
||||
val internal : Int? = 1
|
||||
}
|
||||
internal class Internal() {
|
||||
public val public : Int? = 1;
|
||||
protected val protected : Int? = 1;
|
||||
val internal : Int? = 1
|
||||
}
|
||||
Vendored
+21
@@ -0,0 +1,21 @@
|
||||
// FILE: A.java
|
||||
|
||||
class A {
|
||||
enum Empty {}
|
||||
|
||||
static Empty foo() { return null; }
|
||||
}
|
||||
|
||||
// FILE: 1.kt
|
||||
|
||||
fun bar() = when (A.foo()) {
|
||||
null -> "null"
|
||||
else -> "else"
|
||||
}
|
||||
|
||||
fun <T : Number?> baz(t: T) = when (t) {
|
||||
is Int -> "int"
|
||||
is Long -> "long"
|
||||
null -> "null"
|
||||
else -> "else"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package a
|
||||
|
||||
fun foo() {
|
||||
bar()!!
|
||||
}
|
||||
|
||||
fun bar() = <!UNRESOLVED_REFERENCE!>aa<!>
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// FILE: JClass.java
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class JClass {
|
||||
@NotNull
|
||||
public static <T> T getNotNullT() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
fun <T : Any> test() {
|
||||
var value: T? = null
|
||||
if (value == null) {
|
||||
value = JClass.getNotNullT()
|
||||
}
|
||||
|
||||
value.<!INAPPLICABLE_CANDIDATE!>hashCode<!>() // unsafe call error
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
class A {
|
||||
fun f(x: Boolean): Int = 0
|
||||
|
||||
fun f(y: String): Int = 0
|
||||
}
|
||||
|
||||
class B {
|
||||
private var a: A? = null
|
||||
|
||||
fun takeInt(i: Int) {}
|
||||
|
||||
fun f() {
|
||||
a = A()
|
||||
a.f(true)
|
||||
takeInt(a.f(""))
|
||||
a.<!INAPPLICABLE_CANDIDATE!>f<!>()
|
||||
}
|
||||
|
||||
fun g() {
|
||||
takeInt(if (3 > 2) {
|
||||
a = A()
|
||||
a.f(true)
|
||||
} else {
|
||||
6
|
||||
})
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// The type checker used to think that T is not null no matter what the upper bound
|
||||
|
||||
fun <T, INDIRECT: T> nullableUpperBound(t: T, ind: INDIRECT) {
|
||||
if (t == null) {} // was a warning
|
||||
if (t != null) {} // was a warning
|
||||
if (ind == null) {} // was a warning
|
||||
if (ind != null) {} // was a warning
|
||||
}
|
||||
|
||||
fun <T: Any, INDIRECT: T> notNullUpperBound(t: T, ind: INDIRECT) {
|
||||
if (t == null) {} // still a warning
|
||||
if (t != null) {} // still a warning
|
||||
if (ind == null) {} // still a warning
|
||||
if (ind != null) {} // still a warning
|
||||
}
|
||||
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
fun test(a: Any?) {
|
||||
if (a != null) {
|
||||
a.foo(11)
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> Any.foo(t: T) = t
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
fun foo(b: Boolean?, c: Boolean) {
|
||||
if (b != null && b) {}
|
||||
if (b == null || b) {}
|
||||
if (b != null) {
|
||||
if (b && c) {}
|
||||
if (b || c) {}
|
||||
}
|
||||
}
|
||||
Vendored
+24
@@ -0,0 +1,24 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER, -SENSELESS_COMPARISON, -DEBUG_INFO_SMARTCAST
|
||||
|
||||
fun takeNotNull(s: String) {}
|
||||
fun <T> notNull(): T = TODO()
|
||||
fun <T> nullable(): T? = null
|
||||
fun <T> dependOn(x: T) = x
|
||||
|
||||
fun test() {
|
||||
takeNotNull(notNull()!!)
|
||||
takeNotNull(nullable()!!)
|
||||
|
||||
var x: String? = null
|
||||
takeNotNull(dependOn(x)!!)
|
||||
takeNotNull(dependOn(dependOn(x))!!)
|
||||
takeNotNull(dependOn(dependOn(x)!!))
|
||||
takeNotNull(dependOn(dependOn(x!!)))
|
||||
|
||||
if (x != null) {
|
||||
takeNotNull(dependOn(x)!!)
|
||||
takeNotNull(dependOn(dependOn(x))!!)
|
||||
takeNotNull(dependOn(dependOn(x)!!))
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
interface Ctx
|
||||
class CtxImpl : Ctx {
|
||||
fun doJob(a: Int) {}
|
||||
fun doJob(s: String) {}
|
||||
}
|
||||
|
||||
open class Test(open val ctx: Ctx) {
|
||||
fun test() {
|
||||
when (ctx) {
|
||||
is CtxImpl -> ctx.doJob(2)
|
||||
}
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
class A
|
||||
class B
|
||||
|
||||
fun A.foo(a: A) {}
|
||||
fun A.foo(b: B) {}
|
||||
var a: A? = null
|
||||
|
||||
fun smartCastInterference(b: B) {
|
||||
if (a != null) {
|
||||
a.foo(b)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user