Rename: auto cast -> smart cast
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
fun main(args : Array<String>) {
|
||||
val a : Int? = null
|
||||
val b : Int? = null
|
||||
a!! : Int
|
||||
a<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!> + 2
|
||||
a<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.plus(2)
|
||||
a<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.plus(b!!)
|
||||
2.plus(b<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>)
|
||||
2 + b<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
|
||||
|
||||
val c = 1
|
||||
c<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
|
||||
|
||||
val d : Any? = null
|
||||
|
||||
if (d != null) {
|
||||
d<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
|
||||
}
|
||||
|
||||
// smart cast isn't needed, but is reported due to KT-4294
|
||||
if (d is String) {
|
||||
<!DEBUG_INFO_SMARTCAST!>d<!><!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
|
||||
}
|
||||
|
||||
if (d is String?) {
|
||||
if (d != null) {
|
||||
<!DEBUG_INFO_SMARTCAST!>d<!><!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
|
||||
}
|
||||
if (d is String) {
|
||||
<!DEBUG_INFO_SMARTCAST!>d<!><!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
|
||||
}
|
||||
}
|
||||
|
||||
val <!UNUSED_VARIABLE!>f<!> : String = <!TYPE_MISMATCH!>a<!><!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
|
||||
<!TYPE_MISMATCH!>a<!><!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!> : String
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package
|
||||
|
||||
internal fun main(/*0*/ args: kotlin.Array<kotlin.String>): kotlin.Unit
|
||||
@@ -0,0 +1,41 @@
|
||||
class A() {
|
||||
fun plus(<!UNUSED_PARAMETER!>i<!> : Int) {}
|
||||
fun minus() {}
|
||||
fun contains(<!UNUSED_PARAMETER!>a<!> : Any?) : Boolean = true
|
||||
}
|
||||
|
||||
fun A.div(<!UNUSED_PARAMETER!>i<!> : Int) {}
|
||||
fun A?.times(<!UNUSED_PARAMETER!>i<!> : Int) {}
|
||||
|
||||
fun test(x : Int?, a : A?) {
|
||||
x<!UNSAFE_CALL!>.<!>plus(1)
|
||||
x?.plus(1)
|
||||
x <!UNSAFE_INFIX_CALL!>plus<!> 1
|
||||
x <!UNSAFE_INFIX_CALL!>+<!> 1
|
||||
<!UNSAFE_CALL!>-<!>x
|
||||
x<!UNSAFE_CALL!>.<!>minus()
|
||||
x?.minus()
|
||||
|
||||
a<!UNSAFE_CALL!>.<!>plus(1)
|
||||
a?.plus(1)
|
||||
a <!UNSAFE_INFIX_CALL!>plus<!> 1
|
||||
a <!UNSAFE_INFIX_CALL!>+<!> 1
|
||||
<!UNSAFE_CALL!>-<!>a
|
||||
a<!UNSAFE_CALL!>.<!>minus()
|
||||
a?.minus()
|
||||
|
||||
a<!UNSAFE_CALL!>.<!>div(1)
|
||||
a <!UNSAFE_INFIX_CALL!>/<!> 1
|
||||
a <!UNSAFE_INFIX_CALL!>div<!> 1
|
||||
a?.div(1)
|
||||
|
||||
a.times(1)
|
||||
a * 1
|
||||
a times 1
|
||||
a?.times(1)
|
||||
|
||||
1 <!UNSAFE_INFIX_CALL!>in<!> a
|
||||
a <!UNSAFE_INFIX_CALL!>contains<!> 1
|
||||
a<!UNSAFE_CALL!>.<!>contains(1)
|
||||
a?.contains(1)
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package
|
||||
|
||||
internal fun test(/*0*/ x: kotlin.Int?, /*1*/ a: A?): kotlin.Unit
|
||||
internal fun A.div(/*0*/ i: kotlin.Int): kotlin.Unit
|
||||
internal fun A?.times(/*0*/ i: kotlin.Int): kotlin.Unit
|
||||
|
||||
internal final class A {
|
||||
public constructor A()
|
||||
internal final fun contains(/*0*/ a: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
internal final fun minus(): kotlin.Unit
|
||||
internal final fun plus(/*0*/ i: kotlin.Int): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
fun test() {
|
||||
val out : Int? = null
|
||||
val x : Nothing? = null
|
||||
if (out != x)
|
||||
<!DEBUG_INFO_SMARTCAST!>out<!>.plus(1)
|
||||
if (out == x) return
|
||||
<!DEBUG_INFO_SMARTCAST!>out<!>.plus(1)
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
package
|
||||
|
||||
internal fun test(): kotlin.Unit
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
class Foo {
|
||||
fun foo() {}
|
||||
}
|
||||
|
||||
fun Any?.foo() {}
|
||||
|
||||
fun test(f : Foo?) {
|
||||
f.foo()
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package
|
||||
|
||||
internal fun test(/*0*/ f: Foo?): kotlin.Unit
|
||||
internal fun kotlin.Any?.foo(): kotlin.Unit
|
||||
|
||||
internal final class Foo {
|
||||
public constructor Foo()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
internal final fun foo(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
// !DIAGNOSTICS: -DEBUG_INFO_SMARTCAST
|
||||
class Foo {
|
||||
fun foo(a: Foo): Foo = a
|
||||
}
|
||||
|
||||
fun main(args : Array<String>) {
|
||||
val x: Foo? = null
|
||||
val y: Foo? = null
|
||||
|
||||
x<!UNSAFE_CALL!>.<!>foo(<!TYPE_MISMATCH!>y<!>)
|
||||
x!!.foo(<!TYPE_MISMATCH!>y<!>)
|
||||
x.foo(y!!)
|
||||
x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.foo(y<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>)
|
||||
|
||||
val a: Foo? = null
|
||||
val b: Foo? = null
|
||||
val c: Foo? = null
|
||||
|
||||
a<!UNSAFE_CALL!>.<!>foo(b<!UNSAFE_CALL!>.<!>foo(<!TYPE_MISMATCH!>c<!>))
|
||||
a!!.foo(b<!UNSAFE_CALL!>.<!>foo(<!TYPE_MISMATCH!>c<!>))
|
||||
a.foo(b!!.foo(<!TYPE_MISMATCH!>c<!>))
|
||||
a<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.foo(b<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.foo(<!TYPE_MISMATCH!>c<!>))
|
||||
a.foo(b.foo(c!!))
|
||||
a<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.foo(b.foo(c<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>))
|
||||
a.foo(b<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.foo(c<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>))
|
||||
a<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.foo(b<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.foo(c<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>))
|
||||
|
||||
val z: Foo? = null
|
||||
z!!.foo(z<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>)
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package
|
||||
|
||||
internal fun main(/*0*/ args: kotlin.Array<kotlin.String>): kotlin.Unit
|
||||
|
||||
internal final class Foo {
|
||||
public constructor Foo()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
internal final fun foo(/*0*/ a: Foo): Foo
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
class A {
|
||||
fun foo() {}
|
||||
}
|
||||
|
||||
fun A.bar() {}
|
||||
fun A?.buzz() {}
|
||||
|
||||
fun test(a : A?) {
|
||||
a<!UNSAFE_CALL!>.<!>foo() // error
|
||||
a<!UNSAFE_CALL!>.<!>bar() // error
|
||||
a.buzz()
|
||||
|
||||
a?.foo()
|
||||
a?.bar()
|
||||
a?.buzz()
|
||||
}
|
||||
|
||||
fun A.test2() {
|
||||
foo()
|
||||
bar()
|
||||
buzz()
|
||||
|
||||
this.foo()
|
||||
this.bar()
|
||||
this.buzz()
|
||||
|
||||
this<!UNNECESSARY_SAFE_CALL!>?.<!>foo() // warning
|
||||
this<!UNNECESSARY_SAFE_CALL!>?.<!>bar() // warning
|
||||
this<!UNNECESSARY_SAFE_CALL!>?.<!>buzz() // warning
|
||||
}
|
||||
|
||||
fun A?.test3() {
|
||||
<!UNSAFE_CALL!>foo<!>() // error
|
||||
<!UNSAFE_CALL!>bar<!>() // error
|
||||
buzz()
|
||||
|
||||
this<!UNSAFE_CALL!>.<!>foo() // error
|
||||
this<!UNSAFE_CALL!>.<!>bar() // error
|
||||
this.buzz()
|
||||
|
||||
this?.foo()
|
||||
this?.bar()
|
||||
this?.buzz()
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package
|
||||
|
||||
internal fun test(/*0*/ a: A?): kotlin.Unit
|
||||
internal fun A.bar(): kotlin.Unit
|
||||
internal fun A?.buzz(): kotlin.Unit
|
||||
internal fun A.test2(): kotlin.Unit
|
||||
internal fun A?.test3(): kotlin.Unit
|
||||
|
||||
internal final class A {
|
||||
public constructor A()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
internal final fun foo(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
@@ -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
|
||||
<!SENSELESS_NULL_IN_WHEN!>null<!> -> 1
|
||||
else -> 1
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package
|
||||
|
||||
package kt2457 {
|
||||
internal fun foo(/*0*/ i: kotlin.Int): kotlin.Int
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
fun foo(d: Any?) {
|
||||
if (d is String?) {
|
||||
<!DEBUG_INFO_SMARTCAST!>d<!>!!
|
||||
doString(<!DEBUG_INFO_SMARTCAST!>d<!>)
|
||||
}
|
||||
}
|
||||
|
||||
fun doString(s: String) = s
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package
|
||||
|
||||
internal fun doString(/*0*/ s: kotlin.String): kotlin.String
|
||||
internal fun foo(/*0*/ d: kotlin.Any?): kotlin.Unit
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
fun test(a: Any?) {
|
||||
if (a is String) {
|
||||
a == ""
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
package
|
||||
|
||||
internal fun test(/*0*/ a: kotlin.Any?): kotlin.Unit
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
|
||||
package d
|
||||
|
||||
fun bar() {
|
||||
val i: Int? = 42
|
||||
if (i != null) {
|
||||
<!OVERLOAD_RESOLUTION_AMBIGUITY!>doSmth1<!> {
|
||||
val x = <!DEBUG_INFO_SMARTCAST!>i<!> + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun doSmth1(f: ()->Unit) {}
|
||||
fun doSmth1(g: (Int)->Unit) {}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package
|
||||
|
||||
package d {
|
||||
internal fun bar(): kotlin.Unit
|
||||
internal fun doSmth1(/*0*/ f: () -> kotlin.Unit): kotlin.Unit
|
||||
internal fun doSmth1(/*0*/ g: (kotlin.Int) -> kotlin.Unit): kotlin.Unit
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package a
|
||||
|
||||
fun foo() {
|
||||
val i : Int? = 42
|
||||
if (i != null) {
|
||||
<!UNRESOLVED_REFERENCE!>doSmth<!> {
|
||||
val <!UNUSED_VARIABLE!>x<!> = <!DEBUG_INFO_SMARTCAST!>i<!> + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package
|
||||
|
||||
package a {
|
||||
internal fun foo(): kotlin.Unit
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
//KT-1270 Poor highlighting when trying to dereference a nullable reference
|
||||
|
||||
package kt1270
|
||||
|
||||
fun foo() {
|
||||
val sc = java.util.HashMap<String, SomeClass>()[""]
|
||||
val <!UNUSED_VARIABLE!>value<!> = sc<!UNSAFE_CALL!>.<!>value
|
||||
}
|
||||
|
||||
private class SomeClass() {
|
||||
val value : Int = 5
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package
|
||||
|
||||
package kt1270 {
|
||||
internal fun foo(): kotlin.Unit
|
||||
|
||||
private final class SomeClass {
|
||||
public constructor SomeClass()
|
||||
internal final val value: kotlin.Int = 5
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
//KT-1680 Warn if non-null variable is compared to null
|
||||
package kt1680
|
||||
|
||||
fun foo() {
|
||||
val x = 1
|
||||
if (<!SENSELESS_COMPARISON!>x != null<!>) {} // <-- need a warning here!
|
||||
if (<!SENSELESS_COMPARISON!>x == null<!>) {}
|
||||
if (<!SENSELESS_COMPARISON!>null != x<!>) {}
|
||||
if (<!SENSELESS_COMPARISON!>null == x<!>) {}
|
||||
|
||||
val y : Int? = 1
|
||||
if (y != null) {}
|
||||
if (y == null) {}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package
|
||||
|
||||
package kt1680 {
|
||||
internal fun foo(): kotlin.Unit
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
//KT-1778 Automatically cast error
|
||||
package kt1778
|
||||
|
||||
fun main(args : Array<String>) {
|
||||
val x = args[0]: Any
|
||||
if(x is <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>java.lang.CharSequence<!>) {
|
||||
if ("a" == x) <!DEBUG_INFO_SMARTCAST!>x<!>.length() else <!DEBUG_INFO_SMARTCAST!>x<!>.length() // OK
|
||||
if ("a" == x || "b" == x) <!DEBUG_INFO_SMARTCAST!>x<!>.length() else <!DEBUG_INFO_SMARTCAST!>x<!>.length() // <– THEN ERROR
|
||||
if ("a" == x && "a" == x) <!DEBUG_INFO_SMARTCAST!>x<!>.length() else <!DEBUG_INFO_SMARTCAST!>x<!>.length() // <– ELSE ERROR
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package
|
||||
|
||||
package kt1778 {
|
||||
internal fun main(/*0*/ args: kotlin.Array<kotlin.String>): kotlin.Unit
|
||||
}
|
||||
@@ -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 (<!SENSELESS_COMPARISON!>this == null<!>) {
|
||||
return
|
||||
}
|
||||
foo()
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package
|
||||
|
||||
package kt2109 {
|
||||
internal fun kt2109.A?.bar(): kotlin.Unit
|
||||
internal fun kt2109.A.baz(): kotlin.Unit
|
||||
|
||||
internal final class A {
|
||||
public constructor A()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
internal final fun foo(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
//KT-2125 Inconsistent error message on UNSAFE_CALL
|
||||
|
||||
package e
|
||||
|
||||
fun main() {
|
||||
val <!UNUSED_VARIABLE!>compareTo<!> = 1
|
||||
val s: String? = null
|
||||
s<!UNSAFE_CALL!>.<!>compareTo("")
|
||||
|
||||
val <!UNUSED_VARIABLE!>bar<!> = 2
|
||||
s.<!UNRESOLVED_REFERENCE!>bar<!>()
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package
|
||||
|
||||
package e {
|
||||
internal fun main(): kotlin.Unit
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
//KT-2146 Nullability casts in when.
|
||||
package kt2146
|
||||
|
||||
fun f1(s: Int?): Int {
|
||||
return when (s) {
|
||||
null -> 3
|
||||
else -> <!DEBUG_INFO_SMARTCAST!>s<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun f2(s: Int?): Int {
|
||||
return when (s) {
|
||||
!is Int -> <!TYPE_MISMATCH!>s<!>
|
||||
else -> <!DEBUG_INFO_SMARTCAST!>s<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun f3(s: Int?): Int {
|
||||
return when (s) {
|
||||
is Int -> <!DEBUG_INFO_SMARTCAST!>s<!>
|
||||
else -> <!TYPE_MISMATCH!>s<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun f4(s: Int?): Int {
|
||||
return when {
|
||||
s == 4 -> <!DEBUG_INFO_SMARTCAST!>s<!>
|
||||
s == null -> <!TYPE_MISMATCH!>s<!>
|
||||
else -> <!DEBUG_INFO_SMARTCAST!>s<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun f5(s: Int?): Int {
|
||||
return when (s) {
|
||||
s -> <!TYPE_MISMATCH!>s<!>
|
||||
s!! -> <!DEBUG_INFO_SMARTCAST!>s<!>
|
||||
s -> <!DEBUG_INFO_SMARTCAST!>s<!>
|
||||
else -> 0
|
||||
}
|
||||
}
|
||||
|
||||
fun f6(s: Int?): Int {
|
||||
return when {
|
||||
s is Int -> <!DEBUG_INFO_SMARTCAST!>s<!>
|
||||
else -> <!TYPE_MISMATCH!>s<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun f7(s: Int?): Int {
|
||||
return when {
|
||||
s !is Int -> <!TYPE_MISMATCH!>s<!>
|
||||
else -> <!DEBUG_INFO_SMARTCAST!>s<!>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package
|
||||
|
||||
package kt2146 {
|
||||
internal fun f1(/*0*/ s: kotlin.Int?): kotlin.Int
|
||||
internal fun f2(/*0*/ s: kotlin.Int?): kotlin.Int
|
||||
internal fun f3(/*0*/ s: kotlin.Int?): kotlin.Int
|
||||
internal fun f4(/*0*/ s: kotlin.Int?): kotlin.Int
|
||||
internal fun f5(/*0*/ s: kotlin.Int?): kotlin.Int
|
||||
internal fun f6(/*0*/ s: kotlin.Int?): kotlin.Int
|
||||
internal fun f7(/*0*/ s: kotlin.Int?): kotlin.Int
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
//KT-2164 !! does not propagate nullability information
|
||||
package kt2164
|
||||
|
||||
fun foo(x: Int): Int = x + 1
|
||||
|
||||
fun main(args : Array<String>) {
|
||||
val x: Int? = null
|
||||
|
||||
foo(<!TYPE_MISMATCH!>x<!>)
|
||||
|
||||
if (x != null) {
|
||||
foo(<!DEBUG_INFO_SMARTCAST!>x<!>)
|
||||
foo(x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>)
|
||||
foo(<!DEBUG_INFO_SMARTCAST!>x<!>)
|
||||
}
|
||||
|
||||
foo(<!TYPE_MISMATCH!>x<!>)
|
||||
|
||||
if (x != null) {
|
||||
foo(<!DEBUG_INFO_SMARTCAST!>x<!>)
|
||||
foo(x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>)
|
||||
foo(<!DEBUG_INFO_SMARTCAST!>x<!>)
|
||||
} else {
|
||||
foo(<!TYPE_MISMATCH!>x<!>)
|
||||
foo(x!!)
|
||||
foo(<!DEBUG_INFO_SMARTCAST!>x<!>)
|
||||
}
|
||||
|
||||
foo(<!DEBUG_INFO_SMARTCAST!>x<!>)
|
||||
foo(x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>)
|
||||
foo(<!DEBUG_INFO_SMARTCAST!>x<!>)
|
||||
|
||||
val y: Int? = null
|
||||
y!!
|
||||
y<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
|
||||
foo(<!DEBUG_INFO_SMARTCAST!>y<!>)
|
||||
foo(y<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>)
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package
|
||||
|
||||
package kt2164 {
|
||||
internal fun foo(/*0*/ x: kotlin.Int): kotlin.Int
|
||||
internal fun main(/*0*/ args: kotlin.Array<kotlin.String>): kotlin.Unit
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
//KT-2176 non-nullability is not inferred after !! or "as"
|
||||
package kt2176
|
||||
|
||||
fun f1(a: String?) {
|
||||
a!!
|
||||
<!DEBUG_INFO_SMARTCAST!>a<!>: String
|
||||
}
|
||||
|
||||
fun f2(a: String) {
|
||||
a<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
|
||||
a: String
|
||||
}
|
||||
|
||||
fun f3(a: Any?) {
|
||||
a as String
|
||||
<!DEBUG_INFO_SMARTCAST!>a<!>: String
|
||||
}
|
||||
|
||||
fun f4(a: Any) {
|
||||
a as String
|
||||
<!DEBUG_INFO_SMARTCAST!>a<!>: String
|
||||
}
|
||||
|
||||
fun f5(a: String) {
|
||||
a <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as<!> Any?
|
||||
a: String
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package
|
||||
|
||||
package kt2176 {
|
||||
internal fun f1(/*0*/ a: kotlin.String?): kotlin.Unit
|
||||
internal fun f2(/*0*/ a: kotlin.String): kotlin.Unit
|
||||
internal fun f3(/*0*/ a: kotlin.Any?): kotlin.Unit
|
||||
internal fun f4(/*0*/ a: kotlin.Any): kotlin.Unit
|
||||
internal fun f5(/*0*/ a: kotlin.String): kotlin.Unit
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
//KT-2195 error "Only safe calls are allowed ..." but it is function param (val)
|
||||
package foo
|
||||
|
||||
private fun sendCommand<T>(errorCallback: (()->Unit)? = null) {
|
||||
if (errorCallback != null) {
|
||||
<!DEBUG_INFO_SMARTCAST!>errorCallback<!>()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package
|
||||
|
||||
package foo {
|
||||
private fun </*0*/ T> sendCommand(/*0*/ errorCallback: (() -> kotlin.Unit)? = ...): kotlin.Unit
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
//KT-2212 Incomplete nullability information
|
||||
package kt2212
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val x: Int? = 1
|
||||
if (x == null) return
|
||||
System.out.println(<!DEBUG_INFO_SMARTCAST!>x<!>.plus(x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>))
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package
|
||||
|
||||
package kt2212 {
|
||||
internal fun main(/*0*/ args: kotlin.Array<kotlin.String>): kotlin.Unit
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// !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<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>)
|
||||
|
||||
val y: Int? = 0
|
||||
val z: Int? = 0
|
||||
bar(if (y != null) y else <!TYPE_MISMATCH!>z<!>, <!TYPE_MISMATCH!>y<!>)
|
||||
y <!UNSAFE_INFIX_CALL!>+<!> 2
|
||||
baz(<!TYPE_MISMATCH!>y<!>, <!TYPE_MISMATCH!>y<!>, if (y == null) return else y, y)
|
||||
baz(y, z!!, z, y)
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package
|
||||
|
||||
package kt2216 {
|
||||
internal fun bar(/*0*/ y: kotlin.Int, /*1*/ z: kotlin.Int): kotlin.Int
|
||||
internal fun baz(/*0*/ a: kotlin.Int, /*1*/ b: kotlin.Int, /*2*/ c: kotlin.Int, /*3*/ d: kotlin.Int): kotlin.Int
|
||||
internal fun foo(): kotlin.Unit
|
||||
}
|
||||
@@ -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 (<!SENSELESS_COMPARISON!>x == null<!>) return
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package
|
||||
|
||||
package kt2223 {
|
||||
internal fun foo(): kotlin.Unit
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package a
|
||||
|
||||
//KT-2234 'period!!' has type Int?
|
||||
|
||||
class Pair<A, B>(val a: A, val b: B)
|
||||
|
||||
fun main(args : Array<String>) {
|
||||
val d : Long = 1
|
||||
val period : Int? = null
|
||||
if (period != null) Pair(d, period<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!> : Int) else Pair(d, 1)
|
||||
if (period != null) Pair(d, <!DEBUG_INFO_SMARTCAST!>period<!> : Int) else Pair(d, 1)
|
||||
}
|
||||
|
||||
fun foo() {
|
||||
val x : Int? = 3
|
||||
if (x != null) {
|
||||
val <!UNUSED_VARIABLE!>u<!> = x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!> : Int
|
||||
val y = <!DEBUG_INFO_SMARTCAST!>x<!> : Int
|
||||
val <!UNUSED_VARIABLE!>z<!> : Int = y
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package
|
||||
|
||||
package a {
|
||||
internal fun foo(): kotlin.Unit
|
||||
internal fun main(/*0*/ args: kotlin.Array<kotlin.String>): kotlin.Unit
|
||||
|
||||
internal final class Pair</*0*/ A, /*1*/ B> {
|
||||
public constructor Pair</*0*/ A, /*1*/ B>(/*0*/ a: A, /*1*/ b: B)
|
||||
internal final val a: A
|
||||
internal final val b: B
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fun main(args: Array<String>) {
|
||||
val b: Boolean? = null
|
||||
if (b != null) {
|
||||
if (!<!DEBUG_INFO_SMARTCAST!>b<!>) {} // OK
|
||||
if (<!DEBUG_INFO_SMARTCAST!>b<!>) {} // Error: Condition must be of type jet.Boolean, but is of type jet.Boolean?
|
||||
if (b<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>) {} // WARN: Unnecessary non-null assertion (!!) on a non-null receiver of type jet.Boolean?
|
||||
foo(<!DEBUG_INFO_SMARTCAST!>b<!>) // OK
|
||||
}
|
||||
}
|
||||
|
||||
fun foo(a: Boolean) = a
|
||||
@@ -0,0 +1,4 @@
|
||||
package
|
||||
|
||||
internal fun foo(/*0*/ a: kotlin.Boolean): kotlin.Boolean
|
||||
internal fun main(/*0*/ args: kotlin.Array<kotlin.String>): kotlin.Unit
|
||||
@@ -0,0 +1,33 @@
|
||||
package kt244
|
||||
|
||||
|
||||
// KT-244 Use dataflow info while resolving variable initializers
|
||||
|
||||
fun f(s: String?) {
|
||||
if (s != null) {
|
||||
<!DEBUG_INFO_SMARTCAST!>s<!>.length //ok
|
||||
var <!UNUSED_VARIABLE!>i<!> = <!DEBUG_INFO_SMARTCAST!>s<!>.length //error: Only safe calls are allowed on a nullable receiver
|
||||
System.out.println(<!DEBUG_INFO_SMARTCAST!>s<!>.length) //error
|
||||
}
|
||||
}
|
||||
|
||||
// more tests
|
||||
class A(a: String?) {
|
||||
val b = if (a != null) <!DEBUG_INFO_SMARTCAST!>a<!>.length else 1
|
||||
{
|
||||
if (a != null) {
|
||||
val <!UNUSED_VARIABLE!>c<!> = <!DEBUG_INFO_SMARTCAST!>a<!>.length
|
||||
}
|
||||
}
|
||||
|
||||
val i : Int
|
||||
|
||||
{
|
||||
if (a is String) {
|
||||
i = <!DEBUG_INFO_SMARTCAST!>a<!>.length
|
||||
}
|
||||
else {
|
||||
i = 3
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package
|
||||
|
||||
package kt244 {
|
||||
internal fun f(/*0*/ s: kotlin.String?): kotlin.Unit
|
||||
|
||||
internal final class A {
|
||||
public constructor A(/*0*/ a: kotlin.String?)
|
||||
internal final val b: kotlin.Int
|
||||
internal final val i: kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
@@ -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) <!SMARTCAST_IMPOSSIBLE!>p.public<!> + 1
|
||||
if (p.<!INVISIBLE_MEMBER!>protected<!> is Int) <!SMARTCAST_IMPOSSIBLE!>p.<!INVISIBLE_MEMBER!>protected<!><!> + 1
|
||||
if (p.internal is Int) <!DEBUG_INFO_SMARTCAST!>p.internal<!> + 1
|
||||
val i = test.Internal()
|
||||
if (i.public is Int) <!DEBUG_INFO_SMARTCAST!>i.public<!> + 1
|
||||
if (i.<!INVISIBLE_MEMBER!>protected<!> is Int) <!DEBUG_INFO_SMARTCAST!>i.<!INVISIBLE_MEMBER!>protected<!><!> + 1
|
||||
if (i.internal is Int) <!DEBUG_INFO_SMARTCAST!>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
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package
|
||||
|
||||
package example {
|
||||
internal fun test(): kotlin.Unit
|
||||
}
|
||||
|
||||
package test {
|
||||
|
||||
internal final class Internal {
|
||||
public constructor Internal()
|
||||
internal final val internal: kotlin.Int? = 1
|
||||
protected final val protected: kotlin.Int? = 1
|
||||
public final val public: kotlin.Int? = 1
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public final class Public {
|
||||
public constructor Public()
|
||||
internal final val internal: kotlin.Int? = 1
|
||||
protected final val protected: kotlin.Int? = 1
|
||||
public final val public: kotlin.Int? = 1
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package a
|
||||
|
||||
fun foo() {
|
||||
bar()!!
|
||||
}
|
||||
|
||||
fun bar() = <!UNRESOLVED_REFERENCE!>aa<!>
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package
|
||||
|
||||
package a {
|
||||
internal fun bar(): [ERROR : Error function type]
|
||||
internal fun foo(): kotlin.Unit
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// The type checker used to think that T is not null no matter what the upper bound
|
||||
|
||||
fun nullableUpperBound<T, INDIRECT: T>(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 notNullUpperBound<T: Any, INDIRECT: T>(t: T, ind: INDIRECT) {
|
||||
if (<!SENSELESS_COMPARISON!>t == null<!>) {} // still a warning
|
||||
if (<!SENSELESS_COMPARISON!>t != null<!>) {} // still a warning
|
||||
if (<!SENSELESS_COMPARISON!>ind == null<!>) {} // still a warning
|
||||
if (<!SENSELESS_COMPARISON!>ind != null<!>) {} // still a warning
|
||||
}
|
||||
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package
|
||||
|
||||
internal fun </*0*/ T : kotlin.Any, /*1*/ INDIRECT : T> notNullUpperBound(/*0*/ t: T, /*1*/ ind: INDIRECT): kotlin.Unit
|
||||
internal fun </*0*/ T, /*1*/ INDIRECT : T> nullableUpperBound(/*0*/ t: T, /*1*/ ind: INDIRECT): kotlin.Unit
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
fun test(a: Any?) {
|
||||
if (a != null) {
|
||||
<!DEBUG_INFO_SMARTCAST!>a<!>.foo(11)
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> Any.foo(t: T) = t
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package
|
||||
|
||||
internal fun test(/*0*/ a: kotlin.Any?): kotlin.Unit
|
||||
internal fun </*0*/ T> kotlin.Any.foo(/*0*/ t: T): T
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
fun foo(b: Boolean?, c: Boolean) {
|
||||
if (b != null && <!DEBUG_INFO_SMARTCAST!>b<!>) {}
|
||||
if (b == null || <!DEBUG_INFO_SMARTCAST!>b<!>) {}
|
||||
if (b != null) {
|
||||
if (<!DEBUG_INFO_SMARTCAST!>b<!> && c) {}
|
||||
if (<!DEBUG_INFO_SMARTCAST!>b<!> || c) {}
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
package
|
||||
|
||||
internal fun foo(/*0*/ b: kotlin.Boolean?, /*1*/ c: kotlin.Boolean): kotlin.Unit
|
||||
Reference in New Issue
Block a user