FIR checker: report nullable expression as LHS of class literals
This commit is contained in:
committed by
Mikhail Glukhikh
parent
33c5b49632
commit
5ba5b63dee
Vendored
+3
-3
@@ -23,11 +23,11 @@ class Test {
|
||||
fun <T> List<T>.testCallable4(): () -> Unit = <!UNRESOLVED_REFERENCE!>b<T>?::foo<!>
|
||||
|
||||
fun <T> List<T>.testClassLiteral1() = a<T>::class
|
||||
fun <T> List<T>.testClassLiteral2() = b?::class
|
||||
fun <T> List<T>.testClassLiteral3() = b<T, Any>::class
|
||||
fun <T> List<T>.testClassLiteral2() = <!EXPRESSION_OF_NULLABLE_TYPE_IN_CLASS_LITERAL_LHS!>b<!>?::class
|
||||
fun <T> List<T>.testClassLiteral3() = <!EXPRESSION_OF_NULLABLE_TYPE_IN_CLASS_LITERAL_LHS!>b<T, Any><!>::class
|
||||
|
||||
fun <T> List<T>.testUnresolved1() = <!UNRESOLVED_REFERENCE!>unresolved<!><T>::foo
|
||||
fun <T> List<T>.testUnresolved2() = a<<!UNRESOLVED_REFERENCE!>unresolved<!>>::foo
|
||||
fun <T> List<T>.testUnresolved3() = a<<!SYNTAX!><!>>::foo
|
||||
fun <T> List<T>.testUnresolved4() = <!UNRESOLVED_REFERENCE!>unresolved<!>?::foo
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -6,10 +6,10 @@ public interface J {
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun f1(x: Int?): Any = x::class
|
||||
fun f1(x: Int?): Any = <!EXPRESSION_OF_NULLABLE_TYPE_IN_CLASS_LITERAL_LHS!>x<!>::class
|
||||
fun <T> f2(t: T): Any = t::class
|
||||
fun <S : String?> f3(s: S): Any = s::class
|
||||
fun <U : Any> f4(u: U?): Any = u::class
|
||||
fun f5(c: List<*>): Any = c[0]::class
|
||||
fun <U : Any> f4(u: U?): Any = <!EXPRESSION_OF_NULLABLE_TYPE_IN_CLASS_LITERAL_LHS!>u<!>::class
|
||||
fun f5(c: List<*>): Any = <!EXPRESSION_OF_NULLABLE_TYPE_IN_CLASS_LITERAL_LHS!>c[0]<!>::class
|
||||
|
||||
fun f6(j: J): Any = j.platformString()::class
|
||||
|
||||
@@ -10,11 +10,11 @@ val l2 = <!NULLABLE_TYPE_IN_CLASS_LITERAL_LHS!>List?::class<!>
|
||||
|
||||
fun <T : Any> foo() {
|
||||
val t1 = <!TYPE_PARAMETER_IS_NOT_AN_EXPRESSION!>T<!>::class
|
||||
val t2 = <!TYPE_PARAMETER_IS_NOT_AN_EXPRESSION!>T<!>?::class
|
||||
val t2 = <!NULLABLE_TYPE_IN_CLASS_LITERAL_LHS!><!TYPE_PARAMETER_IS_NOT_AN_EXPRESSION!>T<!>?::class<!>
|
||||
}
|
||||
|
||||
inline fun <reified T : Any> bar() {
|
||||
val t3 = T?::class
|
||||
val t3 = <!NULLABLE_TYPE_IN_CLASS_LITERAL_LHS!>T?::class<!>
|
||||
}
|
||||
|
||||
val m = Map<String>::class
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
// KT-16291 Smart cast doesn't work when getting class of instance
|
||||
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
class Foo {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other === null || other::class != this::class) return false
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
fun test(f: Foo?): KClass<out Foo>? = if (f != null) f::class else null
|
||||
|
||||
fun test2(): KClass<out Foo>? {
|
||||
var f: Foo? = null
|
||||
if (f != null) {
|
||||
run { f = null }
|
||||
return f::class
|
||||
}
|
||||
return null
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// KT-16291 Smart cast doesn't work when getting class of instance
|
||||
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
Reference in New Issue
Block a user