diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/CastDiagnosticsUtil.kt b/compiler/frontend/src/org/jetbrains/kotlin/types/CastDiagnosticsUtil.kt index 400f1d4204d..ba09dd4bcec 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/CastDiagnosticsUtil.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/CastDiagnosticsUtil.kt @@ -43,6 +43,13 @@ object CastDiagnosticsUtil { if (lhsType.constructor == rhsType.constructor) { if (lhsType.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 diff --git a/compiler/testData/diagnostics/tests/cast/AsWithOtherParameter.kt b/compiler/testData/diagnostics/tests/cast/AsWithOtherParameter.kt index 6c225909d01..97e355b37e8 100644 --- a/compiler/testData/diagnostics/tests/cast/AsWithOtherParameter.kt +++ b/compiler/testData/diagnostics/tests/cast/AsWithOtherParameter.kt @@ -10,5 +10,18 @@ fun use() { test(Class("String", "")) } +fun checkArrays(): Array { + val someArray = arrayOfNulls(5) + someArray as Array + return someArray as Array +} + +class Wrapper(val x: T) + +fun checkArrays2(): Array> { + val someArray = arrayOf(Wrapper(1), Wrapper(2)) + return someArray as Array> +} + fun println(s: String) = s diff --git a/compiler/testData/diagnostics/tests/cast/AsWithOtherParameter.txt b/compiler/testData/diagnostics/tests/cast/AsWithOtherParameter.txt index 4ff48442c2d..e27b19b636e 100644 --- a/compiler/testData/diagnostics/tests/cast/AsWithOtherParameter.txt +++ b/compiler/testData/diagnostics/tests/cast/AsWithOtherParameter.txt @@ -1,5 +1,7 @@ package +public fun checkArrays(): kotlin.Array +public fun checkArrays2(): kotlin.Array> public fun println(/*0*/ s: kotlin.String): kotlin.String public fun test(/*0*/ clazz: Class): kotlin.Unit public fun use(): kotlin.Unit @@ -12,3 +14,11 @@ public final class Class { public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } + +public final class Wrapper { + public constructor Wrapper(/*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 +}