Rename: auto cast -> smart cast

This commit is contained in:
Svetlana Isakova
2014-09-29 23:09:05 +04:00
parent 20f3403c80
commit ce01c61811
294 changed files with 840 additions and 842 deletions
@@ -1,4 +1,4 @@
// !DIAGNOSTICS: -DEBUG_INFO_AUTOCAST
// !DIAGNOSTICS: -DEBUG_INFO_SMARTCAST
fun bar(x: Int): Int = x + 1
fun foo() {
@@ -4,10 +4,10 @@ fun foo() {
val x: Int? = null
val a = Array<Int>(3, {0})
if (x != null) bar(a[<!DEBUG_INFO_AUTOCAST!>x<!>]) else bar(a[<!TYPE_MISMATCH!>x<!>])
bar(a[if (x == null) 0 else <!DEBUG_INFO_AUTOCAST!>x<!>])
if (x != null) bar(a[<!DEBUG_INFO_SMARTCAST!>x<!>]) else bar(a[<!TYPE_MISMATCH!>x<!>])
bar(a[if (x == null) 0 else <!DEBUG_INFO_SMARTCAST!>x<!>])
bar(a[<!TYPE_MISMATCH!>x<!>])
"123"[<!TYPE_MISMATCH!>x<!>];
if (x != null) "123"[<!DEBUG_INFO_AUTOCAST!>x<!>];
if (x != null) "123"[<!DEBUG_INFO_SMARTCAST!>x<!>];
}
@@ -1,5 +1,5 @@
fun foo(arr: Array<out Number>): Int {
val result = (arr as Array<Int>)[0]
<!DEBUG_INFO_AUTOCAST!>arr<!> : Array<Int>
<!DEBUG_INFO_SMARTCAST!>arr<!> : Array<Int>
return result
}
@@ -4,23 +4,23 @@ trait G {
}
fun foo1(a: Int?, b: G) {
b[a!!, a<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>] = <!DEBUG_INFO_AUTOCAST!>a<!>
<!DEBUG_INFO_AUTOCAST!>a<!> : Int
b[a!!, a<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>] = <!DEBUG_INFO_SMARTCAST!>a<!>
<!DEBUG_INFO_SMARTCAST!>a<!> : Int
}
fun foo2(a: Int?, b: G) {
b[0, a!!] = <!DEBUG_INFO_AUTOCAST!>a<!>
<!DEBUG_INFO_AUTOCAST!>a<!> : Int
b[0, a!!] = <!DEBUG_INFO_SMARTCAST!>a<!>
<!DEBUG_INFO_SMARTCAST!>a<!> : Int
}
fun foo3(a: Int?, b: G) {
val r = b[a!!, <!DEBUG_INFO_AUTOCAST!>a<!>]
<!DEBUG_INFO_AUTOCAST!>a<!> : Int
val r = b[a!!, <!DEBUG_INFO_SMARTCAST!>a<!>]
<!DEBUG_INFO_SMARTCAST!>a<!> : Int
r : Int
}
fun foo4(a: Int?, b: G) {
val r = b[0, a!!]
<!DEBUG_INFO_AUTOCAST!>a<!> : Int
<!DEBUG_INFO_SMARTCAST!>a<!> : Int
r : Int
}
@@ -1,9 +1,9 @@
fun foo1(a: Int?, b: Array<Array<Int>>) {
b[a!!][a<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>] = <!DEBUG_INFO_AUTOCAST!>a<!>
<!DEBUG_INFO_AUTOCAST!>a<!> : Int
b[a!!][a<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>] = <!DEBUG_INFO_SMARTCAST!>a<!>
<!DEBUG_INFO_SMARTCAST!>a<!> : Int
}
fun foo2(a: Int?, b: Array<Array<Int>>) {
b[0][a!!] = <!DEBUG_INFO_AUTOCAST!>a<!>
<!DEBUG_INFO_AUTOCAST!>a<!> : Int
b[0][a!!] = <!DEBUG_INFO_SMARTCAST!>a<!>
<!DEBUG_INFO_SMARTCAST!>a<!> : Int
}
@@ -5,13 +5,13 @@ trait B : A {
fun bar1(a: A) {
var b: B = a as B
<!DEBUG_INFO_AUTOCAST!>a<!>.foo()
<!DEBUG_INFO_SMARTCAST!>a<!>.foo()
b.foo()
}
fun id(b: B) = b
fun bar2(a: A) {
var b: B = id(a as B)
<!DEBUG_INFO_AUTOCAST!>a<!>.foo()
<!DEBUG_INFO_SMARTCAST!>a<!>.foo()
b.foo()
}
@@ -10,12 +10,12 @@ fun baz(b: B) = b
fun bar1(a: A) {
val b = a as B
<!DEBUG_INFO_AUTOCAST!>a<!>.foo()
<!DEBUG_INFO_SMARTCAST!>a<!>.foo()
b.foo()
}
fun bar2(a: A) {
val b = baz(a as B)
<!DEBUG_INFO_AUTOCAST!>a<!>.foo()
<!DEBUG_INFO_SMARTCAST!>a<!>.foo()
b.foo()
}
@@ -1,15 +1,15 @@
fun bar1(x: Number, y: Int) {
var yy = y
yy += x as Int
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
}
fun bar2(x: Number) {
<!UNRESOLVED_REFERENCE!>y<!> <!UNRESOLVED_REFERENCE!>+=<!> x as Int
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
}
fun bar3(x: Number, y: Array<Int>) {
y[0] += x as Int
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
}
@@ -1,10 +1,10 @@
fun arrayAccessRHS(a: Int?, b: Array<Int>) {
b[0] = a!!
<!DEBUG_INFO_AUTOCAST!>a<!> : Int
<!DEBUG_INFO_SMARTCAST!>a<!> : Int
}
fun arrayAccessLHS(a: Int?, b: Array<Int>) {
b[a!!] = <!DEBUG_INFO_AUTOCAST!>a<!>
<!DEBUG_INFO_AUTOCAST!>a<!> : Int
b[a!!] = <!DEBUG_INFO_SMARTCAST!>a<!>
<!DEBUG_INFO_SMARTCAST!>a<!> : Int
}
@@ -1,4 +1,4 @@
// !DIAGNOSTICS: -DEBUG_INFO_AUTOCAST
// !DIAGNOSTICS: -DEBUG_INFO_SMARTCAST
fun bar(x: Int): Int = x + 1
fun foo() {
@@ -6,7 +6,7 @@ fun foo1(x: Number, cond: Boolean): Boolean {
fun foo2(x: Number, cond: Boolean): Boolean {
val result = ((x as Int) == 42) && cond
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
return result
}
@@ -18,6 +18,6 @@ fun foo3(x: Number, cond: Boolean): Boolean {
fun foo4(x: Number, cond: Boolean): Boolean {
val result = ((x as Int) == 42) || cond
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
return result
}
@@ -4,13 +4,13 @@ trait B : A
fun B.compareTo(b: B) = if (this == b) 0 else 1
fun foo(a: A): Boolean {
val result = (a as B) < <!DEBUG_INFO_AUTOCAST!>a<!>
<!DEBUG_INFO_AUTOCAST!>a<!> : B
val result = (a as B) < <!DEBUG_INFO_SMARTCAST!>a<!>
<!DEBUG_INFO_SMARTCAST!>a<!> : B
return result
}
fun bar(a: A, b: B): Boolean {
val result = b < (a as B)
<!DEBUG_INFO_AUTOCAST!>a<!> : B
<!DEBUG_INFO_SMARTCAST!>a<!> : B
return result
}
@@ -1,5 +1,5 @@
fun foo(x: Number): Boolean {
val result = (x as Int) in 1..5
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
return result
}
@@ -1,8 +1,8 @@
fun foo(x: Int?): Int = x!!
fun elvis(x: Number?): Int {
val result = (x as Int?) ?: foo(<!DEBUG_INFO_AUTOCAST!>x<!>)
<!DEBUG_INFO_AUTOCAST!>x<!> : Int?
val result = (x as Int?) ?: foo(<!DEBUG_INFO_SMARTCAST!>x<!>)
<!DEBUG_INFO_SMARTCAST!>x<!> : Int?
return result
}
@@ -3,12 +3,12 @@ trait B : A
fun foo1(a: A, b: B): Boolean {
val result = (a as B) == b
<!DEBUG_INFO_AUTOCAST!>a<!> : B
<!DEBUG_INFO_SMARTCAST!>a<!> : B
return result
}
fun foo2(a: A, b: B): Boolean {
val result = b == (a as B)
<!DEBUG_INFO_AUTOCAST!>a<!> : B
<!DEBUG_INFO_SMARTCAST!>a<!> : B
return result
}
@@ -1,11 +1,11 @@
fun foo(a: Number): Int {
val result = (a as Int) compareTo <!DEBUG_INFO_AUTOCAST!>a<!>
<!DEBUG_INFO_AUTOCAST!>a<!> : Int
val result = (a as Int) compareTo <!DEBUG_INFO_SMARTCAST!>a<!>
<!DEBUG_INFO_SMARTCAST!>a<!> : Int
return result
}
fun bar(a: Number): Int {
val result = 42 compareTo (a as Int)
<!DEBUG_INFO_AUTOCAST!>a<!> : Int
<!DEBUG_INFO_SMARTCAST!>a<!> : Int
return result
}
@@ -4,13 +4,13 @@ trait B : A
fun B.plus(b: B) = if (this == b) b else this
fun foo(a: A): B {
val result = (a as B) + <!DEBUG_INFO_AUTOCAST!>a<!>
<!DEBUG_INFO_AUTOCAST!>a<!> : B
val result = (a as B) + <!DEBUG_INFO_SMARTCAST!>a<!>
<!DEBUG_INFO_SMARTCAST!>a<!> : B
return result
}
fun bar(a: A, b: B): B {
val result = b + (a as B)
<!DEBUG_INFO_AUTOCAST!>a<!> : B
<!DEBUG_INFO_SMARTCAST!>a<!> : B
return result
}
@@ -1,5 +1,5 @@
fun foo(x: Int?): Boolean {
val result = ((x!! == 0) && ((<!DEBUG_INFO_AUTOCAST!>x<!> : Int) == 0))
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
val result = ((x!! == 0) && ((<!DEBUG_INFO_SMARTCAST!>x<!> : Int) == 0))
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
return result
}
@@ -5,7 +5,7 @@ fun whileLoop(x: Int?) {
}
<!TYPE_MISMATCH!>x<!> : Int
}
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
}
fun doWhileLoop(x: Int?) {
@@ -15,7 +15,7 @@ fun doWhileLoop(x: Int?) {
} while (x == null)
<!TYPE_MISMATCH!>x<!> : Int
}
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
}
fun whileLoopContinueInnerOuter(x: Int?) {
@@ -26,7 +26,7 @@ fun whileLoopContinueInnerOuter(x: Int?) {
}
<!TYPE_MISMATCH!>x<!> : Int
}
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
}
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
}
@@ -1,4 +1,4 @@
// !DIAGNOSTICS: -DEBUG_INFO_AUTOCAST
// !DIAGNOSTICS: -DEBUG_INFO_SMARTCAST
fun bar(x: Int) = x + 1
fun foo() {
@@ -6,7 +6,7 @@ fun foo() {
do {
bar(<!TYPE_MISMATCH!>x<!>)
} while (x == null)
bar(<!DEBUG_INFO_AUTOCAST!>x<!>)
bar(<!DEBUG_INFO_SMARTCAST!>x<!>)
val y: Int? = null
do {
@@ -4,7 +4,7 @@ fun simpleDoWhile(x: Int?, y0: Int) {
x : Int?
y++
} while (x!! == y)
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
}
fun doWhileWithBreak(x: Int?, y0: Int) {
@@ -4,6 +4,6 @@ fun foo() {
val x: Int? = null
bar(x ?: 0)
if (x != null) bar(<!USELESS_ELVIS!>x<!> ?: <!DEBUG_INFO_AUTOCAST!>x<!>)
if (x != null) bar(<!USELESS_ELVIS!>x<!> ?: <!DEBUG_INFO_SMARTCAST!>x<!>)
bar(<!TYPE_MISMATCH!>x<!>)
}
@@ -1,5 +1,3 @@
import java.util.HashMap
fun bar(x: Int): Int = x + 1
fun foo() {
@@ -9,16 +7,16 @@ fun foo() {
for (p in a) {
bar(<!TYPE_MISMATCH!>x<!>)
if (x == null) continue
bar(<!DEBUG_INFO_AUTOCAST!>x<!>)
bar(<!DEBUG_INFO_SMARTCAST!>x<!>)
for (q in a) {
bar(<!DEBUG_INFO_AUTOCAST!>x<!>)
if (<!SENSELESS_COMPARISON!>x == null<!>) bar(<!DEBUG_INFO_AUTOCAST!>x<!>)
bar(<!DEBUG_INFO_SMARTCAST!>x<!>)
if (<!SENSELESS_COMPARISON!>x == null<!>) bar(<!DEBUG_INFO_SMARTCAST!>x<!>)
}
}
for (p in a) {
bar(<!TYPE_MISMATCH!>x<!>)
if (x == null) break
bar(<!DEBUG_INFO_AUTOCAST!>x<!>)
bar(<!DEBUG_INFO_SMARTCAST!>x<!>)
}
}
@@ -1,6 +1,6 @@
fun foo(arr: Array<Int>?) {
for (x in arr!!) {
<!DEBUG_INFO_AUTOCAST!>arr<!> : Array<Int>
<!DEBUG_INFO_SMARTCAST!>arr<!> : Array<Int>
}
<!DEBUG_INFO_AUTOCAST!>arr<!> : Array<Int>
<!DEBUG_INFO_SMARTCAST!>arr<!> : Array<Int>
}
@@ -4,6 +4,6 @@ fun foo() {
val x: Int? = null
fun baz() = bar(<!TYPE_MISMATCH!>x<!>)
fun quux() = if (x != null) bar(<!DEBUG_INFO_AUTOCAST!>x<!>) else baz()
fun quuux() = bar(if (x == null) 0 else <!DEBUG_INFO_AUTOCAST!>x<!>)
fun quux() = if (x != null) bar(<!DEBUG_INFO_SMARTCAST!>x<!>) else baz()
fun quuux() = bar(if (x == null) 0 else <!DEBUG_INFO_SMARTCAST!>x<!>)
}
@@ -1,24 +1,24 @@
fun ifThen(x: Int?) {
if (x!! == 0) {
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
}
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
}
fun ifElse(x: Int?) {
if (x!! == 0) else {
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
}
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
}
fun ifThenElse(x: Int?) {
if (x!! == 0) {
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
} else {
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
}
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
}
fun ifIs(x: Int?, cond: Boolean) {
@@ -3,27 +3,27 @@ fun bar(x: Int): Int = x + 1
fun foo() {
val x: Int? = null
bar(if (x == null) 0 else <!DEBUG_INFO_AUTOCAST!>x<!>)
bar(if (x == null) 0 else <!DEBUG_INFO_SMARTCAST!>x<!>)
if (x == null) {
bar(<!TYPE_MISMATCH!>x<!>)
return
} else {
bar(<!DEBUG_INFO_AUTOCAST!>x<!>)
bar(<!DEBUG_INFO_SMARTCAST!>x<!>)
}
bar(<!DEBUG_INFO_AUTOCAST!>x<!>)
bar(<!DEBUG_INFO_SMARTCAST!>x<!>)
val y: Int? = null
if (y is Int) {
bar(<!DEBUG_INFO_AUTOCAST!>y<!>)
bar(<!DEBUG_INFO_SMARTCAST!>y<!>)
} else {
bar(<!TYPE_MISMATCH!>y<!>)
return
}
bar(<!DEBUG_INFO_AUTOCAST!>y<!>)
bar(<!DEBUG_INFO_SMARTCAST!>y<!>)
val z: Int? = null
if (z != null) bar(<!DEBUG_INFO_AUTOCAST!>z<!>)
if (z != null) bar(<!DEBUG_INFO_SMARTCAST!>z<!>)
bar(<!TYPE_MISMATCH!>z<!>)
bar(z!!)
if (<!SENSELESS_COMPARISON!>z != null<!>) bar(z<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>)
@@ -12,5 +12,5 @@ fun foo() {
if (<!SENSELESS_COMPARISON!>x == null<!>) return
2<!OVERLOAD_RESOLUTION_AMBIGUITY!>+<!><!SYNTAX!><!>
}
bar(<!DEBUG_INFO_AUTOCAST!>x<!>)
bar(<!DEBUG_INFO_SMARTCAST!>x<!>)
}
@@ -1,6 +1,6 @@
fun foo(x: Number) {
if ((x as Int) is Int) {
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
}
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
}
@@ -2,6 +2,6 @@ fun Int.component1() = "a"
fun foo(a: Number) {
val (x) = a as Int
<!DEBUG_INFO_AUTOCAST!>a<!> : Int
<!DEBUG_INFO_SMARTCAST!>a<!> : Int
x : String
}
@@ -4,7 +4,7 @@ fun foo() {
val x: Int? = null
val <!UNUSED_VARIABLE!>a<!> = object {
fun baz() = bar(if (x == null) 0 else <!DEBUG_INFO_AUTOCAST!>x<!>)
fun quux(): Int = if (x == null) <!TYPE_MISMATCH!>x<!> else <!DEBUG_INFO_AUTOCAST!>x<!>
fun baz() = bar(if (x == null) 0 else <!DEBUG_INFO_SMARTCAST!>x<!>)
fun quux(): Int = if (x == null) <!TYPE_MISMATCH!>x<!> else <!DEBUG_INFO_SMARTCAST!>x<!>
}
}
@@ -9,5 +9,5 @@ fun foo() {
A().bar(<!TYPE_MISMATCH!>x<!>)
if (x == null) return
A().bar(<!DEBUG_INFO_AUTOCAST!>x<!>)
A().bar(<!DEBUG_INFO_SMARTCAST!>x<!>)
}
@@ -1,4 +1,4 @@
// !DIAGNOSTICS: -DEBUG_INFO_AUTOCAST
// !DIAGNOSTICS: -DEBUG_INFO_SMARTCAST
fun bar(x: Int): Int = x + 1
fun foo(): Int {
@@ -1,6 +1,6 @@
fun foo(x: Number, y: String?): String {
val result = "abcde $x ${x as Int} ${y!!} $x $y"
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
<!DEBUG_INFO_AUTOCAST!>y<!> : String
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
<!DEBUG_INFO_SMARTCAST!>y<!> : String
return result
}
@@ -11,11 +11,11 @@ class Derived : Base() {
super.bar(<!TYPE_MISMATCH!>x<!>)
this.baz(<!TYPE_MISMATCH!>x<!>)
if (x == null) return
super.bar(<!DEBUG_INFO_AUTOCAST!>x<!>)
this.baz(<!DEBUG_INFO_AUTOCAST!>x<!>)
super.bar(<!DEBUG_INFO_SMARTCAST!>x<!>)
this.baz(<!DEBUG_INFO_SMARTCAST!>x<!>)
val y: Int? = null
if (y != null) super.bar(this.baz(<!DEBUG_INFO_AUTOCAST!>y<!>))
if (y != null) super.bar(this.baz(<!DEBUG_INFO_SMARTCAST!>y<!>))
else this.baz(super.bar(<!TYPE_MISMATCH!>y<!>))
}
}
@@ -4,6 +4,6 @@ fun foo() {
val x: Int? = null
if (x == null) throw bar(<!TYPE_MISMATCH!>x<!>)
throw bar(<!DEBUG_INFO_AUTOCAST!>x<!>)
<!UNREACHABLE_CODE!>throw bar(<!DEBUG_INFO_AUTOCAST!>x<!>)<!>
throw bar(<!DEBUG_INFO_SMARTCAST!>x<!>)
<!UNREACHABLE_CODE!>throw bar(<!DEBUG_INFO_SMARTCAST!>x<!>)<!>
}
@@ -6,10 +6,10 @@ fun foo() {
bar(<!TYPE_MISMATCH!>x<!>)
if (x == null) return
try {
bar(<!DEBUG_INFO_AUTOCAST!>x<!>)
bar(<!DEBUG_INFO_SMARTCAST!>x<!>)
}
catch (e: Exception) {
bar(<!DEBUG_INFO_AUTOCAST!>x<!>)
bar(<!DEBUG_INFO_SMARTCAST!>x<!>)
}
bar(<!DEBUG_INFO_AUTOCAST!>x<!>)
bar(<!DEBUG_INFO_SMARTCAST!>x<!>)
}
@@ -3,7 +3,7 @@ fun tryFinally(x: Int?) {
} finally {
x!!
}
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
}
fun tryCatchFinally(x: Int?) {
@@ -15,5 +15,5 @@ fun tryCatchFinally(x: Int?) {
<!TYPE_MISMATCH!>x<!> : Int
x!!
}
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
}
@@ -5,10 +5,10 @@ fun foo() {
val x: Int? = null
bar(<!UNSAFE_CALL!>-<!>x)
if (x != null) bar(-<!DEBUG_INFO_AUTOCAST!>x<!>)
if (x != null) bar(-<!DEBUG_INFO_SMARTCAST!>x<!>)
bar(<!UNSAFE_CALL!>-<!>x)
val b: Boolean? = null
baz(<!UNSAFE_CALL!>!<!>b)
if (b != null) baz(!<!DEBUG_INFO_AUTOCAST!>b<!>)
if (b != null) baz(!<!DEBUG_INFO_SMARTCAST!>b<!>)
}
@@ -5,7 +5,7 @@ fun foo() {
if (x != null) {
when (x) {
0 -> bar(<!DEBUG_INFO_AUTOCAST!>x<!>)
0 -> bar(<!DEBUG_INFO_SMARTCAST!>x<!>)
else -> {}
}
}
@@ -14,5 +14,5 @@ fun foo() {
0 -> { if (<!SENSELESS_COMPARISON!>x == null<!>) return }
else -> { if (x == null) return }
}
bar(<!DEBUG_INFO_AUTOCAST!>x<!>)
bar(<!DEBUG_INFO_SMARTCAST!>x<!>)
}
@@ -1,24 +1,24 @@
fun foo(x: Number, y: Int) {
when (x) {
x as Int -> <!DEBUG_INFO_AUTOCAST!>x<!> : Int
x as Int -> <!DEBUG_INFO_SMARTCAST!>x<!> : Int
y -> {}
else -> {}
}
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
}
fun bar(x: Number) {
when (x) {
x as Int -> <!DEBUG_INFO_AUTOCAST!>x<!> : Int
x as Int -> <!DEBUG_INFO_SMARTCAST!>x<!> : Int
else -> {}
}
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
}
fun whenWithoutSubject(x: Number) {
when {
(x as Int) == 42 -> <!DEBUG_INFO_AUTOCAST!>x<!> : Int
(x as Int) == 42 -> <!DEBUG_INFO_SMARTCAST!>x<!> : Int
else -> {}
}
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
}
@@ -1,6 +1,6 @@
fun foo(x: Number, y: Int) {
when (x) {
is Int -> <!DEBUG_INFO_AUTOCAST!>x<!> : Int
is Int -> <!DEBUG_INFO_SMARTCAST!>x<!> : Int
y -> {}
else -> {}
}
@@ -9,7 +9,7 @@ fun foo(x: Number, y: Int) {
fun bar(x: Number) {
when (x) {
is Int -> <!DEBUG_INFO_AUTOCAST!>x<!> : Int
is Int -> <!DEBUG_INFO_SMARTCAST!>x<!> : Int
else -> {}
}
<!TYPE_MISMATCH!>x<!> : Int
@@ -17,7 +17,7 @@ fun bar(x: Number) {
fun whenWithoutSubject(x: Number) {
when {
(x is Int) -> <!DEBUG_INFO_AUTOCAST!>x<!> : Int
(x is Int) -> <!DEBUG_INFO_SMARTCAST!>x<!> : Int
else -> {}
}
<!TYPE_MISMATCH!>x<!> : Int
@@ -1,13 +1,13 @@
fun foo(x: Int, list: List<Int>?) {
when (x) {
in list!! -> <!DEBUG_INFO_AUTOCAST!>list<!> : List<Int>
in list!! -> <!DEBUG_INFO_SMARTCAST!>list<!> : List<Int>
else -> {}
}
}
fun whenWithoutSubject(x: Int, list: List<Int>?) {
when {
x in list!! -> <!DEBUG_INFO_AUTOCAST!>list<!> : List<Int>
x in list!! -> <!DEBUG_INFO_SMARTCAST!>list<!> : List<Int>
else -> {}
}
}
@@ -1,6 +1,6 @@
fun foo(x: Number) {
when (x as Int) {
else -> <!DEBUG_INFO_AUTOCAST!>x<!> : Int
else -> <!DEBUG_INFO_SMARTCAST!>x<!> : Int
}
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
}
@@ -5,11 +5,11 @@ fun foo() {
while (x == null) {
bar(<!TYPE_MISMATCH!>x<!>)
}
bar(<!DEBUG_INFO_AUTOCAST!>x<!>)
bar(<!DEBUG_INFO_SMARTCAST!>x<!>)
val y: Int? = null
while (y != null) {
bar(<!DEBUG_INFO_AUTOCAST!>y<!>)
bar(<!DEBUG_INFO_SMARTCAST!>y<!>)
}
bar(<!TYPE_MISMATCH!>y<!>)
@@ -1,19 +1,19 @@
fun simpleWhile(x: Int?, y0: Int) {
var y = y0
while (x!! == y) {
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
y++
}
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
}
fun whileWithBreak(x: Int?, y0: Int) {
var y = y0
while (x!! == y) {
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
break
}
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
}
fun whileWithNoCondition(x: Int?) {
@@ -1,9 +1,9 @@
//KT-4332 when/autocast underperforms
//KT-4332 when/smartcast underperforms
fun testWhen(t: String?, x: String?): Int {
return when {
t == null -> 0
x == null -> <!DEBUG_INFO_AUTOCAST!>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_AUTOCAST!>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
}
}
@@ -3,7 +3,7 @@
fun foo(s: String?) {
when {
s == null -> <!UNUSED_EXPRESSION!>1<!>
<!DEBUG_INFO_AUTOCAST!>s<!>.foo() -> <!UNUSED_EXPRESSION!>2<!>
<!DEBUG_INFO_SMARTCAST!>s<!>.foo() -> <!UNUSED_EXPRESSION!>2<!>
else -> <!UNUSED_EXPRESSION!>3<!>
}
}
@@ -8,6 +8,6 @@ class B: A() {
fun foo(a: A) = when {
a !is B -> 2
true -> <!DEBUG_INFO_AUTOCAST!>a<!>.foo() //'foo' is unresolved, smart cast doesn't work
else -> <!DEBUG_INFO_AUTOCAST!>a<!>.foo()
true -> <!DEBUG_INFO_SMARTCAST!>a<!>.foo() //'foo' is unresolved, smart cast doesn't work
else -> <!DEBUG_INFO_SMARTCAST!>a<!>.foo()
}
@@ -0,0 +1,16 @@
trait B {
fun bar() {}
}
class C() {
fun bar() {
}
}
fun test(a : Any?) {
if (a is B) {
if (a is C) {
a.<!OVERLOAD_RESOLUTION_AMBIGUITY!>bar<!>();
}
}
}
@@ -0,0 +1,18 @@
package
internal fun test(/*0*/ a: kotlin.Any?): kotlin.Unit
internal trait B {
internal open fun bar(): kotlin.Unit
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
}
internal final class C {
public constructor C()
internal final fun bar(): kotlin.Unit
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,92 @@
// FILE: a.kt
package example.ns
val y : Any? = 2
// FILE: b.kt
package example
object Obj {
val y : Any? = 2
}
class AClass() {
class object {
val y : Any? = 2
}
}
val x : Any? = 1
fun Any?.vars(<!UNUSED_PARAMETER!>a<!>: Any?) : Int {
var <!ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE!>b<!>: Int = 0
if (ns.y is Int) {
b = <!UNUSED_VALUE, DEBUG_INFO_SMARTCAST!>ns.y<!>
}
if (ns.y is Int) {
b = <!UNUSED_VALUE, DEBUG_INFO_SMARTCAST!>example.ns.y<!>
}
if (example.ns.y is Int) {
b = <!UNUSED_VALUE, DEBUG_INFO_SMARTCAST!>ns.y<!>
}
if (example.ns.y is Int) {
b = <!UNUSED_VALUE, DEBUG_INFO_SMARTCAST!>example.ns.y<!>
}
// if (package.bottles.ns.y is Int) {
// b = ns.y
// }
if (Obj.y is Int) {
b = <!UNUSED_VALUE, DEBUG_INFO_SMARTCAST!>Obj.y<!>
}
if (example.Obj.y is Int) {
b = <!UNUSED_VALUE, DEBUG_INFO_SMARTCAST!>Obj.y<!>
}
if (AClass.y is Int) {
b = <!UNUSED_VALUE, DEBUG_INFO_SMARTCAST!>AClass.y<!>
}
if (example.AClass.y is Int) {
b = <!UNUSED_VALUE, DEBUG_INFO_SMARTCAST!>AClass.y<!>
}
if (x is Int) {
b = <!UNUSED_VALUE, DEBUG_INFO_SMARTCAST!>x<!>
}
if (example.x is Int) {
b = <!UNUSED_VALUE, DEBUG_INFO_SMARTCAST!>x<!>
}
if (example.x is Int) {
b = <!UNUSED_VALUE, DEBUG_INFO_SMARTCAST!>example.x<!>
}
return 1
}
fun Any?.foo() : Int {
if (this is Int)
return <!DEBUG_INFO_SMARTCAST!>this<!>
if (this@foo is Int)
return <!DEBUG_INFO_SMARTCAST!>this<!>
if (this@foo is Int)
return <!DEBUG_INFO_SMARTCAST!>this@foo<!>
if (this is Int)
return <!DEBUG_INFO_SMARTCAST!>this@foo<!>
return 1
}
trait T {}
open class C {
fun foo() {
var <!ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE!>t<!> : T? = null
if (this is T) {
t = <!UNUSED_VALUE, DEBUG_INFO_SMARTCAST!>this<!>
}
if (this is T) {
t = <!UNUSED_VALUE, DEBUG_INFO_SMARTCAST!>this@C<!>
}
if (this@C is T) {
t = <!UNUSED_VALUE, DEBUG_INFO_SMARTCAST!>this<!>
}
if (this@C is T) {
t = <!UNUSED_VALUE, DEBUG_INFO_SMARTCAST!>this@C<!>
}
}
}
@@ -0,0 +1,56 @@
package
package example {
internal val x: kotlin.Any? = 1
internal fun kotlin.Any?.foo(): kotlin.Int
internal fun kotlin.Any?.vars(/*0*/ a: kotlin.Any?): kotlin.Int
internal final class AClass {
public constructor AClass()
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
internal class object <class-object-for-AClass> {
private constructor <class-object-for-AClass>()
internal final val y: kotlin.Any? = 2
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
}
}
internal open class C {
public constructor C()
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
}
internal object Obj {
private constructor Obj()
internal final val y: kotlin.Any? = 2
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 class object <class-object-for-Obj> : example.Obj {
private constructor <class-object-for-Obj>()
internal final override /*1*/ /*fake_override*/ val y: kotlin.Any?
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
}
}
internal trait T {
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
}
package example.ns {
internal val y: kotlin.Any? = 2
}
}