Array<Subtype> can be now cast to Array<Supertype(?)> without CAST_NEVER_SUCCEEDS #KT-6391 Fixed
(cherry picked from commit 2629d55)
This commit is contained in:
committed by
Mikhail Glukhikh
parent
90e5e561e3
commit
dbbc4ec281
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||
import org.jetbrains.kotlin.types.checker.TypeCheckingProcedure
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.types.typeUtil.isPrimitiveNumberType
|
||||
|
||||
object CastDiagnosticsUtil {
|
||||
|
||||
@@ -46,8 +47,11 @@ object CastDiagnosticsUtil {
|
||||
if (KotlinBuiltIns.isArray(lhsType)) {
|
||||
val lhsArgument = lhsType.arguments.firstOrNull()
|
||||
val rhsArgument = rhsType.arguments.firstOrNull()
|
||||
if (lhsArgument != null && rhsArgument != null && lhsArgument.type.constructor == rhsArgument.type.constructor) {
|
||||
return true
|
||||
if (lhsArgument != null && rhsArgument != null) {
|
||||
if (lhsArgument.type.constructor == rhsArgument.type.constructor) return true
|
||||
if (KotlinTypeChecker.DEFAULT.isSubtypeOf(TypeUtils.makeNotNullable(lhsArgument.type), rhsArgument.type)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,5 +23,12 @@ fun checkArrays2(): Array<Wrapper<String>> {
|
||||
return <!UNCHECKED_CAST!>someArray as Array<Wrapper<String>><!>
|
||||
}
|
||||
|
||||
fun checkArrays3() {
|
||||
val someArray = arrayOfNulls<String>(1)
|
||||
<!UNCHECKED_CAST!>someArray as Array<Any><!>
|
||||
val intArray = arrayOfNulls<Int>(1)
|
||||
<!UNCHECKED_CAST!>intArray as Array<Any><!>
|
||||
}
|
||||
|
||||
fun println(s: String) = s
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package
|
||||
|
||||
public fun checkArrays(): kotlin.Array<kotlin.Any>
|
||||
public fun checkArrays2(): kotlin.Array<Wrapper<kotlin.String>>
|
||||
public fun checkArrays3(): kotlin.Unit
|
||||
public fun println(/*0*/ s: kotlin.String): kotlin.String
|
||||
public fun </*0*/ T> test(/*0*/ clazz: Class<T>): kotlin.Unit
|
||||
public fun use(): kotlin.Unit
|
||||
|
||||
Reference in New Issue
Block a user