KT-6391: Arrays with same erased types counted as cast-compatible now
(cherry picked from commit 9e6f4bf)
This commit is contained in:
committed by
Mikhail Glukhikh
parent
82e69d9587
commit
90e5e561e3
@@ -43,6 +43,13 @@ object CastDiagnosticsUtil {
|
|||||||
if (lhsType.constructor == rhsType.constructor) {
|
if (lhsType.constructor == rhsType.constructor) {
|
||||||
if (lhsType.arguments.all { TypeUtils.isTypeParameter(it.type) }) return true
|
if (lhsType.arguments.all { TypeUtils.isTypeParameter(it.type) }) return true
|
||||||
if (rhsType.arguments.all { TypeUtils.isTypeParameter(it.type) }) return true
|
if (rhsType.arguments.all { TypeUtils.isTypeParameter(it.type) }) return true
|
||||||
|
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 (isFinal(lhsType) || isFinal(rhsType)) return false
|
if (isFinal(lhsType) || isFinal(rhsType)) return false
|
||||||
|
|||||||
@@ -10,5 +10,18 @@ fun use() {
|
|||||||
test(Class("String", ""))
|
test(Class("String", ""))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun checkArrays(): Array<Any> {
|
||||||
|
val someArray = arrayOfNulls<Any>(5)
|
||||||
|
someArray <!CAST_NEVER_SUCCEEDS!>as<!> Array<Int>
|
||||||
|
return <!UNCHECKED_CAST!>someArray as Array<Any><!>
|
||||||
|
}
|
||||||
|
|
||||||
|
class Wrapper<T>(val x: T)
|
||||||
|
|
||||||
|
fun checkArrays2(): Array<Wrapper<String>> {
|
||||||
|
val someArray = arrayOf(Wrapper(1), Wrapper(2))
|
||||||
|
return <!UNCHECKED_CAST!>someArray as Array<Wrapper<String>><!>
|
||||||
|
}
|
||||||
|
|
||||||
fun println(s: String) = s
|
fun println(s: String) = s
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package
|
package
|
||||||
|
|
||||||
|
public fun checkArrays(): kotlin.Array<kotlin.Any>
|
||||||
|
public fun checkArrays2(): kotlin.Array<Wrapper<kotlin.String>>
|
||||||
public fun println(/*0*/ s: kotlin.String): kotlin.String
|
public fun println(/*0*/ s: kotlin.String): kotlin.String
|
||||||
public fun </*0*/ T> test(/*0*/ clazz: Class<T>): kotlin.Unit
|
public fun </*0*/ T> test(/*0*/ clazz: Class<T>): kotlin.Unit
|
||||||
public fun use(): kotlin.Unit
|
public fun use(): kotlin.Unit
|
||||||
@@ -12,3 +14,11 @@ public final class Class</*0*/ T> {
|
|||||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final class Wrapper</*0*/ T> {
|
||||||
|
public constructor Wrapper</*0*/ T>(/*0*/ x: T)
|
||||||
|
public final val x: T
|
||||||
|
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