Adjust testData to CharSequence.length transformation

This commit is contained in:
Denis Zharkov
2015-10-12 20:29:01 +03:00
committed by Mikhail Glukhikh
parent cb562e7ea5
commit f0e3fd617d
348 changed files with 524 additions and 540 deletions
@@ -3,7 +3,7 @@ package foo
fun dispatch(request: Request) {
val <!UNUSED_VARIABLE!>url<!> = request.getRequestURI() as String
if (request.getMethod()?.length() != 0) {
if (request.getMethod()?.length != 0) {
}
}
+1 -1
View File
@@ -5,6 +5,6 @@
fun foo(p1: String?, p2: String?) {
if (p2 != null) {
val v = p1 ?: <!DEBUG_INFO_SMARTCAST!>p2<!>
val size = v.length()
val size = v.length
}
}
+1 -1
View File
@@ -1,5 +1,5 @@
fun foo(p: String?): Int {
// We should get smart cast here
val x = if (p != null) { <!DEBUG_INFO_SMARTCAST!>p<!> } else "a"
return x.length()
return x.length
}
+1 -1
View File
@@ -1,7 +1,7 @@
//KT-5455 Need warning about redundant type cast
fun foo(o: Any): Int {
if (o is String) {
return (o <!USELESS_CAST!>as String<!>).length()
return (o <!USELESS_CAST!>as String<!>).length
}
return -1
}
+2 -2
View File
@@ -1,7 +1,7 @@
public fun test(o: String?): Boolean {
return when {
// Data flow info should propagate from o == null to o.length()
o == null, <!DEBUG_INFO_SMARTCAST!>o<!>.length() == 0 -> false
// Data flow info should propagate from o == null to o.length
o == null, <!DEBUG_INFO_SMARTCAST!>o<!>.length == 0 -> false
else -> true
}
}
@@ -2,10 +2,10 @@ public fun foo(x: String?, y: String?): Int {
while (true) {
val z = x ?: if (y == null) break else <!DEBUG_INFO_SMARTCAST!>y<!>
// z is not null in both branches
z.length()
z.length
// y is nullable if x != null
y<!UNSAFE_CALL!>.<!>length()
y<!UNSAFE_CALL!>.<!>length
}
// y is null because of the break
return y<!UNSAFE_CALL!>.<!>length()
return y<!UNSAFE_CALL!>.<!>length
}
@@ -7,11 +7,11 @@ public fun foo(x: String?): Int {
null -> break@loop
"abc" -> return 0
"xyz" -> return 1
else -> <!DEBUG_INFO_SMARTCAST!>x<!>.length()
else -> <!DEBUG_INFO_SMARTCAST!>x<!>.length
}
// y is always Int after when
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>y<!>)
}
// x is null because of the break
return x<!UNSAFE_CALL!>.<!>length()
return x<!UNSAFE_CALL!>.<!>length
}
@@ -8,9 +8,9 @@ public fun foo(x: String?, z: String?, w: String?): Int {
gav(w!!, if (x == null) break else <!DEBUG_INFO_SMARTCAST!>x<!>, z!!)
} while (bar())
// w is not null because of w!!
<!DEBUG_INFO_SMARTCAST!>w<!>.length()
<!DEBUG_INFO_SMARTCAST!>w<!>.length
// z is nullable despite of z!!
z<!UNSAFE_CALL!>.<!>length()
z<!UNSAFE_CALL!>.<!>length
// x is null because of the break
return x<!UNSAFE_CALL!>.<!>length()
return x<!UNSAFE_CALL!>.<!>length
}
@@ -7,7 +7,7 @@ public fun foo(x: String?, z: String?): Int {
gav(if (x == null) break else <!DEBUG_INFO_SMARTCAST!>x<!>, z!!)
} while (bar())
// z is nullable despite of z!!
z<!UNSAFE_CALL!>.<!>length()
z<!UNSAFE_CALL!>.<!>length
// x is null because of the break
return x<!UNSAFE_CALL!>.<!>length()
return x<!UNSAFE_CALL!>.<!>length
}
@@ -10,5 +10,5 @@ public fun foo(x: String?): Int {
} while (bar())
y.hashCode()
// x is null because of the break
return x<!UNSAFE_CALL!>.<!>length()
return x<!UNSAFE_CALL!>.<!>length
}
@@ -7,7 +7,7 @@ public fun foo(x: String?, z: String?): Int {
gav(z!!, if (x == null) break else <!DEBUG_INFO_SMARTCAST!>x<!>)
} while (bar())
// z is not null because of z!!
<!DEBUG_INFO_SMARTCAST!>z<!>.length()
<!DEBUG_INFO_SMARTCAST!>z<!>.length
// x is null because of the break
return x<!UNSAFE_CALL!>.<!>length()
return x<!UNSAFE_CALL!>.<!>length
}
@@ -8,9 +8,9 @@ public fun foo(x: String?, z: String?, w: String?): Int {
gav(z!!, w!!, if (x == null) break else <!DEBUG_INFO_SMARTCAST!>x<!>)
} while (bar())
// w is not null because of w!!
<!DEBUG_INFO_SMARTCAST!>w<!>.length()
<!DEBUG_INFO_SMARTCAST!>w<!>.length
// z is not null because of z!!
<!DEBUG_INFO_SMARTCAST!>z<!>.length()
<!DEBUG_INFO_SMARTCAST!>z<!>.length
// x is null because of the break
return x<!UNSAFE_CALL!>.<!>length()
return x<!UNSAFE_CALL!>.<!>length
}
@@ -3,9 +3,9 @@ fun x(): Boolean { return true }
public fun foo(p: String?): Int {
// See KT-6283
do {
p!!.length()
p!!.length
} while (!x())
// Do-while loop is executed at least once, so
// p should be not null here
return <!DEBUG_INFO_SMARTCAST!>p<!>.length()
return <!DEBUG_INFO_SMARTCAST!>p<!>.length
}
@@ -3,9 +3,9 @@ fun x(): Boolean { return true }
public fun foo(p: String?): Int {
// See KT-6283
do {
p!!.length()
p!!.length
if (p == "abc") break
} while (!x())
// p should be smart casted despite of break
return <!DEBUG_INFO_SMARTCAST!>p<!>.length()
return <!DEBUG_INFO_SMARTCAST!>p<!>.length
}
@@ -3,9 +3,9 @@ fun x(): Boolean { return true }
public fun foo(p: String?): Int {
// See KT-6283
do {
p!!.length()
p!!.length
if (p == "abc") continue
} while (!x())
// p should be smart casted despite of continue
return <!DEBUG_INFO_SMARTCAST!>p<!>.length()
return <!DEBUG_INFO_SMARTCAST!>p<!>.length
}
@@ -6,8 +6,8 @@ public fun foo(p: String?): Int {
do {
if (y()) break
// We do not always reach this statement
p!!.length()
p!!.length
} while (!x())
// Here we have do while loop but p is still nullable due to break before
return p<!UNSAFE_CALL!>.<!>length()
return p<!UNSAFE_CALL!>.<!>length
}
@@ -6,8 +6,8 @@ public fun foo(p: String?): Int {
do {
if (y()) continue
// We do not always reach this statement
p!!.length()
p!!.length
} while (!x())
// Here we have do while loop but p is still nullable due to continue before
return p<!UNSAFE_CALL!>.<!>length()
return p<!UNSAFE_CALL!>.<!>length
}
@@ -1,5 +1,5 @@
fun foo(s: String?): Int {
do {
} while (s!!.length() > 0)
return <!DEBUG_INFO_SMARTCAST!>s<!>.length()
} while (s!!.length > 0)
return <!DEBUG_INFO_SMARTCAST!>s<!>.length
}
@@ -3,7 +3,7 @@ fun bar(): Boolean { return true }
fun foo(s: String?): Int {
do {
if (bar()) break
} while (s!!.length() > 0)
} while (s!!.length > 0)
// This call is unsafe due to break
return s<!UNSAFE_CALL!>.<!>length()
return s<!UNSAFE_CALL!>.<!>length
}
@@ -3,8 +3,8 @@ fun x(): Boolean { return true }
public fun foo(p: String?): Int {
// Exotic variant with unused literal
do <!UNUSED_FUNCTION_LITERAL!>{ ->
p!!.length()
p!!.length
}<!> while (!x())
// Literal is not called so p.length() is unsafe
return p<!UNSAFE_CALL!>.<!>length()
// Literal is not called so p.length is unsafe
return p<!UNSAFE_CALL!>.<!>length
}
@@ -6,5 +6,5 @@ public fun foo(p: String?): Int {
if (p != null) break
} while (!x())
// p can be null despite of the break
return p<!UNSAFE_CALL!>.<!>length()
return p<!UNSAFE_CALL!>.<!>length
}
@@ -1,5 +1,5 @@
fun foo(s: String?): Int {
do {
} while (s==null)
return <!DEBUG_INFO_SMARTCAST!>s<!>.length()
return <!DEBUG_INFO_SMARTCAST!>s<!>.length
}
@@ -5,5 +5,5 @@ fun foo(s: String?): Int {
if (bar()) break
} while (s==null)
// This call is unsafe due to break
return s<!UNSAFE_CALL!>.<!>length()
return s<!UNSAFE_CALL!>.<!>length
}
@@ -3,8 +3,8 @@ public fun foo(x: String?): Int {
// After the check, smart cast should work
x ?: break
// x is not null in both branches
<!DEBUG_INFO_SMARTCAST!>x<!>.length()
<!DEBUG_INFO_SMARTCAST!>x<!>.length
} while (true)
// x is null because of the break
return x<!UNSAFE_CALL!>.<!>length()
return x<!UNSAFE_CALL!>.<!>length
}
@@ -2,8 +2,8 @@ public fun foo(x: String?, y: String?): Int {
while (true) {
x ?: if (y == null) break
// y is nullable if x != null
y<!UNSAFE_CALL!>.<!>length()
y<!UNSAFE_CALL!>.<!>length
}
// y is null because of the break
return y<!UNSAFE_CALL!>.<!>length()
return y<!UNSAFE_CALL!>.<!>length
}
@@ -1,9 +1,9 @@
public fun foo(x: String?): Int {
do {
// After the check, smart cast should work
x ?: x!!.length()
x ?: x!!.length
// x is not null in both branches
if (<!DEBUG_INFO_SMARTCAST!>x<!>.length() == 0) break
if (<!DEBUG_INFO_SMARTCAST!>x<!>.length == 0) break
} while (true)
return <!DEBUG_INFO_SMARTCAST!>x<!>.length()
return <!DEBUG_INFO_SMARTCAST!>x<!>.length
}
@@ -2,8 +2,8 @@ public fun foo(x: String?, y: String?): Int {
while (true) {
(if (x != null) break else y) ?: y!!
// y is not null in both branches but it's hard to determine
y<!UNSAFE_CALL!>.<!>length()
y<!UNSAFE_CALL!>.<!>length
}
// y can be null because of the break
return y<!UNSAFE_CALL!>.<!>length()
return y<!UNSAFE_CALL!>.<!>length
}
@@ -5,8 +5,8 @@ public fun foo(p: String?, y: String?): Int {
"null".toString()
break
}
<!DEBUG_INFO_SMARTCAST!>y<!>.length()
p!!.length()
<!DEBUG_INFO_SMARTCAST!>y<!>.length
p!!.length
} while (true)
return y?.length() ?: -1
return y?.length ?: -1
}
@@ -10,5 +10,5 @@ public fun foo(x: String?): Int {
} while (bar())
y.hashCode()
// x is null because of the break
return x<!UNSAFE_CALL!>.<!>length()
return x<!UNSAFE_CALL!>.<!>length
}
@@ -6,5 +6,5 @@ public fun foo(x: String?): Int {
// In future we can infer this initialization
<!UNINITIALIZED_VARIABLE!>y<!>.hashCode()
// x is null because of the break
return x<!UNSAFE_CALL!>.<!>length()
return x<!UNSAFE_CALL!>.<!>length
}
@@ -3,8 +3,8 @@ public fun foo(x: String?): Int {
// After the check, smart cast should work
val y = if (x == null) break else <!DEBUG_INFO_SMARTCAST!>x<!>
// y is not null in both branches
y.length()
y.length
}
// x is null because of the break
return x<!UNSAFE_CALL!>.<!>length()
return x<!UNSAFE_CALL!>.<!>length
}
@@ -3,13 +3,13 @@ public fun foo(x: String?, y: String?): Int {
// After the check, smart cast should work
if (x != null) {
if (x == "abc") break
y!!.length()
y!!.length
} else {
y!!.length()
y!!.length
}
// y!! in both branches
<!DEBUG_INFO_SMARTCAST!>y<!>.length()
<!DEBUG_INFO_SMARTCAST!>y<!>.length
} while (true)
// break is possible before so !! is necessary
return y!!.length()
return y!!.length
}
@@ -2,8 +2,8 @@ public fun foo(p: String?, y: String?): Int {
do {
// After the check, smart cast should work
if (y == null) break
<!DEBUG_INFO_SMARTCAST!>y<!>.length()
p!!.length()
<!DEBUG_INFO_SMARTCAST!>y<!>.length
p!!.length
} while (true)
return y?.length() ?: -1
return y?.length ?: -1
}
@@ -2,10 +2,10 @@ public fun foo(x: String?, y: String?): Int {
while (true) {
val z = (if (y == null) break else x) ?: <!DEBUG_INFO_SMARTCAST!>y<!>
// z is not null in both branches
z.length()
z.length
// y is not null in both branches
<!DEBUG_INFO_SMARTCAST!>y<!>.length()
<!DEBUG_INFO_SMARTCAST!>y<!>.length
}
// y is null because of the break
return y<!UNSAFE_CALL!>.<!>length()
return y<!UNSAFE_CALL!>.<!>length
}
@@ -3,11 +3,11 @@ fun x(): Boolean { return true }
public fun foo(p: String?, r: String?): Int {
do {
do {
p!!.length()
p!!.length
} while (r == null)
} while (!x())
// Auto cast possible
<!DEBUG_INFO_SMARTCAST!>r<!>.length()
<!DEBUG_INFO_SMARTCAST!>r<!>.length
// Auto cast possible
return <!DEBUG_INFO_SMARTCAST!>p<!>.length()
return <!DEBUG_INFO_SMARTCAST!>p<!>.length
}
@@ -3,12 +3,12 @@ fun x(): Boolean { return true }
public fun foo(p: String?, r: String?): Int {
outer@ do {
do {
p!!.length()
p!!.length
if (!x()) continue@outer
} while (r == null)
} while (!x())
// Auto cast NOT possible due to long continue
r<!UNSAFE_CALL!>.<!>length()
r<!UNSAFE_CALL!>.<!>length
// Auto cast possible
return <!DEBUG_INFO_SMARTCAST!>p<!>.length()
return <!DEBUG_INFO_SMARTCAST!>p<!>.length
}
@@ -2,16 +2,16 @@ fun x(): Boolean { return true }
public fun foo(p: String?, r: String?, q: String?): Int {
while(true) {
q!!.length()
q!!.length
do {
do {
p!!.length()
p!!.length
} while (!x())
} while (r == null)
if (!x()) break
}
// Smart cast is possible everywhere
<!DEBUG_INFO_SMARTCAST!>r<!>.length()
<!DEBUG_INFO_SMARTCAST!>q<!>.length()
return <!DEBUG_INFO_SMARTCAST!>p<!>.length()
<!DEBUG_INFO_SMARTCAST!>r<!>.length
<!DEBUG_INFO_SMARTCAST!>q<!>.length
return <!DEBUG_INFO_SMARTCAST!>p<!>.length
}
@@ -2,14 +2,14 @@ fun x(): Boolean { return true }
public fun foo(p: String?, r: String?, q: String?): Int {
while(true) {
q!!.length()
q!!.length
do {
p!!.length()
p!!.length
} while (r == null)
if (!x()) break
}
// Smart cast is possible everywhere
<!DEBUG_INFO_SMARTCAST!>r<!>.length()
<!DEBUG_INFO_SMARTCAST!>q<!>.length()
return <!DEBUG_INFO_SMARTCAST!>p<!>.length()
<!DEBUG_INFO_SMARTCAST!>r<!>.length
<!DEBUG_INFO_SMARTCAST!>q<!>.length
return <!DEBUG_INFO_SMARTCAST!>p<!>.length
}
@@ -2,17 +2,17 @@ fun x(): Boolean { return true }
public fun foo(p: String?, r: String?, q: String?): Int {
while(true) {
q!!.length()
q!!.length
do {
while(true) {
p!!.length()
p!!.length
if (x()) break
}
} while (r == null)
if (!x()) break
}
// Smart cast is possible everywhere
<!DEBUG_INFO_SMARTCAST!>r<!>.length()
<!DEBUG_INFO_SMARTCAST!>q<!>.length()
return <!DEBUG_INFO_SMARTCAST!>p<!>.length()
<!DEBUG_INFO_SMARTCAST!>r<!>.length
<!DEBUG_INFO_SMARTCAST!>q<!>.length
return <!DEBUG_INFO_SMARTCAST!>p<!>.length
}
@@ -2,10 +2,10 @@ fun x(p: String): Boolean { return p == "abc" }
public fun foo(p: String?, r: String?, q: String?): Int {
while(true) {
q!!.length()
q!!.length
loop@ do {
while(true) {
p!!.length()
p!!.length
if (x(<!DEBUG_INFO_SMARTCAST!>p<!>)) break@loop
if (x(<!DEBUG_INFO_SMARTCAST!>q<!>)) break
}
@@ -13,8 +13,8 @@ public fun foo(p: String?, r: String?, q: String?): Int {
if (!x(<!DEBUG_INFO_SMARTCAST!>p<!>)) break
}
// Long break allows r == null
r<!UNSAFE_CALL!>.<!>length()
r<!UNSAFE_CALL!>.<!>length
// Smart cast is possible
<!DEBUG_INFO_SMARTCAST!>q<!>.length()
return <!DEBUG_INFO_SMARTCAST!>p<!>.length()
<!DEBUG_INFO_SMARTCAST!>q<!>.length
return <!DEBUG_INFO_SMARTCAST!>p<!>.length
}
@@ -2,18 +2,18 @@ fun x(): Boolean { return true }
public fun foo(p: String?, r: String?, q: String?): Int {
outer@ while(true) {
q!!.length()
q!!.length
do {
if (x()) continue@outer
do {
p!!.length()
p!!.length
} while (!x())
} while (r == null)
if (!x()) break
}
// Smart cast is possible only for q
<!DEBUG_INFO_SMARTCAST!>q<!>.length()
<!DEBUG_INFO_SMARTCAST!>q<!>.length
// But not possible for the others
r<!UNSAFE_CALL!>.<!>length()
return p<!UNSAFE_CALL!>.<!>length()
r<!UNSAFE_CALL!>.<!>length
return p<!UNSAFE_CALL!>.<!>length
}
@@ -10,7 +10,7 @@ public fun foo(x: String?): Int {
null -> break@loop
"abc" -> return 0
"xyz" -> return 1
else -> <!DEBUG_INFO_SMARTCAST!>x<!>.length()
else -> <!DEBUG_INFO_SMARTCAST!>x<!>.length
}
// y is always Int after when
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>y<!>)
@@ -18,5 +18,5 @@ public fun foo(x: String?): Int {
// y is always Int even here
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>y<!>)
// x is null because of the break
return x<!UNSAFE_CALL!>.<!>length()
return x<!UNSAFE_CALL!>.<!>length
}
@@ -3,12 +3,12 @@ fun foo(x: String): String? = x
fun calc(x: String?, y: String?): Int {
do {
// Smart cast because of x!! in receiver
foo(x!!)?.subSequence(0, if (<!DEBUG_INFO_SMARTCAST!>x<!>.length() > 0) 5 else break)
y!!.length()
foo(x!!)?.subSequence(0, if (<!DEBUG_INFO_SMARTCAST!>x<!>.length > 0) 5 else break)
y!!.length
// x is not null in condition but we do not see it yet
} while (x<!UNSAFE_CALL!>.<!>length() > 0)
} while (x<!UNSAFE_CALL!>.<!>length > 0)
// y is nullable because of break
y<!UNSAFE_CALL!>.<!>length()
y<!UNSAFE_CALL!>.<!>length
// x is not null, at least in theory
return <!DEBUG_INFO_SMARTCAST!>x<!>.length()
return <!DEBUG_INFO_SMARTCAST!>x<!>.length
}
@@ -3,10 +3,10 @@ fun foo(x: String): String? = x
fun calc(x: String?): Int {
do {
// Smart cast because of x!! in receiver
foo(x!!)?.subSequence(0, <!DEBUG_INFO_SMARTCAST!>x<!>.length())
foo(x!!)?.subSequence(0, <!DEBUG_INFO_SMARTCAST!>x<!>.length)
// Smart cast because of x!! in receiver
if (<!DEBUG_INFO_SMARTCAST!>x<!>.length() == 0) break
if (<!DEBUG_INFO_SMARTCAST!>x<!>.length == 0) break
} while (true)
// Here x is also not null
return <!DEBUG_INFO_SMARTCAST!>x<!>.length()
return <!DEBUG_INFO_SMARTCAST!>x<!>.length
}
@@ -1,9 +1,9 @@
public fun foo(p: String?, y: String?): Int {
do {
// After this !!, y. should be smartcasted in loop as well as outside
y!!.length()
y!!.length
if (p == null) break
<!DEBUG_INFO_SMARTCAST!>y<!>.length()
<!DEBUG_INFO_SMARTCAST!>y<!>.length
} while (true)
return <!DEBUG_INFO_SMARTCAST!>y<!>.length()
return <!DEBUG_INFO_SMARTCAST!>y<!>.length
}
@@ -4,9 +4,9 @@ public fun foo(x: String?): Int {
null -> break@loop
"abc" -> return 0
"xyz" -> return 1
else -> <!DEBUG_INFO_SMARTCAST!>x<!>.length()
else -> <!DEBUG_INFO_SMARTCAST!>x<!>.length
}
}
// x is null because of the break
return x<!UNSAFE_CALL!>.<!>length()
return x<!UNSAFE_CALL!>.<!>length
}
@@ -9,5 +9,5 @@ public fun foo(x: String?): Int {
}
// x is not null because of the break
// but we are not able to detect it
return x<!UNSAFE_CALL!>.<!>length()
return x<!UNSAFE_CALL!>.<!>length
}
@@ -1,6 +1,6 @@
fun foo(s: String?): Int {
while (s!!.length() > 0) {
<!DEBUG_INFO_SMARTCAST!>s<!>.length()
while (s!!.length > 0) {
<!DEBUG_INFO_SMARTCAST!>s<!>.length
}
return <!DEBUG_INFO_SMARTCAST!>s<!>.length()
return <!DEBUG_INFO_SMARTCAST!>s<!>.length
}
@@ -1,9 +1,9 @@
fun bar(): Boolean { return true }
fun foo(s: String?): Int {
while (s!!.length() > 0) {
<!DEBUG_INFO_SMARTCAST!>s<!>.length()
while (s!!.length > 0) {
<!DEBUG_INFO_SMARTCAST!>s<!>.length
if (bar()) break
}
return <!DEBUG_INFO_SMARTCAST!>s<!>.length()
return <!DEBUG_INFO_SMARTCAST!>s<!>.length
}
@@ -1,5 +1,5 @@
fun foo(s: String?): Int {
while (s==null) {
}
return <!DEBUG_INFO_SMARTCAST!>s<!>.length()
return <!DEBUG_INFO_SMARTCAST!>s<!>.length
}
@@ -5,5 +5,5 @@ fun foo(s: String?): Int {
if (bar()) break
}
// Call is unsafe due to break
return s<!UNSAFE_CALL!>.<!>length()
return s<!UNSAFE_CALL!>.<!>length
}
@@ -2,9 +2,9 @@ fun x(): Boolean { return true }
public fun foo(p: String?): Int {
while(x()) {
p!!.length()
p!!.length
if (x()) break
}
// p is nullable because it's possible loop body is not executed at all
return p<!UNSAFE_CALL!>.<!>length()
return p<!UNSAFE_CALL!>.<!>length
}
@@ -3,9 +3,9 @@ fun x(): Boolean { return true }
public fun foo(p: String?): Int {
// Like whileTrue but 2 == 2 is in use
while(2 == 2) {
p!!.length()
p!!.length
if (x()) break
}
// Smart cast should not work in this case, see KT-6284
return p<!UNSAFE_CALL!>.<!>length()
return p<!UNSAFE_CALL!>.<!>length
}
@@ -3,10 +3,10 @@ fun x(): Boolean { return true }
public fun foo(p: String?): Int {
// KT-6284
while(true) {
p!!.length()
p!!.length
if (x()) break
}
// while (true) loop body is executed at least once
// so p is not null here
return <!DEBUG_INFO_SMARTCAST!>p<!>.length()
return <!DEBUG_INFO_SMARTCAST!>p<!>.length
}
@@ -5,8 +5,8 @@ public fun foo(p: String?): Int {
if (x()) break
if (p==null) return -1
// p is not null
<!DEBUG_INFO_SMARTCAST!>p<!>.length()
<!DEBUG_INFO_SMARTCAST!>p<!>.length
}
// p can be null because break is earlier than return
return p<!UNSAFE_CALL!>.<!>length()
return p<!UNSAFE_CALL!>.<!>length
}
@@ -4,8 +4,8 @@ public fun foo(p: String?): Int {
while(true) {
if (x()) break
// We do not always reach this statement
p!!.length()
p!!.length
}
// Here we have while (true) loop but p is nullable due to break before
return p<!UNSAFE_CALL!>.<!>length()
return p<!UNSAFE_CALL!>.<!>length
}
@@ -5,9 +5,9 @@ public fun foo(p: String?): Int {
if (p==null) return -1
if (x()) break
// p is not null
<!DEBUG_INFO_SMARTCAST!>p<!>.length()
<!DEBUG_INFO_SMARTCAST!>p<!>.length
}
// while (true) loop body with return is executed at least once
// so p is not null here
return <!DEBUG_INFO_SMARTCAST!>p<!>.length()
return <!DEBUG_INFO_SMARTCAST!>p<!>.length
}
@@ -7,5 +7,5 @@ abstract class A(val s: String) {
fun foo(o: String?): Int {
val a = object : A(o!!){}
a.bar()
return <!DEBUG_INFO_SMARTCAST!>o<!>.length()
return <!DEBUG_INFO_SMARTCAST!>o<!>.length
}
@@ -5,7 +5,7 @@ public class X {
public fun fn(): Int {
if (y != null)
// With non-default getter smartcast is not possible
return y<!UNSAFE_CALL!>.<!>length()
return y<!UNSAFE_CALL!>.<!>length
else
return 0
}
@@ -5,7 +5,7 @@ public interface A {
public class B(override public val x: Any) : A {
fun foo(): Int {
if (x is String) {
return <!DEBUG_INFO_SMARTCAST!>x<!>.length()
return <!DEBUG_INFO_SMARTCAST!>x<!>.length
} else {
return 0
}
@@ -17,7 +17,7 @@ import a.X
public fun X.gav(): Int {
if (x != null)
// Smart cast is not possible if definition is in another module
return x<!UNSAFE_CALL!>.<!>length()
return x<!UNSAFE_CALL!>.<!>length
else
return 0
}
@@ -29,7 +29,7 @@ package a
public fun X.gav(): Int {
if (x != null)
// Even if it's in the same package
return x<!UNSAFE_CALL!>.<!>length()
return x<!UNSAFE_CALL!>.<!>length
else
return 0
}
@@ -3,7 +3,7 @@ public open class X {
public fun fn(): Int {
if (x != null)
// Smartcast is possible for protected value property in the same class
return <!DEBUG_INFO_SMARTCAST!>x<!>.length()
return <!DEBUG_INFO_SMARTCAST!>x<!>.length
else
return 0
}
@@ -12,6 +12,6 @@ public open class X {
public class Y: X() {
public fun bar(): Int {
// Smartcast is possible even in derived class
return if (x != null) <!DEBUG_INFO_SMARTCAST!>x<!>.length() else 0
return if (x != null) <!DEBUG_INFO_SMARTCAST!>x<!>.length else 0
}
}
@@ -4,7 +4,7 @@ public class X {
if (x != null)
// Smartcast is possible because it's value property with default getter
// used in the same module
return <!DEBUG_INFO_SMARTCAST!>x<!>.length()
return <!DEBUG_INFO_SMARTCAST!>x<!>.length
else
return 0
}
@@ -4,10 +4,10 @@ public class X {
public fun fn(): Int {
if (x != null)
// Smartcast is not possible for variable properties
return x<!UNSAFE_CALL!>.<!>length()
return x<!UNSAFE_CALL!>.<!>length
else if (y != null)
// Even if they are private
return y<!UNSAFE_CALL!>.<!>length()
return y<!UNSAFE_CALL!>.<!>length
else
return 0
}
@@ -1,6 +1,6 @@
fun calc(x: List<String>?): Int {
// x should be non-null in arguments list, including inner call
x?.get(<!DEBUG_INFO_SMARTCAST!>x<!>.get(<!DEBUG_INFO_SMARTCAST!>x<!>.size - 1).length())
x?.get(<!DEBUG_INFO_SMARTCAST!>x<!>.get(<!DEBUG_INFO_SMARTCAST!>x<!>.size - 1).length)
// but not also here!
return x<!UNSAFE_CALL!>.<!>size
}
@@ -2,5 +2,5 @@ fun String.foo(arg: Int) = this[arg]
fun calc(x: String?) {
// x should be non-null in arguments list
x?.foo(<!DEBUG_INFO_SMARTCAST!>x<!>.length() - 1)
x?.foo(<!DEBUG_INFO_SMARTCAST!>x<!>.length - 1)
}
@@ -2,5 +2,5 @@ fun String.bar(s: String) = s
fun foo(s: String?) {
s?.bar(<!DEBUG_INFO_SMARTCAST!>s<!>)
s?.get(<!DEBUG_INFO_SMARTCAST!>s<!>.length())
s?.get(<!DEBUG_INFO_SMARTCAST!>s<!>.length)
}
@@ -2,7 +2,7 @@ fun foo(x: String): String? = x
fun calc(x: String?, y: String?): Int {
// Smart cast because of y!! in receiver
x?.subSequence(y!!.subSequence(0, 1).length(), <!DEBUG_INFO_SMARTCAST!>y<!>.length())
x?.subSequence(y!!.subSequence(0, 1).length, <!DEBUG_INFO_SMARTCAST!>y<!>.length)
// No smart cast possible
return y<!UNSAFE_CALL!>.<!>length()
return y<!UNSAFE_CALL!>.<!>length
}
@@ -4,5 +4,5 @@ fun foo(y: Int): Int {
fun calc(x: List<String>?): Int {
// x should be non-null in arguments list
return foo(x?.get(<!DEBUG_INFO_SMARTCAST!>x<!>.size - 1)!!.length())
return foo(x?.get(<!DEBUG_INFO_SMARTCAST!>x<!>.size - 1)!!.length)
}
@@ -1,6 +1,6 @@
data class MyClass(val x: String?)
fun foo(y: MyClass): Int {
val z = y.x?.subSequence(0, <!DEBUG_INFO_SMARTCAST!>y.x<!>.length())
return z?.length() ?: -1
val z = y.x?.subSequence(0, <!DEBUG_INFO_SMARTCAST!>y.x<!>.length)
return z?.length ?: -1
}
@@ -2,7 +2,7 @@ fun foo(x: String): String? = x
fun calc(x: String?): Int {
// Smart cast because of x!! in receiver
foo(x!!)?.subSequence(0, <!DEBUG_INFO_SMARTCAST!>x<!>.length())
foo(x!!)?.subSequence(0, <!DEBUG_INFO_SMARTCAST!>x<!>.length)
// Smart cast because of x!! in receiver
return <!DEBUG_INFO_SMARTCAST!>x<!>.length()
return <!DEBUG_INFO_SMARTCAST!>x<!>.length
}
@@ -2,7 +2,7 @@ fun foo(x: String): String? = x
fun calc(x: String?): Int {
// Smart cast because of x!! in receiver
foo(x!!)?.subSequence(0, <!DEBUG_INFO_SMARTCAST!>x<!>.length())?.length()
foo(x!!)?.subSequence(0, <!DEBUG_INFO_SMARTCAST!>x<!>.length)?.length
// Smart cast because of x!! in receiver
return <!DEBUG_INFO_SMARTCAST!>x<!>.length()
return <!DEBUG_INFO_SMARTCAST!>x<!>.length
}
@@ -2,7 +2,7 @@ fun foo(x: String): String? = x
fun calc(x: String?, y: Int?): Int {
// Smart cast because of x!! in receiver
foo(x!!)?.subSequence(y!!, <!DEBUG_INFO_SMARTCAST!>x<!>.length())?.length()
foo(x!!)?.subSequence(y!!, <!DEBUG_INFO_SMARTCAST!>x<!>.length)?.length
// No smart cast possible
return <!TYPE_MISMATCH!>y<!>
}
@@ -2,9 +2,9 @@ fun foo() {
var v: Any = 42
v.<!UNRESOLVED_REFERENCE!>length<!>()
v = "abc"
<!DEBUG_INFO_SMARTCAST!>v<!>.length()
<!DEBUG_INFO_SMARTCAST!>v<!>.length
v = 42
v.<!UNRESOLVED_REFERENCE!>length<!>()
v = "abc"
<!DEBUG_INFO_SMARTCAST!>v<!>.length()
<!DEBUG_INFO_SMARTCAST!>v<!>.length
}
@@ -3,7 +3,7 @@ fun x(): Boolean { return true }
public fun foo(pp: Any): Int {
var p = pp
do {
(p as String).length()
(p as String).length
if (p == "abc") break
p = 42
} while (!x())
@@ -9,7 +9,7 @@ public fun foo(xx: Any): Int {
y = "abc"
}
// y!! in both branches
<!DEBUG_INFO_SMARTCAST!>y<!>.length()
<!DEBUG_INFO_SMARTCAST!>y<!>.length
} while (!(x is String))
return <!DEBUG_INFO_SMARTCAST!>x<!>.length()
return <!DEBUG_INFO_SMARTCAST!>x<!>.length
}
@@ -9,7 +9,7 @@ public fun foo(xx: Any): Int {
y = "abc"
}
// y!! in both branches
<!DEBUG_INFO_SMARTCAST!>y<!>.length()
<!DEBUG_INFO_SMARTCAST!>y<!>.length
} while (true)
// We could have smart cast here but with break it's hard to detect
return x.<!UNRESOLVED_REFERENCE!>length<!>()
@@ -1,5 +1,5 @@
public fun bar(s: String) {
System.out.println("Length of $s is ${s.length()}")
System.out.println("Length of $s is ${s.length}")
}
public fun foo() {
@@ -6,7 +6,7 @@ fun get(): Any {
fun foo(): Int {
var ss: Any = get()
return if (ss is String && <!DEBUG_INFO_SMARTCAST!>ss<!>.length() > 0)
return if (ss is String && <!DEBUG_INFO_SMARTCAST!>ss<!>.length > 0)
1
else
0
@@ -1,5 +1,5 @@
public fun bar(s: String) {
System.out.println("Length of $s is ${s.length()}")
System.out.println("Length of $s is ${s.length}")
}
public fun foo() {
@@ -1,7 +1,7 @@
class MyClass(var p: String?)
fun bar(s: String): Int {
return s.length()
return s.length
}
fun foo(m: MyClass): Int {
@@ -1,7 +1,7 @@
class MyClass(var p: String?)
fun bar(s: String?): Int {
return s?.length() ?: -1
return s?.length ?: -1
}
fun foo(m: MyClass): Int {
@@ -4,6 +4,6 @@ fun get(): Any {
fun foo(): Int {
var c: Any = get()
(c as String).length()
return <!DEBUG_INFO_SMARTCAST!>c<!>.length() // Previous line should make as unnecessary here.
(c as String).length
return <!DEBUG_INFO_SMARTCAST!>c<!>.length // Previous line should make as unnecessary here.
}
@@ -3,7 +3,7 @@ fun x(): Boolean { return true }
public fun foo(pp: Any): Int {
var p = pp
while(true) {
(p as String).length()
(p as String).length
if (x()) break
p = 42
}
@@ -7,7 +7,7 @@ fun list(start: String) {
if (e==null) return
while (e is String) {
// Smart cast due to the loop condition
if (<!DEBUG_INFO_SMARTCAST!>e<!>.length() == 0)
if (<!DEBUG_INFO_SMARTCAST!>e<!>.length == 0)
break
// We still have smart cast here despite of a break
e = <!DEBUG_INFO_SMARTCAST!>e<!>.next()
@@ -1,10 +1,10 @@
fun foo() {
var v: String? = null
v<!UNSAFE_CALL!>.<!>length()
v<!UNSAFE_CALL!>.<!>length
v = "abc"
<!DEBUG_INFO_SMARTCAST!>v<!>.length()
<!DEBUG_INFO_SMARTCAST!>v<!>.length
v = null
v<!UNSAFE_CALL!>.<!>length()
v<!UNSAFE_CALL!>.<!>length
v = "abc"
<!DEBUG_INFO_SMARTCAST!>v<!>.length()
<!DEBUG_INFO_SMARTCAST!>v<!>.length
}
@@ -3,10 +3,10 @@ fun x(): Boolean { return true }
public fun foo(pp: String?): Int {
var p = pp
do {
p!!.length()
p!!.length
if (p == "abc") break
p = null
} while (!x())
// Smart cast is NOT possible here
return p<!UNSAFE_CALL!>.<!>length()
return p<!UNSAFE_CALL!>.<!>length
}
@@ -1,5 +1,5 @@
public fun fooNotNull(s: String) {
System.out.println("Length of $s is ${s.length()}")
System.out.println("Length of $s is ${s.length}")
}
public fun foo() {
@@ -6,7 +6,7 @@ fun get(): String? {
fun foo(): Int {
var ss:String? = get()
return if (ss != null && <!DEBUG_INFO_SMARTCAST!>ss<!>.length() > 0)
return if (ss != null && <!DEBUG_INFO_SMARTCAST!>ss<!>.length > 0)
1
else
0
@@ -1,5 +1,5 @@
public fun fooNotNull(s: String) {
System.out.println("Length of $s is ${s.length()}")
System.out.println("Length of $s is ${s.length}")
}
public fun foo() {
@@ -1,5 +1,5 @@
public fun fooNotNull(s: String) {
System.out.println("Length of $s is ${s.length()}")
System.out.println("Length of $s is ${s.length}")
}
public fun foo() {
@@ -2,20 +2,20 @@
fun f() {
var s: String?
s = "a"
var s1 = "" // String ?
var s1 = "" // String ?
if (<!SENSELESS_COMPARISON!>s != null<!>) { // Redundant
s1.length()
s1.length
// We can do smartcast here and below
s1 = <!DEBUG_INFO_SMARTCAST!>s<!>.toString() // return String?
s1.length()
s1.length
s1 = <!DEBUG_INFO_SMARTCAST!>s<!>
s1.length()
s1.length
// It's just an assignment without smartcast
val s2 = s
// But smartcast can be done here
<!DEBUG_INFO_SMARTCAST!>s2<!>.length()
<!DEBUG_INFO_SMARTCAST!>s2<!>.length
// And also here
val s3 = <!DEBUG_INFO_SMARTCAST!>s<!>.toString()
s3.length()
s3.length
}
}
@@ -1,7 +1,7 @@
fun foo() {
var v: String? = "xyz"
// It is possible in principle to provide smart cast here
v<!UNSAFE_CALL!>.<!>length()
v<!UNSAFE_CALL!>.<!>length
v = null
v<!UNSAFE_CALL!>.<!>length()
v<!UNSAFE_CALL!>.<!>length
}
@@ -5,11 +5,11 @@ public fun foo(pp: String?, rr: String?): Int {
var r = rr
do {
do {
p!!.length()
p!!.length
} while (r == null)
} while (!x())
// Auto cast possible
<!DEBUG_INFO_SMARTCAST!>r<!>.length()
<!DEBUG_INFO_SMARTCAST!>r<!>.length
// Auto cast possible
return <!DEBUG_INFO_SMARTCAST!>p<!>.length()
return <!DEBUG_INFO_SMARTCAST!>p<!>.length
}
@@ -3,17 +3,17 @@ fun x(): Boolean { return true }
public fun foo(qq: String?): Int {
var q = qq
while(true) {
q!!.length()
q!!.length
var r = q
do {
var p = r
do {
// p = r, r = q and q is not null
<!DEBUG_INFO_SMARTCAST!>p<!>.length()
<!DEBUG_INFO_SMARTCAST!>p<!>.length
} while (!x())
} while (<!SENSELESS_COMPARISON!>r == null<!>) // r = q and q is not null
if (!x()) break
}
// Smart cast is possible
return <!DEBUG_INFO_SMARTCAST!>q<!>.length()
return <!DEBUG_INFO_SMARTCAST!>q<!>.length
}
@@ -13,7 +13,7 @@ class MyClass {
m = create()
// See KT-7428
for ((k, v) in <!SMARTCAST_IMPOSSIBLE!>m<!>)
res += (k.length() + v.length())
res += (k.length + v.length)
return res
}
}
@@ -7,11 +7,11 @@ public fun foo() {
} else if (s == null) {
return -2
} else {
return s<!UNSAFE_CALL!>.<!>length() // Here smartcast is possible, at least in principle
return s<!UNSAFE_CALL!>.<!>length // Here smartcast is possible, at least in principle
}
}
if (s != null) {
System.out.println(closure())
System.out.println(s<!UNSAFE_CALL!>.<!>length()) // Here smartcast is not possible due to a closure predecessor
System.out.println(s<!UNSAFE_CALL!>.<!>length) // Here smartcast is not possible due to a closure predecessor
}
}
@@ -10,6 +10,6 @@ public fun foo() {
if (s != null) {
System.out.println(closure())
// Smart cast is possible but closure makes it harder to understand
System.out.println(s<!UNSAFE_CALL!>.<!>length())
System.out.println(s<!UNSAFE_CALL!>.<!>length)
}
}
@@ -4,6 +4,6 @@ fun get(): String? {
fun foo(): Int {
var c: String? = get()
c!!.length()
return <!DEBUG_INFO_SMARTCAST!>c<!>.length() // Previous line should make !! unnecessary here.
c!!.length
return <!DEBUG_INFO_SMARTCAST!>c<!>.length // Previous line should make !! unnecessary here.
}
@@ -1,5 +1,5 @@
fun foo(): Int {
var s: String? = <!VARIABLE_WITH_REDUNDANT_INITIALIZER!>"abc"<!>
s = null
return s<!UNSAFE_CALL!>.<!>length()
return s<!UNSAFE_CALL!>.<!>length
}

Some files were not shown because too many files have changed in this diff Show More