[NI] Add support ExpectedTypeFromCast to new inference. #KT-30405 Fixed

This commit is contained in:
Dmitriy Novozhilov
2019-03-14 14:14:28 +03:00
parent 9062811231
commit 1c92c22dee
12 changed files with 123 additions and 48 deletions
@@ -14,5 +14,5 @@ fun <S, D: S> g() {
val <!UNUSED_VARIABLE!>y<!> = <!OI;TYPE_INFERENCE_UPPER_BOUND_VIOLATED!>foo<!>() as Int
val <!UNUSED_VARIABLE!>y2<!> = foo() <!NI;UNCHECKED_CAST!>as D<!>
val <!UNUSED_VARIABLE!>y2<!> = foo() as D
}
@@ -31,7 +31,7 @@ val xCastExplicitType = Test().findViewById<X>(0) as X
val xSafeCastExplicitType = Test().findViewById<X>(0) <!USELESS_CAST!>as? X<!>
val yExplicit: Y<String> = Test().findViewById(0)
val yCast = Test().findViewById(0) <!NI;UNCHECKED_CAST!>as Y<String><!>
val yCast = Test().findViewById(0) as Y<String>
class TestChild : Test() {
@@ -39,7 +39,7 @@ class TestChild : Test() {
val xCast = findViewById(0) as X
val yExplicit: Y<String> = findViewById(0)
val yCast = findViewById(0) <!NI;UNCHECKED_CAST!>as Y<String><!>
val yCast = findViewById(0) as Y<String>
}
fun test(t: Test) {
@@ -47,7 +47,7 @@ fun test(t: Test) {
val xCast = t.findViewById(0) as X
val yExplicit: Y<String> = t.findViewById(0)
val yCast = t.findViewById(0) <!NI;UNCHECKED_CAST!>as Y<String><!>
val yCast = t.findViewById(0) as Y<String>
}
fun test2(t: Test?) {
@@ -0,0 +1,16 @@
// !WITH_NEW_INFERENCE
// !LANGUAGE: +ExpectedTypeFromCast
// !CHECK_TYPE
// Issue: KT-30405
inline fun <reified T> foo(): T {
TODO()
}
fun test() {
val fooCall = foo() as String // T in foo should be inferred to String
fooCall checkType { _<String>() }
val safeFooCall = foo() as? String
safeFooCall checkType { _<String?>() }
}
@@ -0,0 +1,4 @@
package
public inline fun </*0*/ reified T> foo(): T
public fun test(): kotlin.Unit