Report warning about implicitly inferred nothing only for return position
^KT-31535 Fixed
This commit is contained in:
+1
-1
@@ -14,7 +14,7 @@ fun doSomething() {}
|
||||
|
||||
fun test2() {
|
||||
fun f(x: Any?) = x
|
||||
f(null?.<!IMPLICIT_NOTHING_AS_TYPE_PARAMETER, NI;IMPLICIT_NOTHING_AS_TYPE_PARAMETER!>let<!> { return })
|
||||
f(null?.let { return })
|
||||
|
||||
// false unreachable here
|
||||
doSomething()
|
||||
|
||||
+1
-1
@@ -52,7 +52,7 @@ fun testLoopLabelInReturn(xs: List<Int>) {
|
||||
|
||||
fun testValLabelInReturn() {
|
||||
<!REDUNDANT_LABEL_WARNING!>L@<!> val fn = { <!NOT_A_FUNCTION_LABEL!>return@L<!> }
|
||||
fn()
|
||||
<!IMPLICIT_NOTHING_AS_TYPE_PARAMETER!>fn<!>()
|
||||
}
|
||||
|
||||
fun testHighOrderFunctionCallLabelInReturn() {
|
||||
|
||||
+1
-1
@@ -52,7 +52,7 @@ fun testLoopLabelInReturn(xs: List<Int>) {
|
||||
|
||||
fun testValLabelInReturn() {
|
||||
<!REDUNDANT_LABEL_WARNING!>L@<!> val fn = { <!NOT_A_FUNCTION_LABEL_WARNING!>return@L<!> }
|
||||
fn()
|
||||
<!IMPLICIT_NOTHING_AS_TYPE_PARAMETER!>fn<!>()
|
||||
}
|
||||
|
||||
fun testHighOrderFunctionCallLabelInReturn() {
|
||||
|
||||
@@ -24,7 +24,7 @@ fun foo(x: MC<out Open>) {
|
||||
x.addAll(<!NI;TYPE_MISMATCH, OI;TYPE_MISMATCH_DUE_TO_TYPE_PROJECTIONS!>mc<Derived>()<!>)
|
||||
x.addAllMC(<!NI;TYPE_MISMATCH, OI;TYPE_MISMATCH_DUE_TO_TYPE_PROJECTIONS!>mc<Derived>()<!>)
|
||||
|
||||
x.addAll(<!IMPLICIT_NOTHING_AS_TYPE_PARAMETER, NI;IMPLICIT_NOTHING_AS_TYPE_PARAMETER!>c<!>())
|
||||
x.addAll(c())
|
||||
x.addAll(c<Nothing>())
|
||||
|
||||
x.<!OI;MEMBER_PROJECTED_OUT!>addAllInv<!>(<!NI;TYPE_MISMATCH!>mc<Open>()<!>)
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ fun test(a: A<out CharSequence>, z: Out<CharSequence>) {
|
||||
<!NI;TYPE_MISMATCH, NI;TYPE_MISMATCH, TYPE_MISMATCH!>""<!>
|
||||
}
|
||||
a.bar { <!NI;TYPE_MISMATCH, NI;TYPE_MISMATCH, NI;TYPE_MISMATCH, TYPE_MISMATCH!>Out<CharSequence>()<!> }
|
||||
a.bar { <!IMPLICIT_NOTHING_AS_TYPE_PARAMETER!>Out<!>() }
|
||||
a.bar { Out() }
|
||||
a.bar { <!NI;TYPE_MISMATCH, NI;TYPE_MISMATCH, TYPE_MISMATCH!>z.id()<!> }
|
||||
|
||||
a.foo {
|
||||
|
||||
+2
-2
@@ -14,9 +14,9 @@ class A<T> {
|
||||
|
||||
fun foo2(a: A<out CharSequence>, b: A<in CharSequence>) {
|
||||
a.<!OI;TYPE_INFERENCE_UPPER_BOUND_VIOLATED!>foo1<!>(<!NI;TYPE_MISMATCH!>Out<CharSequence>()<!>)
|
||||
a.foo1<<!UPPER_BOUND_VIOLATED!>Out<CharSequence><!>>(<!NI;TYPE_MISMATCH!><!NI;IMPLICIT_NOTHING_AS_TYPE_PARAMETER, NI;IMPLICIT_NOTHING_AS_TYPE_PARAMETER!>Out<!>()<!>)
|
||||
a.foo1<<!UPPER_BOUND_VIOLATED!>Out<CharSequence><!>>(<!NI;TYPE_MISMATCH!>Out()<!>)
|
||||
|
||||
a.foo1(<!IMPLICIT_NOTHING_AS_TYPE_PARAMETER, NI;IMPLICIT_NOTHING_AS_TYPE_PARAMETER!>Out<!>())
|
||||
a.foo1(Out())
|
||||
a.foo1(Out<Nothing>())
|
||||
|
||||
a.<!OI;TYPE_INFERENCE_INCORPORATION_ERROR!>foo2<!>(<!NI;TYPE_MISMATCH!><!OI;TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>Inv<!>()<!>)
|
||||
|
||||
+1
-1
@@ -7,6 +7,6 @@ fun foo1() {
|
||||
<!NI;NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, OI;TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>fooT22<!>()
|
||||
}
|
||||
|
||||
val n : Nothing = null.<!IMPLICIT_NOTHING_AS_TYPE_PARAMETER!>sure<!>()
|
||||
val n : Nothing = null.sure()
|
||||
|
||||
fun <T : Any> T?.sure() : T = this!!
|
||||
|
||||
Vendored
+2
-2
@@ -9,8 +9,8 @@ inline fun <reified T> foo2(f: (T) -> Unit): Foo<T> = Foo()
|
||||
|
||||
fun test1() {
|
||||
val f1: Foo<out Int> = foo1 { it checkType { _<Int>() } }
|
||||
val f2: Foo<in Nothing> = <!IMPLICIT_NOTHING_AS_TYPE_PARAMETER!>foo1<!> { it <!UNREACHABLE_CODE!><!IMPLICIT_NOTHING_AS_TYPE_PARAMETER!>checkType<!> { _<Nothing>() }<!> }
|
||||
val f2: Foo<in Nothing> = foo1 { it <!UNREACHABLE_CODE!>checkType { _<Nothing>() }<!> }
|
||||
|
||||
val f3: Foo<out Int> = foo2 { it checkType { _<Int>() } }
|
||||
val f4: Foo<in Nothing> = <!IMPLICIT_NOTHING_AS_TYPE_PARAMETER, REIFIED_TYPE_FORBIDDEN_SUBSTITUTION!>foo2<!> { it <!UNREACHABLE_CODE!><!IMPLICIT_NOTHING_AS_TYPE_PARAMETER!>checkType<!> { _<Nothing>() }<!> }
|
||||
val f4: Foo<in Nothing> = <!REIFIED_TYPE_FORBIDDEN_SUBSTITUTION!>foo2<!> { it <!UNREACHABLE_CODE!>checkType { _<Nothing>() }<!> }
|
||||
}
|
||||
+1
-1
@@ -13,5 +13,5 @@ fun test(s: String): String {
|
||||
a checkType { _<String>() }
|
||||
|
||||
<!UNREACHABLE_CODE!>val b =<!> TestClass { return s }
|
||||
<!UNREACHABLE_CODE!>b <!IMPLICIT_NOTHING_AS_TYPE_PARAMETER!>checkType<!> { _<Nothing>() }<!>
|
||||
<!UNREACHABLE_CODE!>b checkType { _<Nothing>() }<!>
|
||||
}
|
||||
Vendored
+1
-1
@@ -11,5 +11,5 @@ fun test(s: String): String {
|
||||
a checkType { _<TestClass>() }
|
||||
|
||||
<!UNREACHABLE_CODE!>val b =<!> TestClass { return s }
|
||||
<!UNREACHABLE_CODE!>b <!IMPLICIT_NOTHING_AS_TYPE_PARAMETER!>checkType<!> { _<Nothing>() }<!>
|
||||
<!UNREACHABLE_CODE!>b checkType { _<Nothing>() }<!>
|
||||
}
|
||||
+1
-1
@@ -8,7 +8,7 @@ class TestClass {
|
||||
|
||||
fun <T> test(value: T, test: TestClass): T {
|
||||
<!UNREACHABLE_CODE!>val x =<!> test { return value }
|
||||
<!UNREACHABLE_CODE!>x <!IMPLICIT_NOTHING_AS_TYPE_PARAMETER!>checkType<!> { _<Nothing>() }<!>
|
||||
<!UNREACHABLE_CODE!>x checkType { _<Nothing>() }<!>
|
||||
|
||||
<!UNREACHABLE_CODE!>return value<!>
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ public class TestClass {
|
||||
fun run() {
|
||||
val testClass = TestClass()
|
||||
// inferred as `set<Nothing>()`, return type is Nothing!
|
||||
testClass.<!OI;IMPLICIT_NOTHING_AS_TYPE_PARAMETER!>set<!>("test", null)
|
||||
testClass.set("test", null)
|
||||
|
||||
// Should not be unreachable
|
||||
run()
|
||||
|
||||
@@ -22,5 +22,5 @@ public class Element {
|
||||
import p.*
|
||||
|
||||
fun test(v: Visitor<Nothing>, e: Element) {
|
||||
e.<!NI;IMPLICIT_NOTHING_AS_TYPE_PARAMETER!>accept<!>(v, null)
|
||||
e.accept(v, null)
|
||||
}
|
||||
|
||||
+1
-1
@@ -5,5 +5,5 @@ val <!IMPLICIT_NOTHING_PROPERTY_TYPE!>y<!> get() = null!!
|
||||
|
||||
fun foo() {
|
||||
<!DEBUG_INFO_CONSTANT!>x<!> checkType { _<Nothing?>() }
|
||||
y <!UNREACHABLE_CODE!><!IMPLICIT_NOTHING_AS_TYPE_PARAMETER!>checkType<!> { _<Nothing>() }<!>
|
||||
y <!UNREACHABLE_CODE!>checkType { _<Nothing>() }<!>
|
||||
}
|
||||
|
||||
+52
-5
@@ -1,4 +1,4 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNCHECKED_CAST
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE -UNCHECKED_CAST
|
||||
// !WITH_NEW_INFERENCE
|
||||
// SKIP_TXT
|
||||
// Issue: KT-20849
|
||||
@@ -7,8 +7,8 @@ fun <T>test_1(x: T): T = null as T
|
||||
fun <T>test_2(x: () -> T): T = null as T
|
||||
|
||||
fun case_1() {
|
||||
null?.<!IMPLICIT_NOTHING_AS_TYPE_PARAMETER!>run<!> { return }
|
||||
null!!.<!UNREACHABLE_CODE!><!IMPLICIT_NOTHING_AS_TYPE_PARAMETER!>run<!> { throw Exception() }<!>
|
||||
null?.run { return }
|
||||
null!!.<!UNREACHABLE_CODE!>run { throw Exception() }<!>
|
||||
}
|
||||
|
||||
fun case_2() {
|
||||
@@ -39,6 +39,53 @@ class Context<T>
|
||||
|
||||
fun <T> Any.decodeIn(typeFrom: Context<in T>): T = something()
|
||||
|
||||
fun <T> Any?.decodeOut(typeFrom: Context<out T>): T {
|
||||
return this?.<!IMPLICIT_NOTHING_AS_TYPE_PARAMETER, NI;IMPLICIT_NOTHING_AS_TYPE_PARAMETER!>decodeIn<!>(typeFrom) ?: <!UNRESOLVED_REFERENCE!>error<!>("")
|
||||
fun <T> Any?.decodeOut1(typeFrom: Context<out T>): T {
|
||||
return <!NI;TYPE_MISMATCH!>this?.<!IMPLICIT_NOTHING_AS_TYPE_PARAMETER, NI;IMPLICIT_NOTHING_AS_TYPE_PARAMETER!>decodeIn<!>(typeFrom) ?: <!OI;TYPE_MISMATCH!>kotlin.Unit<!><!>
|
||||
}
|
||||
|
||||
fun <T> Any.decodeOut2(typeFrom: Context<out T>): T {
|
||||
<!UNREACHABLE_CODE!>val x: Nothing =<!> this.decodeIn(typeFrom)
|
||||
}
|
||||
|
||||
fun <T> Any.decodeOut3(typeFrom: Context<out T>): T {
|
||||
<!UNREACHABLE_CODE!>val x =<!> this.<!IMPLICIT_NOTHING_AS_TYPE_PARAMETER!>decodeIn<!>(typeFrom)
|
||||
}
|
||||
|
||||
fun <T> Any.decodeOut4(typeFrom: Context<out T>): T {
|
||||
<!UNREACHABLE_CODE!>val x: Any =<!> this.<!IMPLICIT_NOTHING_AS_TYPE_PARAMETER!>decodeIn<!>(typeFrom)
|
||||
}
|
||||
|
||||
class TrieNode<out E> {
|
||||
companion object {
|
||||
internal val EMPTY = TrieNode<Nothing>()
|
||||
}
|
||||
}
|
||||
class PersistentHashSet<out E>(root: TrieNode<E>) {
|
||||
companion object {
|
||||
internal val EMPTY = PersistentHashSet(TrieNode.EMPTY)
|
||||
}
|
||||
}
|
||||
|
||||
interface F<in T>
|
||||
fun <T> F<T>.join() = {}
|
||||
|
||||
fun main() {
|
||||
val f: Any = Any()
|
||||
(f as F<*>).join()
|
||||
}
|
||||
|
||||
fun bug(worker: Worker<Unit>) {
|
||||
stateless<Boolean, Nothing, Unit> {
|
||||
onWorkerOutput(worker)
|
||||
}
|
||||
}
|
||||
|
||||
fun <StateT, OutputT : Any, T> RenderContext<StateT, OutputT>.onWorkerOutput(worker: Worker<T>): Unit = Unit
|
||||
|
||||
fun <InputT, OutputT : Any, RenderingT> stateless(
|
||||
render: RenderContext<Nothing, OutputT>.(input: InputT) -> RenderingT
|
||||
) { }
|
||||
|
||||
interface Worker<out T>
|
||||
|
||||
interface RenderContext<StateT, in OutputT : Any>
|
||||
|
||||
-49
@@ -1,49 +0,0 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNCHECKED_CAST
|
||||
// !LANGUAGE: +NewInference
|
||||
// SKIP_TXT
|
||||
// Issue: KT-20849
|
||||
|
||||
fun <T>test_1(x: T.() -> T): T = null as T
|
||||
fun <T>test_2(x: (T) -> T): T = null as T
|
||||
fun <T>test_3(x: T.(T) -> T): T = null as T
|
||||
fun <T>test_4(x: T.(T) -> List<T>): T = null as T
|
||||
fun <T>test_5(): List<T> = 10 <!CAST_NEVER_SUCCEEDS!>as<!> List<T>
|
||||
fun <K, V>test_6(): Map<K, V> = 10 <!CAST_NEVER_SUCCEEDS!>as<!> Map<K, V>
|
||||
|
||||
fun case_1() {
|
||||
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>test_5<!>()
|
||||
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>test_6<!>()
|
||||
val <!UNUSED_VARIABLE!>x<!> = <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>test_6<!>()
|
||||
}
|
||||
|
||||
fun case_2() {
|
||||
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>test_1<!> { null!! }
|
||||
}
|
||||
|
||||
fun case_3() {
|
||||
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>test_2<!> { null!! }
|
||||
}
|
||||
|
||||
fun case_4() {
|
||||
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>test_3<!> { null!! }
|
||||
}
|
||||
|
||||
fun case_5() {
|
||||
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>test_4<!> { null!! }
|
||||
}
|
||||
|
||||
fun case_6() {
|
||||
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>test_1<!> { throw <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>Exception<!>() }
|
||||
}
|
||||
|
||||
fun case_7() {
|
||||
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>test_2<!> { throw Exception() }
|
||||
}
|
||||
|
||||
fun case_8() {
|
||||
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>test_3<!> { throw <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>Exception<!>() }
|
||||
}
|
||||
|
||||
fun case_9() {
|
||||
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>test_4<!> { throw <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>Exception<!>() }
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// !DIAGNOSTICS: -UNCHECKED_CAST
|
||||
// !WITH_NEW_INFERENCE
|
||||
// WITH_RUNTIME
|
||||
// WITH_REFLECT
|
||||
// SKIP_TXT
|
||||
|
||||
import kotlin.reflect.*
|
||||
|
||||
private object Scope {
|
||||
class Inv<T>
|
||||
|
||||
class Delegate<T>(private val p: Inv<in T>) {
|
||||
operator fun getValue(thisRef: Any?, property: KProperty<*>): T {
|
||||
return materialize()
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> materialize(): T = Any() as T
|
||||
|
||||
fun test(i: Inv<out Number>) {
|
||||
val <!UNUSED_VARIABLE!>p<!>: Int by <!IMPLICIT_NOTHING_AS_TYPE_PARAMETER!>Scope.Delegate(i)<!>
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -13,4 +13,4 @@ fun <T> listOf(): List<T> = null!!
|
||||
// since it has 'out' type projection in 'in' position.
|
||||
val test1 = <!UNRESOLVED_REFERENCE!>BOutIn<!>(<!OI;TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>listOf<!>(), null!!)
|
||||
|
||||
val test2 = <!OI;EXPANDED_TYPE_CANNOT_BE_CONSTRUCTED!><!OI;IMPLICIT_NOTHING_AS_TYPE_PARAMETER!>BInIn<!>(<!OI;IMPLICIT_NOTHING_AS_TYPE_PARAMETER!>listOf<!>(), null!!)<!>
|
||||
val test2 = <!OI;EXPANDED_TYPE_CANNOT_BE_CONSTRUCTED!>BInIn(listOf(), null!!)<!>
|
||||
Reference in New Issue
Block a user