[NI] Check stub types in result type
An uninferred parameter stub may leak through calculation of CST(Inv<Uninferred Stub>, Nothing) into a result type. A stub type in the result type means a type error. So we can afford recalculating CST with stub-containing types filtered out, since its an error anyway. This prevents stub types leakages and helps with reporting type error diagnostics. KT-35914 Fixed KT-35943 Fixed
This commit is contained in:
Vendored
+38
@@ -0,0 +1,38 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// !CHECK_TYPE
|
||||
|
||||
class Inv<I>
|
||||
fun <T> materialize(): Inv<T> = TODO()
|
||||
fun <K> id(arg: K) = arg
|
||||
fun <S> select(vararg args: S): S = TODO()
|
||||
|
||||
fun test1(b: Boolean?) {
|
||||
val v = when(b) {
|
||||
true -> materialize()
|
||||
false -> null
|
||||
null -> materialize<String>()
|
||||
}
|
||||
v checkType { <!UNRESOLVED_REFERENCE!>_<!><Inv<String>?>() }
|
||||
}
|
||||
|
||||
fun test2() {
|
||||
select(
|
||||
materialize()
|
||||
)
|
||||
select(materialize(), materialize<String>())
|
||||
select(materialize(), null, Inv<String>())
|
||||
select(
|
||||
materialize(),
|
||||
null
|
||||
)
|
||||
select(
|
||||
materialize(),
|
||||
materialize()
|
||||
)
|
||||
select(
|
||||
materialize(),
|
||||
materialize(),
|
||||
null
|
||||
)
|
||||
}
|
||||
Vendored
+38
@@ -0,0 +1,38 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// !CHECK_TYPE
|
||||
|
||||
class Inv<I>
|
||||
fun <T> materialize(): Inv<T> = TODO()
|
||||
fun <K> id(arg: K) = arg
|
||||
fun <S> select(vararg args: S): S = TODO()
|
||||
|
||||
fun test1(b: Boolean?) {
|
||||
val v = when(b) {
|
||||
true -> materialize()
|
||||
false -> null
|
||||
null -> materialize<String>()
|
||||
}
|
||||
v checkType { _<Inv<String>?>() }
|
||||
}
|
||||
|
||||
fun test2() {
|
||||
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>select<!>(
|
||||
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>materialize<!>()
|
||||
)
|
||||
select(materialize(), materialize<String>())
|
||||
select(materialize(), null, Inv<String>())
|
||||
<!TYPE_MISMATCH!>select<!>(
|
||||
materialize(),
|
||||
null
|
||||
)
|
||||
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>select<!>(
|
||||
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>materialize<!>(),
|
||||
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>materialize<!>()
|
||||
)
|
||||
select(
|
||||
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>materialize<!>(),
|
||||
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>materialize<!>(),
|
||||
null
|
||||
)
|
||||
}
|
||||
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
package
|
||||
|
||||
public fun </*0*/ K> id(/*0*/ arg: K): K
|
||||
public fun </*0*/ T> materialize(): Inv<T>
|
||||
public fun </*0*/ S> select(/*0*/ vararg args: S /*kotlin.Array<out S>*/): S
|
||||
public fun test1(/*0*/ b: kotlin.Boolean?): kotlin.Unit
|
||||
public fun test2(): kotlin.Unit
|
||||
|
||||
public final class Inv</*0*/ I> {
|
||||
public constructor Inv</*0*/ I>()
|
||||
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,9 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION
|
||||
|
||||
class Inv<I>
|
||||
fun <T> create(): Inv<T> = TODO()
|
||||
|
||||
fun main() {
|
||||
if (true) create() else null
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION
|
||||
|
||||
class Inv<I>
|
||||
fun <T> create(): Inv<T> = TODO()
|
||||
|
||||
fun main() {
|
||||
<!TYPE_MISMATCH!>if (true) create() else null<!>
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package
|
||||
|
||||
public fun </*0*/ T> create(): Inv<T>
|
||||
public fun main(): kotlin.Unit
|
||||
|
||||
public final class Inv</*0*/ I> {
|
||||
public constructor Inv</*0*/ I>()
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user