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
@@ -10,8 +10,8 @@ fun f9(a : A?) {
a<info>?.</info>foo()
a<info>?.</info><error descr="[UNRESOLVED_REFERENCE] Unresolved reference: bar">bar</error>()
if (a is B) {
<info descr="Automatically cast to B">a</info>.bar()
<info descr="Automatically cast to B">a</info>.foo()
<info descr="Smart cast to B">a</info>.bar()
<info descr="Smart cast to B">a</info>.foo()
}
a<info>?.</info>foo()
a<info>?.</info><error descr="[UNRESOLVED_REFERENCE] Unresolved reference: bar">bar</error>()
@@ -19,14 +19,14 @@ fun f9(a : A?) {
a<info>?.</info><error descr="[UNRESOLVED_REFERENCE] Unresolved reference: bar">bar</error>()
a<info>?.</info>foo()
}
if (!(a is B) || <info descr="Automatically cast to B">a</info>.bar() == Unit) {
if (!(a is B) || <info descr="Smart cast to B">a</info>.bar() == Unit) {
a<info>?.</info><error descr="[UNRESOLVED_REFERENCE] Unresolved reference: bar">bar</error>()
}
if (!(a is B)) {
return;
}
<info descr="Automatically cast to B">a</info>.bar()
<info descr="Automatically cast to B">a</info>.foo()
<info descr="Smart cast to B">a</info>.bar()
<info descr="Smart cast to B">a</info>.foo()
}
fun f10(a : A?) {
@@ -46,15 +46,15 @@ class C() : A() {
fun f101(a : A?) {
if (a is C) {
<info descr="Automatically cast to C">a</info>.bar();
<info descr="Smart cast to C">a</info>.bar();
}
}
fun f11(a : A?) {
when (a) {
is B -> <info descr="Automatically cast to B">a</info>.bar()
is A -> <info descr="Automatically cast to A">a</info>.foo()
is Any -> <info descr="Automatically cast to A">a</info>.foo()
is B -> <info descr="Smart cast to B">a</info>.bar()
is A -> <info descr="Smart cast to A">a</info>.foo()
is Any -> <info descr="Smart cast to A">a</info>.foo()
is Any? -> a.<error descr="[UNRESOLVED_REFERENCE] Unresolved reference: bar">bar</error>()
else -> a<info>?.</info>foo()
}
@@ -62,11 +62,11 @@ fun f11(a : A?) {
fun f12(a : A?) {
when (a) {
is B -> <info descr="Automatically cast to B">a</info>.bar()
is A -> <info descr="Automatically cast to A">a</info>.foo()
is Any -> <info descr="Automatically cast to A">a</info>.foo();
is B -> <info descr="Smart cast to B">a</info>.bar()
is A -> <info descr="Smart cast to A">a</info>.foo()
is Any -> <info descr="Smart cast to A">a</info>.foo();
is Any? -> a.<error descr="[UNRESOLVED_REFERENCE] Unresolved reference: bar">bar</error>()
is C -> <info descr="Automatically cast to C">a</info>.bar()
is C -> <info descr="Smart cast to C">a</info>.bar()
else -> a<info>?.</info>foo()
}
@@ -74,14 +74,14 @@ fun f12(a : A?) {
a<info>?.</info><error descr="[UNRESOLVED_REFERENCE] Unresolved reference: bar">bar</error>()
}
if (a is B) {
<info descr="Automatically cast to B">a</info>.bar()
<info descr="Smart cast to B">a</info>.bar()
}
}
fun f13(a : A?) {
if (a is B) {
<info descr="Automatically cast to B">a</info>.foo()
<info descr="Automatically cast to B">a</info>.bar()
<info descr="Smart cast to B">a</info>.foo()
<info descr="Smart cast to B">a</info>.bar()
}
else {
a<info>?.</info>foo()
@@ -93,13 +93,13 @@ fun f13(a : A?) {
a<info>?.</info>foo()
}
else {
<info descr="Automatically cast to B">a</info>.foo()
<info descr="Smart cast to B">a</info>.foo()
}
a<info>?.</info>foo()
if (a is B && <info descr="Automatically cast to B">a</info>.foo() == Unit) {
<info descr="Automatically cast to B">a</info>.foo()
<info descr="Automatically cast to B">a</info>.bar()
if (a is B && <info descr="Smart cast to B">a</info>.foo() == Unit) {
<info descr="Smart cast to B">a</info>.foo()
<info descr="Smart cast to B">a</info>.bar()
}
else {
a<info>?.</info>foo()
@@ -114,72 +114,72 @@ fun f13(a : A?) {
}
if (!(a is B)) return
<info descr="Automatically cast to B">a</info>.bar()
<info descr="Smart cast to B">a</info>.bar()
}
fun f14(a : A?) {
while (!(a is B)) {
}
<info descr="Automatically cast to B">a</info>.bar()
<info descr="Smart cast to B">a</info>.bar()
}
fun f15(a : A?) {
do {
} while (!(a is B))
<info descr="Automatically cast to B">a</info>.bar()
<info descr="Smart cast to B">a</info>.bar()
}
fun getStringLength(obj : Any) : Char? {
if (obj !is String)
return null
return <info descr="Automatically cast to kotlin.String">obj</info>.get(0) // no cast to kotlin.String is needed
return <info descr="Smart cast to kotlin.String">obj</info>.get(0) // no cast to kotlin.String is needed
}
fun toInt(i: Int?): Int = if (i != null) <info descr="Automatically cast to kotlin.Int">i</info> else 0
fun toInt(i: Int?): Int = if (i != null) <info descr="Smart cast to kotlin.Int">i</info> else 0
fun illegalWhenBody(a: Any): Int = when(a) {
is Int -> <info descr="Automatically cast to kotlin.Int">a</info>
is Int -> <info descr="Smart cast to kotlin.Int">a</info>
is String -> <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is kotlin.Any but kotlin.Int was expected">a</error>
else -> 1
}
fun illegalWhenBlock(a: Any): Int {
when(a) {
is Int -> return <info descr="Automatically cast to kotlin.Int">a</info>
is Int -> return <info descr="Smart cast to kotlin.Int">a</info>
is String -> return <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is kotlin.Any but kotlin.Int was expected">a</error>
else -> return 1
}
}
fun declarations(a: Any?) {
if (a is String) {
val <warning>p4</warning>: String = <info descr="Automatically cast to kotlin.String">a</info>
val <warning>p4</warning>: String = <info descr="Smart cast to kotlin.String">a</info>
}
if (a is String?) {
if (a != null) {
val <warning>s</warning>: String = <info descr="Automatically cast to kotlin.String">a</info>
val <warning>s</warning>: String = <info descr="Smart cast to kotlin.String">a</info>
}
}
if (a != null) {
if (a is String?) {
val <warning>s</warning>: String = <info descr="Automatically cast to kotlin.String">a</info>
val <warning>s</warning>: String = <info descr="Smart cast to kotlin.String">a</info>
}
}
}
fun vars(a: Any?) {
var <warning>b</warning>: Int = 0
if (a is Int) {
b = <warning><info descr="Automatically cast to kotlin.Int">a</info></warning>
b = <warning><info descr="Smart cast to kotlin.Int">a</info></warning>
}
}
fun returnFunctionLiteralBlock(<info>a</info>: Any?): Function0<Int> {
if (<info>a</info> is Int) return { <info descr="Automatically cast to kotlin.Int"><info>a</info></info> }
if (<info>a</info> is Int) return { <info descr="Smart cast to kotlin.Int"><info>a</info></info> }
else return { 1 }
}
fun returnFunctionLiteral(<info>a</info>: Any?): Function0<Int> =
if (<info>a</info> is Int) { (): Int -> <info descr="Automatically cast to kotlin.Int"><info>a</info></info> }
if (<info>a</info> is Int) { (): Int -> <info descr="Smart cast to kotlin.Int"><info>a</info></info> }
else { () -> 1 }
fun merge<TYPO descr="Typo: In word 'Autocasts'">Autocasts</TYPO>(a: Any?) {
fun mergeSmartCasts(a: Any?) {
if (a is String || a is Int) {
a.<error descr="[UNRESOLVED_REFERENCE] Unresolved reference: compareTo">compareTo</error>("")
<info descr="Automatically cast to kotlin.Any"><info>a</info></info>.toString()
<info descr="Smart cast to kotlin.Any"><info>a</info></info>.toString()
}
if (a is Int || a is String) {
a.<error descr="[UNRESOLVED_REFERENCE] Unresolved reference: compareTo">compareTo</error>("")
@@ -188,9 +188,9 @@ fun merge<TYPO descr="Typo: In word 'Autocasts'">Autocasts</TYPO>(a: Any?) {
is String, is Any -> a.<error descr="[UNRESOLVED_REFERENCE] Unresolved reference: compareTo">compareTo</error>("")
}
if (a is String && a is Any) {
val <warning>i</warning>: Int = <info descr="Automatically cast to kotlin.String">a</info>.compareTo("")
val <warning>i</warning>: Int = <info descr="Smart cast to kotlin.String">a</info>.compareTo("")
}
if (a is String && <info descr="Automatically cast to kotlin.String">a</info>.compareTo("") == 0) {}
if (a is String && <info descr="Smart cast to kotlin.String">a</info>.compareTo("") == 0) {}
if (a is String || a.<error descr="[UNRESOLVED_REFERENCE] Unresolved reference: compareTo">compareTo</error>("") <error>==</error> 0) {}
}
@@ -198,10 +198,10 @@ fun merge<TYPO descr="Typo: In word 'Autocasts'">Autocasts</TYPO>(a: Any?) {
fun f(): String {
var <info>a</info>: Any = 11
if (<info>a</info> is String) {
val <warning>i</warning>: String = <error descr="[AUTOCAST_IMPOSSIBLE] Automatic cast to 'kotlin.String' is impossible, because 'a' could have changed since the is-check">a</error>
<error descr="[AUTOCAST_IMPOSSIBLE] Automatic cast to 'kotlin.String' is impossible, because 'a' could have changed since the is-check">a</error>.compareTo("f")
val <warning>f</warning>: Function0<String> = { <error descr="[AUTOCAST_IMPOSSIBLE] Automatic cast to 'kotlin.String' is impossible, because 'a' could have changed since the is-check">a</error> }
return <error descr="[AUTOCAST_IMPOSSIBLE] Automatic cast to 'kotlin.String' is impossible, because 'a' could have changed since the is-check">a</error>
val <warning>i</warning>: String = <error descr="[SMARTCAST_IMPOSSIBLE] Smart cast to 'kotlin.String' is impossible, because 'a' could have changed since the is-check">a</error>
<error descr="[SMARTCAST_IMPOSSIBLE] Smart cast to 'kotlin.String' is impossible, because 'a' could have changed since the is-check">a</error>.compareTo("f")
val <warning>f</warning>: Function0<String> = { <error descr="[SMARTCAST_IMPOSSIBLE] Smart cast to 'kotlin.String' is impossible, because 'a' could have changed since the is-check">a</error> }
return <error descr="[SMARTCAST_IMPOSSIBLE] Smart cast to 'kotlin.String' is impossible, because 'a' could have changed since the is-check">a</error>
}
return ""
}
@@ -209,14 +209,14 @@ fun f(): String {
fun foo(aa: Any): Int {
var a = aa
if (a is Int) {
return <error descr="[AUTOCAST_IMPOSSIBLE] Automatic cast to 'kotlin.Int' is impossible, because 'a' could have changed since the is-check">a</error>
return <error descr="[SMARTCAST_IMPOSSIBLE] Smart cast to 'kotlin.Int' is impossible, because 'a' could have changed since the is-check">a</error>
}
return 1
}
fun inForLoop(x: Any?) {
if (x is Array<String>) {
for (i in <info descr="Automatically cast to kotlin.Array<kotlin.String>">x</info>) {}
for (i in <info descr="Smart cast to kotlin.Array<kotlin.String>">x</info>) {}
}
for (i in <error descr="[ITERATOR_MISSING] For-loop range must have an iterator() method">x</error>) {}
}
@@ -12,15 +12,15 @@ trait D : A
fun test(a: A?) {
if (a != null && a is B?) {
<info descr="Automatically cast to B">a</info>.bar()
<info descr="Smart cast to B">a</info>.bar()
}
if (a is B && a is C) {
<info descr="Automatically cast to B">a</info>.foo()
<info descr="Smart cast to B">a</info>.foo()
}
if (a is B? && a is C?) {
<info descr="Automatically cast to B?">a</info><info>?.</info>bar()
<info descr="Smart cast to B?">a</info><info>?.</info>bar()
}
a<info>?.</info>foo()
@@ -29,7 +29,7 @@ fun test(a: A?) {
}
if (a is B && a is D) {
//when it's resolved, the message should be 'Automatically cast to A'
//when it's resolved, the message should be 'Smart cast to A'
a.<error>foo</error>
}
}