added info about smart casts to diagnostic tests
This commit is contained in:
+2
-2
@@ -2,7 +2,7 @@ fun test() {
|
||||
val out : Int? = null
|
||||
val x : Nothing? = null
|
||||
if (out != x)
|
||||
out.plus(1)
|
||||
<!DEBUG_INFO_AUTOCAST!>out<!>.plus(1)
|
||||
if (out == x) return
|
||||
out.plus(1)
|
||||
<!DEBUG_INFO_AUTOCAST!>out<!>.plus(1)
|
||||
}
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// !DIAGNOSTICS: -DEBUG_INFO_AUTOCAST
|
||||
class Foo {
|
||||
fun foo(a: Foo): Foo = a
|
||||
}
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ fun bar() {
|
||||
val i: Int? = 42
|
||||
if (i != null) {
|
||||
<!OVERLOAD_RESOLUTION_AMBIGUITY!>doSmth1<!> {
|
||||
val x = i + 1
|
||||
val x = <!DEBUG_INFO_AUTOCAST!>i<!> + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ fun foo() {
|
||||
val i : Int? = 42
|
||||
if (i != null) {
|
||||
<!UNRESOLVED_REFERENCE!>doSmth<!> {
|
||||
val <!UNUSED_VARIABLE!>x<!> = i + 1
|
||||
val <!UNUSED_VARIABLE!>x<!> = <!DEBUG_INFO_AUTOCAST!>i<!> + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,8 @@ 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) x.length() else x.length() // OK
|
||||
if ("a" == x || "b" == x) x.length() else x.length() // <– THEN ERROR
|
||||
if ("a" == x && "a" == x) x.length() else x.length() // <– ELSE ERROR
|
||||
if ("a" == x) <!DEBUG_INFO_AUTOCAST!>x<!>.length() else <!DEBUG_INFO_AUTOCAST!>x<!>.length() // OK
|
||||
if ("a" == x || "b" == x) <!DEBUG_INFO_AUTOCAST!>x<!>.length() else <!DEBUG_INFO_AUTOCAST!>x<!>.length() // <– THEN ERROR
|
||||
if ("a" == x && "a" == x) <!DEBUG_INFO_AUTOCAST!>x<!>.length() else <!DEBUG_INFO_AUTOCAST!>x<!>.length() // <– ELSE ERROR
|
||||
}
|
||||
}
|
||||
@@ -4,35 +4,35 @@ package kt2146
|
||||
fun f1(s: Int?): Int {
|
||||
return when (s) {
|
||||
null -> 3
|
||||
else -> s
|
||||
else -> <!DEBUG_INFO_AUTOCAST!>s<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun f2(s: Int?): Int {
|
||||
return when (s) {
|
||||
!is Int -> <!TYPE_MISMATCH!>s<!>
|
||||
else -> s
|
||||
else -> <!DEBUG_INFO_AUTOCAST!>s<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun f3(s: Int?): Int {
|
||||
return when (s) {
|
||||
is Int -> s
|
||||
is Int -> <!DEBUG_INFO_AUTOCAST!>s<!>
|
||||
else -> <!TYPE_MISMATCH!>s<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun f4(s: Int?): Int {
|
||||
return when {
|
||||
s == 4 -> s
|
||||
s == 4 -> <!DEBUG_INFO_AUTOCAST!>s<!>
|
||||
s == null -> <!TYPE_MISMATCH!>s<!>
|
||||
else -> s
|
||||
else -> <!DEBUG_INFO_AUTOCAST!>s<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun f5(s: Int?): Int {
|
||||
return when (s) {
|
||||
s!! -> s
|
||||
s!! -> <!DEBUG_INFO_AUTOCAST!>s<!>
|
||||
s -> <!TYPE_MISMATCH!>s<!>
|
||||
else -> 0
|
||||
}
|
||||
@@ -40,7 +40,7 @@ fun f5(s: Int?): Int {
|
||||
|
||||
fun f6(s: Int?): Int {
|
||||
return when {
|
||||
s is Int -> s
|
||||
s is Int -> <!DEBUG_INFO_AUTOCAST!>s<!>
|
||||
else -> <!TYPE_MISMATCH!>s<!>
|
||||
}
|
||||
}
|
||||
@@ -48,6 +48,6 @@ fun f6(s: Int?): Int {
|
||||
fun f7(s: Int?): Int {
|
||||
return when {
|
||||
s !is Int -> <!TYPE_MISMATCH!>s<!>
|
||||
else -> s
|
||||
else -> <!DEBUG_INFO_AUTOCAST!>s<!>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,30 +9,30 @@ fun main(args : Array<String>) {
|
||||
foo(<!TYPE_MISMATCH!>x<!>)
|
||||
|
||||
if (x != null) {
|
||||
foo(x)
|
||||
foo(<!DEBUG_INFO_AUTOCAST!>x<!>)
|
||||
foo(x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>)
|
||||
foo(x)
|
||||
foo(<!DEBUG_INFO_AUTOCAST!>x<!>)
|
||||
}
|
||||
|
||||
foo(<!TYPE_MISMATCH!>x<!>)
|
||||
|
||||
if (x != null) {
|
||||
foo(x)
|
||||
foo(<!DEBUG_INFO_AUTOCAST!>x<!>)
|
||||
foo(x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>)
|
||||
foo(x)
|
||||
foo(<!DEBUG_INFO_AUTOCAST!>x<!>)
|
||||
} else {
|
||||
foo(<!TYPE_MISMATCH!>x<!>)
|
||||
foo(x!!)
|
||||
foo(x)
|
||||
foo(<!DEBUG_INFO_AUTOCAST!>x<!>)
|
||||
}
|
||||
|
||||
foo(x)
|
||||
foo(<!DEBUG_INFO_AUTOCAST!>x<!>)
|
||||
foo(x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>)
|
||||
foo(x)
|
||||
foo(<!DEBUG_INFO_AUTOCAST!>x<!>)
|
||||
|
||||
val y: Int? = null
|
||||
y!!
|
||||
y<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
|
||||
foo(y)
|
||||
foo(<!DEBUG_INFO_AUTOCAST!>y<!>)
|
||||
foo(y<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package kt2176
|
||||
|
||||
fun f1(a: String?) {
|
||||
a!!
|
||||
a: String
|
||||
<!DEBUG_INFO_AUTOCAST!>a<!>: String
|
||||
}
|
||||
|
||||
fun f2(a: String) {
|
||||
@@ -13,12 +13,12 @@ fun f2(a: String) {
|
||||
|
||||
fun f3(a: Any?) {
|
||||
a as String
|
||||
a: String
|
||||
<!DEBUG_INFO_AUTOCAST!>a<!>: String
|
||||
}
|
||||
|
||||
fun f4(a: Any) {
|
||||
a as String
|
||||
a: String
|
||||
<!DEBUG_INFO_AUTOCAST!>a<!>: String
|
||||
}
|
||||
|
||||
fun f5(a: String) {
|
||||
|
||||
@@ -3,6 +3,6 @@ package foo
|
||||
|
||||
private fun sendCommand<T>(errorCallback: (()->Unit)? = null) {
|
||||
if (errorCallback != null) {
|
||||
errorCallback()
|
||||
<!DEBUG_INFO_AUTOCAST!>errorCallback<!>()
|
||||
}
|
||||
}
|
||||
@@ -4,5 +4,5 @@ package kt2212
|
||||
fun main(args: Array<String>) {
|
||||
val x: Int? = 1
|
||||
if (x == null) return
|
||||
System.out.println(x.plus(x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>))
|
||||
System.out.println(<!DEBUG_INFO_AUTOCAST!>x<!>.plus(x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>))
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// !DIAGNOSTICS: -DEBUG_INFO_AUTOCAST
|
||||
//KT-2216 Nullability of a value determined in function parameter computation doesn't pass to code following
|
||||
package kt2216
|
||||
|
||||
|
||||
@@ -8,14 +8,14 @@ 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, period : Int) else Pair(d, 1)
|
||||
if (period != null) Pair(d, <!DEBUG_INFO_AUTOCAST!>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 = x : Int
|
||||
val y = <!DEBUG_INFO_AUTOCAST!>x<!> : Int
|
||||
val <!UNUSED_VARIABLE!>z<!> : Int = y
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,18 +5,18 @@ package kt244
|
||||
|
||||
fun f(s: String?) {
|
||||
if (s != null) {
|
||||
s.length //ok
|
||||
var <!UNUSED_VARIABLE!>i<!> = s.length //error: Only safe calls are allowed on a nullable receiver
|
||||
System.out.println(s.length) //error
|
||||
<!DEBUG_INFO_AUTOCAST!>s<!>.length //ok
|
||||
var <!UNUSED_VARIABLE!>i<!> = <!DEBUG_INFO_AUTOCAST!>s<!>.length //error: Only safe calls are allowed on a nullable receiver
|
||||
System.out.println(<!DEBUG_INFO_AUTOCAST!>s<!>.length) //error
|
||||
}
|
||||
}
|
||||
|
||||
// more tests
|
||||
class A(a: String?) {
|
||||
val b = if (a != null) a.length else 1
|
||||
val b = if (a != null) <!DEBUG_INFO_AUTOCAST!>a<!>.length else 1
|
||||
{
|
||||
if (a != null) {
|
||||
val c = a.length
|
||||
val c = <!DEBUG_INFO_AUTOCAST!>a<!>.length
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ class A(a: String?) {
|
||||
|
||||
{
|
||||
if (a is String) {
|
||||
i = a.length
|
||||
i = <!DEBUG_INFO_AUTOCAST!>a<!>.length
|
||||
}
|
||||
else {
|
||||
i = 3
|
||||
|
||||
@@ -7,11 +7,11 @@ fun test() {
|
||||
val p = test.Public()
|
||||
if (p.public is Int) <!AUTOCAST_IMPOSSIBLE!>p.public<!> + 1
|
||||
if (p.<!INVISIBLE_MEMBER!>protected<!> is Int) <!AUTOCAST_IMPOSSIBLE!>p.<!INVISIBLE_MEMBER!>protected<!><!> + 1
|
||||
if (p.internal is Int) p.internal + 1
|
||||
if (p.internal is Int) <!DEBUG_INFO_AUTOCAST!>p.internal<!> + 1
|
||||
val i = test.Internal()
|
||||
if (i.public is Int) i.public + 1
|
||||
if (i.<!INVISIBLE_MEMBER!>protected<!> is Int) i.<!INVISIBLE_MEMBER!>protected<!> + 1
|
||||
if (i.internal is Int) i.internal + 1
|
||||
if (i.public is Int) <!DEBUG_INFO_AUTOCAST!>i.public<!> + 1
|
||||
if (i.<!INVISIBLE_MEMBER!>protected<!> is Int) <!DEBUG_INFO_AUTOCAST!>i.<!INVISIBLE_MEMBER!>protected<!><!> + 1
|
||||
if (i.internal is Int) <!DEBUG_INFO_AUTOCAST!>i.internal<!> + 1
|
||||
}
|
||||
|
||||
// FILE: other.kt
|
||||
|
||||
Reference in New Issue
Block a user