Rename: auto cast -> smart cast
This commit is contained in:
@@ -3,5 +3,5 @@ package a
|
||||
fun <T> foo(u: T, <!UNUSED_PARAMETER!>v<!>: T): T = u
|
||||
|
||||
fun test(s: String?) {
|
||||
val <!UNUSED_VARIABLE!>r<!>: String = foo(s!!, <!DEBUG_INFO_AUTOCAST!>s<!>)
|
||||
val <!UNUSED_VARIABLE!>r<!>: String = foo(s!!, <!DEBUG_INFO_SMARTCAST!>s<!>)
|
||||
}
|
||||
@@ -12,16 +12,16 @@ trait C: A
|
||||
|
||||
fun test(a: A, b: B, c: C) {
|
||||
if (a is B && a is C) {
|
||||
val d: C = id(<!DEBUG_INFO_AUTOCAST!>a<!>)
|
||||
val d: C = id(<!DEBUG_INFO_SMARTCAST!>a<!>)
|
||||
val e: Any = id(a)
|
||||
val f = id(a)
|
||||
f: A
|
||||
val g = two(<!DEBUG_INFO_AUTOCAST!>a<!>, b)
|
||||
val g = two(<!DEBUG_INFO_SMARTCAST!>a<!>, b)
|
||||
g: B
|
||||
g: A
|
||||
|
||||
// auto cast isn't needed, but is reported due to KT-4294
|
||||
val h: Any = two(<!DEBUG_INFO_AUTOCAST!>a<!>, b)
|
||||
// smart cast isn't needed, but is reported due to KT-4294
|
||||
val h: Any = two(<!DEBUG_INFO_SMARTCAST!>a<!>, b)
|
||||
|
||||
val k = three(a, b, c)
|
||||
k: A
|
||||
@@ -46,7 +46,7 @@ fun testErrorMessages(a: A, ml: MutableList<String>) {
|
||||
|
||||
fun rr(s: String?) {
|
||||
if (s != null) {
|
||||
val l = arrayListOf("", <!DEBUG_INFO_AUTOCAST!>s<!>)
|
||||
val l = arrayListOf("", <!DEBUG_INFO_SMARTCAST!>s<!>)
|
||||
l: MutableList<String>
|
||||
<!TYPE_MISMATCH!>l<!>: MutableList<String?>
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//KT-1355 Type inference fails with autocast and generic function
|
||||
//KT-1355 Type inference fails with smartcast and generic function
|
||||
//tests for Map.set
|
||||
package a
|
||||
|
||||
@@ -6,9 +6,9 @@ import java.util.HashMap
|
||||
|
||||
fun foo(map: MutableMap<Int, String>, value: String?) {
|
||||
if (value != null) {
|
||||
map.put(1, <!DEBUG_INFO_AUTOCAST!>value<!>) //ok
|
||||
map.set(1, <!DEBUG_INFO_AUTOCAST!>value<!>) //type inference failed
|
||||
map[1] = <!DEBUG_INFO_AUTOCAST!>value<!> //type inference failed
|
||||
map.put(1, <!DEBUG_INFO_SMARTCAST!>value<!>) //ok
|
||||
map.set(1, <!DEBUG_INFO_SMARTCAST!>value<!>) //type inference failed
|
||||
map[1] = <!DEBUG_INFO_SMARTCAST!>value<!> //type inference failed
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ public data open class Tag(public var tagName: String) {
|
||||
}
|
||||
else {
|
||||
attributes["id"] = value<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
|
||||
attributes["id"] = <!DEBUG_INFO_AUTOCAST!>value<!>
|
||||
attributes["id"] = <!DEBUG_INFO_SMARTCAST!>value<!>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
//KT-2746 Do autocasts in inference
|
||||
import java.util.HashMap
|
||||
//KT-2746 Do.smartcasts in inference
|
||||
|
||||
class C<T>(t :T)
|
||||
|
||||
fun test1(a: Any) {
|
||||
if (a is String) {
|
||||
val <!UNUSED_VARIABLE!>c<!>: C<String> = C(<!DEBUG_INFO_AUTOCAST!>a<!>)
|
||||
val <!UNUSED_VARIABLE!>c<!>: C<String> = C(<!DEBUG_INFO_SMARTCAST!>a<!>)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +13,6 @@ fun f<T>(t :T): C<T> = C(t)
|
||||
|
||||
fun test2(a: Any) {
|
||||
if (a is String) {
|
||||
val <!UNUSED_VARIABLE!>c1<!>: C<String> = f(<!DEBUG_INFO_AUTOCAST!>a<!>)
|
||||
val <!UNUSED_VARIABLE!>c1<!>: C<String> = f(<!DEBUG_INFO_SMARTCAST!>a<!>)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,9 @@ package a
|
||||
fun main(args: Array<String>) {
|
||||
val value: String? = ""
|
||||
if (value != null) {
|
||||
foo(Pair("val", <!DEBUG_INFO_AUTOCAST!>value<!>))
|
||||
foo(Pair("val", <!DEBUG_INFO_SMARTCAST!>value<!>))
|
||||
foo(Pair("val", value<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>))
|
||||
foo(Pair<String, String>("val", <!DEBUG_INFO_AUTOCAST!>value<!>))
|
||||
foo(Pair<String, String>("val", <!DEBUG_INFO_SMARTCAST!>value<!>))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,5 +7,5 @@ fun <T> T.f(): T = this
|
||||
|
||||
fun test(a: A) {
|
||||
if (a !is B) return
|
||||
val <!UNUSED_VARIABLE!>c<!> = <!DEBUG_INFO_AUTOCAST!>a<!>.f() // type mismatch
|
||||
val <!UNUSED_VARIABLE!>c<!> = <!DEBUG_INFO_SMARTCAST!>a<!>.f() // type mismatch
|
||||
}
|
||||
@@ -8,7 +8,7 @@ object A {
|
||||
fun toJson2(obj:Any){
|
||||
if(obj is SelfJson){
|
||||
// A.find( (obj as SelfJson).javaClass) // OK
|
||||
A.find( <!DEBUG_INFO_AUTOCAST!>obj<!>.javaClass ) // ERROR: Type mismatch: inferred type is jet.Any but SelfJson was expected
|
||||
A.find( <!DEBUG_INFO_SMARTCAST!>obj<!>.javaClass ) // ERROR: Type mismatch: inferred type is jet.Any but SelfJson was expected
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ trait B
|
||||
class Test {
|
||||
fun test(a: A?, b: B, list: MutableList<Pair<A, B>>) {
|
||||
if (a != null) {
|
||||
list.add(<!DEBUG_INFO_AUTOCAST!>a<!> to b)
|
||||
list.add(<!DEBUG_INFO_SMARTCAST!>a<!> to b)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user