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 -3
View File
@@ -16,8 +16,8 @@ fun test() : Unit {
checkSubtype<Int?>(y as? Int?)
val <!UNUSED_VARIABLE!>s<!> = "" <!USELESS_CAST!>as Any<!>
("" as String?)?.length()
(data@("" as String?))?.length()
(<!WRONG_ANNOTATION_TARGET!>@MustBeDocumented()<!>( "" as String?))?.length()
("" as String?)?.length
(data@("" as String?))?.length
(<!WRONG_ANNOTATION_TARGET!>@MustBeDocumented()<!>( "" as String?))?.length
Unit
}
+1 -1
View File
@@ -60,6 +60,6 @@ public class B {
lateinit var a: String
init {
a.length()
a.length
}
}
@@ -14,7 +14,7 @@ fun box() : String {
val test5 =
"""
${s.length()}
${s.length}
"""
if (test5 != "\n 3\n") return "Fail 5: $test5"
@@ -19,7 +19,7 @@ class SomeClass {
get() = "A"
}
fun @receiver:Ann String.length2() = length()
fun @receiver:Ann String.length2() = length
val @receiver:Ann String.extensionProperty: String
get() = "A"
@@ -3,7 +3,7 @@
import kotlin.reflect.*
val String.countCharacters: Int
get() = length()
get() = length
var Int.meaning: Long
get() = 42L
@@ -1,6 +1,6 @@
fun illegalWhenBlock(a: Any): Int {
when(a) {
is Int -> return <!DEBUG_INFO_SMARTCAST!>a<!>
is String -> return <!DEBUG_INFO_SMARTCAST!>a<!>.length()
is String -> return <!DEBUG_INFO_SMARTCAST!>a<!>.length
}
<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
@@ -3,14 +3,14 @@
fun foo(o: Any) {
if (o is String) {
val s = o <!USELESS_CAST!>as String<!>
s.length()
s.length
}
}
fun foo1(o: Any) {
if (o is String) {
<!DEBUG_INFO_SMARTCAST!>o<!>.length()
<!DEBUG_INFO_SMARTCAST!>o<!>.length
val s = o
<!DEBUG_INFO_SMARTCAST!>s<!>.length()
<!DEBUG_INFO_SMARTCAST!>s<!>.length
}
}
@@ -1,12 +1,12 @@
fun test(a: Any?, flag: Boolean, x: Any?) {
if (a !is String) return
<!DEBUG_INFO_SMARTCAST!>a<!>.length()
<!DEBUG_INFO_SMARTCAST!>a<!>.length
val b: Any?
if (flag) {
b = a
<!DEBUG_INFO_SMARTCAST!>b<!>.length()
<!DEBUG_INFO_SMARTCAST!>b<!>.length
}
else {
b = x
@@ -2,7 +2,7 @@ fun test(a: Any?) {
when (a) {
is String -> {
val s = a
<!DEBUG_INFO_SMARTCAST!>s<!>.length()
<!DEBUG_INFO_SMARTCAST!>s<!>.length
}
"" -> {
val s = a
@@ -6,8 +6,8 @@ fun test(x: Any) {
if (y !is String) return
class Local {
init {
<!DEBUG_INFO_SMARTCAST!>x<!>.length()
<!DEBUG_INFO_SMARTCAST!>y<!>.length()
<!DEBUG_INFO_SMARTCAST!>x<!>.length
<!DEBUG_INFO_SMARTCAST!>y<!>.length
}
}
}
@@ -2,10 +2,10 @@ fun test(x: Any?) {
if (x !is String) return
class C {
val v = <!DEBUG_INFO_SMARTCAST!>x<!>.length()
val v = <!DEBUG_INFO_SMARTCAST!>x<!>.length
val vGet: Int
get() = <!DEBUG_INFO_SMARTCAST!>x<!>.length()
get() = <!DEBUG_INFO_SMARTCAST!>x<!>.length
val s: String = <!DEBUG_INFO_SMARTCAST!>x<!>
}
@@ -1,7 +1,7 @@
fun foo(x: Any?) {
if (x is String) {
object : Base(<!DEBUG_INFO_SMARTCAST!>x<!>) {
fun bar() = <!DEBUG_INFO_SMARTCAST!>x<!>.length()
fun bar() = <!DEBUG_INFO_SMARTCAST!>x<!>.length
}
}
}
@@ -4,7 +4,7 @@ fun test(x: Any) {
class LocalOuter {
inner class Local {
init {
<!DEBUG_INFO_SMARTCAST!>x<!>.length()
<!DEBUG_INFO_SMARTCAST!>x<!>.length
}
}
}
@@ -3,7 +3,7 @@
fun testWhen(t: String?, x: String?): Int {
return when {
t == null -> 0
x == null -> <!DEBUG_INFO_SMARTCAST!>t<!>.length() // Wrong error report here. t can be inferred as not-null. (And it actually does if you replace when with if/else if)
else -> (<!DEBUG_INFO_SMARTCAST!>t<!> + x).length()
x == null -> <!DEBUG_INFO_SMARTCAST!>t<!>.length // Wrong error report here. t can be inferred as not-null. (And it actually does if you replace when with if/else if)
else -> (<!DEBUG_INFO_SMARTCAST!>t<!> + x).length
}
}
@@ -8,7 +8,7 @@ fun test(param: String) {
val local_val = 4
val bar = fun B.(fun_param: Int) {
param.length()
param.length
b_fun()
val inner_bar = local_val + fun_param
@@ -1,13 +1,13 @@
fun <T : Any?> foo(x: T) {
if (x is String<!USELESS_NULLABLE_CHECK!>?<!>) {
x<!UNSAFE_CALL!>.<!>length()
x<!UNSAFE_CALL!>.<!>length
if (x != null) {
<!DEBUG_INFO_SMARTCAST!>x<!>.length()
<!DEBUG_INFO_SMARTCAST!>x<!>.length
}
}
if (x is String) {
<!DEBUG_INFO_SMARTCAST!>x<!>.length()
<!DEBUG_INFO_SMARTCAST!>x<!>.length
}
}
@@ -11,8 +11,8 @@ fun <T : CharSequence?> foo(x: T) {
if (x != null) {
if (<!SENSELESS_COMPARISON!>x != null<!>) {}
<!DEBUG_INFO_SMARTCAST!>x<!>.length()
x<!UNNECESSARY_SAFE_CALL!>?.<!>length()
<!DEBUG_INFO_SMARTCAST!>x<!>.length
x<!UNNECESSARY_SAFE_CALL!>?.<!>length
x.bar1()
x.bar2()
@@ -23,11 +23,11 @@ fun <T : CharSequence?> foo(x: T) {
x<!UNNECESSARY_SAFE_CALL!>?.<!>bar1()
}
x<!UNSAFE_CALL!>.<!>length()
x<!UNSAFE_CALL!>.<!>length
if (x is String) {
<!DEBUG_INFO_SMARTCAST!>x<!>.length()
<!DEBUG_INFO_SMARTCAST!>x<!><!UNNECESSARY_SAFE_CALL!>?.<!>length()
<!DEBUG_INFO_SMARTCAST!>x<!>.length
<!DEBUG_INFO_SMARTCAST!>x<!><!UNNECESSARY_SAFE_CALL!>?.<!>length
<!DEBUG_INFO_SMARTCAST!>x<!>.bar1()
x.bar2()
@@ -35,8 +35,8 @@ fun <T : CharSequence?> foo(x: T) {
}
if (x is CharSequence) {
<!DEBUG_INFO_SMARTCAST!>x<!>.length()
x<!UNNECESSARY_SAFE_CALL!>?.<!>length()
<!DEBUG_INFO_SMARTCAST!>x<!>.length
x<!UNNECESSARY_SAFE_CALL!>?.<!>length
<!DEBUG_INFO_SMARTCAST!>x<!>.bar1()
x.bar2()
@@ -10,8 +10,8 @@ fun <T : String?> T.foo() {
if (this != null) {
if (<!SENSELESS_COMPARISON!>this != null<!>) {}
length()
this<!UNNECESSARY_SAFE_CALL!>?.<!>length()
length
this<!UNNECESSARY_SAFE_CALL!>?.<!>length
bar1()
bar2()
@@ -22,11 +22,11 @@ fun <T : String?> T.foo() {
this<!UNNECESSARY_SAFE_CALL!>?.<!>bar1()
}
<!UNSAFE_CALL!>length<!>()
<!UNSAFE_CALL!>length<!>
if (this is String) {
length()
this<!UNNECESSARY_SAFE_CALL!>?.<!>length()
length
this<!UNNECESSARY_SAFE_CALL!>?.<!>length
bar1()
bar2()
@@ -8,11 +8,11 @@ fun <T : CharSequence> T.bar3() {}
fun <T, R> T.let(f: (T) -> R): R = f(this)
fun <T : String?> foo(x: T) {
x<!UNSAFE_CALL!>.<!>length()
x?.length()
x<!UNSAFE_CALL!>.<!>length
x?.length
if (1 == 1) {
x!!.length()
x!!.length
}
@@ -24,5 +24,5 @@ fun <T : String?> foo(x: T) {
x.<!TYPE_INFERENCE_UPPER_BOUND_VIOLATED!>bar3<!>()
x?.let { it<!UNSAFE_CALL!>.<!>length() }
x?.let { it<!UNSAFE_CALL!>.<!>length }
}
@@ -5,7 +5,7 @@ package n
import java.util.*
fun test() {
val foo = arrayList("").map { it -> it.length() }.fold(0, { x, y -> Math.max(x, y) })
val foo = arrayList("").map { it -> it.length }.fold(0, { x, y -> Math.max(x, y) })
checkSubtype<Int>(foo)
checkSubtype<String>(<!TYPE_MISMATCH!>foo<!>)
}
@@ -8,11 +8,11 @@ fun <T> Array<T>.forEach(operation: (T) -> Unit) : Unit { for (element in this)
fun bar(operation: (String) -> Unit) = operation("")
fun main(args: Array<String>) {
args.forEach { a : String -> a.length() } // Type mismatch: (String) -> Unit required, (String) -> Int found
args.forEach { a -> a.length() } // Type mismatch: (String) -> Unit required, (String) -> Int found
args.forEach { it.length() } // This works!
args.forEach { a : String -> a.length } // Type mismatch: (String) -> Unit required, (String) -> Int found
args.forEach { a -> a.length } // Type mismatch: (String) -> Unit required, (String) -> Int found
args.forEach { it.length } // This works!
bar { a: String -> a.length() }
bar { a -> a.length() }
bar { it.length() }
bar { a: String -> a.length }
bar { a -> a.length }
bar { it.length }
}
@@ -9,8 +9,8 @@ import java.util.*
fun foo(lines: List<String>) {
val w = max(lines, comparator {o1, o2 ->
val l1 : Int = o1.length() // Types of o1 and o2 are ERROR
val l2 = o2.length()
val l1 : Int = o1.length // Types of o1 and o2 are ERROR
val l2 = o2.length
l1 - l2
}).sure()
checkSubtype<String>(w)
+2 -2
View File
@@ -2,11 +2,11 @@
inline fun foo(bar1: (String.() -> Int) -> Int, bar2: (()->Int) -> Int) {
bar1 label@ {
this@label.length()
this@label.length
}
bar1 {
this.length()
this.length
}
//unmute after KT-4247 fix
//bar1 {
@@ -15,6 +15,6 @@ public class Y extends X<String> {
// FILE: test.kt
fun main() {
Y().foo().length()
Y().foo().length
Y().bar(null)
}
@@ -2,20 +2,20 @@ package
public open class C : kotlin.CharSequence {
public constructor C()
public open override /*1*/ val length: kotlin.Int
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
@java.lang.Override() public open override /*1*/ fun get(/*0*/ index: kotlin.Int): kotlin.Char
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
@java.lang.Override() public open override /*1*/ fun length(): kotlin.Int
@java.lang.Override() public open override /*1*/ fun subSequence(/*0*/ start: kotlin.Int, /*1*/ end: kotlin.Int): kotlin.CharSequence
@java.lang.Override() public open override /*1*/ fun toString(): kotlin.String
}
public final class T : C {
public constructor T()
public open override /*1*/ /*fake_override*/ val length: kotlin.Int
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
@java.lang.Override() public open override /*1*/ /*fake_override*/ fun get(/*0*/ index: kotlin.Int): kotlin.Char
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
@java.lang.Override() public open override /*1*/ /*fake_override*/ fun length(): kotlin.Int
@java.lang.Override() public open override /*1*/ /*fake_override*/ fun subSequence(/*0*/ start: kotlin.Int, /*1*/ end: kotlin.Int): kotlin.CharSequence
@java.lang.Override() public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
+2 -2
View File
@@ -2,10 +2,10 @@
fun foo(bar1: (String.() -> Int) -> Int) {
bar1 {
this.length()
this.length
}
bar1 {
this@bar1.length()
this@bar1.length
}
}
@@ -5,18 +5,18 @@ package kt244
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
<!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
val b = if (a != null) <!DEBUG_INFO_SMARTCAST!>a<!>.length else 1
init {
if (a != null) {
val <!UNUSED_VARIABLE!>c<!> = <!DEBUG_INFO_SMARTCAST!>a<!>.length()
val <!UNUSED_VARIABLE!>c<!> = <!DEBUG_INFO_SMARTCAST!>a<!>.length
}
}
@@ -24,7 +24,7 @@ class A(a: String?) {
init {
if (a is String) {
i = <!DEBUG_INFO_SMARTCAST!>a<!>.length()
i = <!DEBUG_INFO_SMARTCAST!>a<!>.length
}
else {
i = 3
+2 -2
View File
@@ -8,10 +8,10 @@ fun withLambda(o : Int, block : Int.(String) -> Unit) {
fun test() {
withLambda {
it.length()
it.length
}
withLambda { r -> // no error should be here
r.length()
r.length
}
}
+2 -2
View File
@@ -8,10 +8,10 @@ fun withLambda(block : Int.(String, String) -> Unit) {
fun test() {
withLambda { r ->
r.length()
r.length
}
withLambda { x, y ->
x.length() + y.length()
x.length + y.length
}
}
@@ -21,8 +21,8 @@ fun test(j: J) {
j.j()!!.j()
val ann = j.foo<String>()
ann!!.length()
ann.length()
ann!!.length
ann.length
val a = j.foo<J>()
a!!.j()
+1 -1
View File
@@ -12,5 +12,5 @@ public class J {
import p.*
fun test(j: J) {
j.s()?.length() ?: ""
j.s()?.length ?: ""
}
@@ -14,7 +14,7 @@ public class J {
// FILE: k.kt
fun safeCall(c: J?) {
c?.nn()?.length()
c?.nn()?.length
}
fun ifelse(c: J): Any? {
@@ -16,7 +16,7 @@ public class J {
fun foo(collection: Collection<J>) {
val mapped = collection.map { it.method() }
mapped[0]<!UNSAFE_CALL!>.<!>length()
mapped[0]<!UNSAFE_CALL!>.<!>length
}
public fun <T, R> Iterable<T>.map(transform: (T) -> R): List<R> {
@@ -4,6 +4,6 @@ fun foo() {
val list = ArrayList<String?>()
for (s in list) {
s<!UNSAFE_CALL!>.<!>length()
s<!UNSAFE_CALL!>.<!>length
}
}
@@ -11,5 +11,5 @@ public class J {
import p.*
fun test(j: J) {
j.s()?.length().checkType { _<Int?>() }
j.s()?.length.checkType { _<Int?>() }
}
@@ -9,7 +9,7 @@ fun takeFirst(expr: StringBuilder): Char {
}
fun evaluateArg(expr: CharSequence, numbers: ArrayList<Int>): Int {
if (expr.length() == 0) throw Exception("Syntax error: Character expected");
if (expr.length == 0) throw Exception("Syntax error: Character expected");
val c = takeFirst(<!TYPE_MISMATCH!>expr<!>)
if (c >= '0' && c <= '9') {
val n = c - '0'
@@ -22,7 +22,7 @@ fun evaluateArg(expr: CharSequence, numbers: ArrayList<Int>): Int {
fun evaluateAdd(expr: StringBuilder, numbers: ArrayList<Int>): Int {
val lhs = evaluateArg(expr, numbers)
if (expr.length() > 0) {
if (expr.length > 0) {
}
return lhs
@@ -30,7 +30,7 @@ fun evaluateAdd(expr: StringBuilder, numbers: ArrayList<Int>): Int {
fun evaluate(expr: StringBuilder, numbers: ArrayList<Int>): Int {
val lhs = evaluateAdd(expr, numbers)
if (expr.length() > 0) {
if (expr.length > 0) {
val <!UNUSED_VARIABLE!>c<!> = expr.get(0)
expr.deleteCharAt(0)
}
+1 -1
View File
@@ -3,7 +3,7 @@ package jet121
fun box() : String {
val answer = apply("OK") {
get(0)
length()
length
}
return if (answer == 2) "OK" else "FAIL"
+1 -1
View File
@@ -11,7 +11,7 @@ package demo
}
fun main(args : Array<String>) {
for (a in filter(args, {it.length() > 1})) {
for (a in filter(args, {it.length > 1})) {
System.out.println("Hello, ${a}!")
}
}
+2 -2
View File
@@ -11,9 +11,9 @@ fun main() {
val diffs = ArrayList<Int>()
for (i in vals.indices) {
for (j in i..vals.lastIndex()) // Type inference failed
diffs.add(vals[i].length() - vals[j].length())
diffs.add(vals[i].length - vals[j].length)
for (j in i..vals.lastIndex) // Type inference failed
diffs.add(vals[i].length() - vals[j].length())
diffs.add(vals[i].length - vals[j].length)
}
}
@@ -5,5 +5,5 @@
fun foo(i: Int) {}
fun test(s: String?) {
foo(<!TYPE_MISMATCH!>s?.length()<!>)
foo(<!TYPE_MISMATCH!>s?.length<!>)
}
+4 -4
View File
@@ -3,16 +3,16 @@ package kt939
//KT-939 CommonSupertypes erases scopes associated to types
fun compare(o1 : String?, o2 : String?) : Int {
val l1 = o1?.length() ?: 0
val l2 = o2?.length() ?: 0
val l1 = o1?.length ?: 0
val l2 = o2?.length ?: 0
return l1 - l2 // '-' is unresolved, because the type of l1 is Int with an empty member scope
}
//KT-1117 Unresolved reference to multiply sign
fun test() {
(System.getProperty("path.separator")?.length() ?: 4) * 55 + 5
(System.getProperty("path.separator")?.length ?: 4) * 55 + 5
val x = System.getProperty("path.separator")?.length() ?: 4
val x = System.getProperty("path.separator")?.length ?: 4
x * 55 + 5
}
@@ -1,7 +1,7 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
class A {
constructor(x: Any, y: Any, z: Any)
constructor(x: String?, y: String?): this(x!!, <!DEBUG_INFO_SMARTCAST!>x<!>.length().toString() + y!!, "") {
<!DEBUG_INFO_SMARTCAST!>x<!>.length() + <!DEBUG_INFO_SMARTCAST!>y<!>.length()
constructor(x: String?, y: String?): this(x!!, <!DEBUG_INFO_SMARTCAST!>x<!>.length.toString() + y!!, "") {
<!DEBUG_INFO_SMARTCAST!>x<!>.length + <!DEBUG_INFO_SMARTCAST!>y<!>.length
}
}
@@ -34,7 +34,7 @@ enum class D(val prop: Int) {
};
constructor(): this(1)
constructor(x: String): this(x.length())
constructor(x: String): this(x.length)
abstract fun f(): Int
}
@@ -2,7 +2,7 @@
fun <T> array(vararg x: T): Array<T> = null!!
open class B(x: Int) {
constructor(vararg y: String): this(y[0].length())
constructor(vararg y: String): this(y[0].length)
}
class A : B {
@@ -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
}

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