Fix casts to type parameters with multiple bounds (#2891)

Fix #2888
This commit is contained in:
SvyatoslavScherbina
2019-04-18 14:41:45 +03:00
parent 85485522cf
commit 44dbf684e5
3 changed files with 38 additions and 1 deletions
@@ -61,7 +61,7 @@ private class TypeOperatorTransformer(val context: CommonBackendContext, val fun
return when (classifier) {
is IrClassSymbol -> this
is IrTypeParameterSymbol -> {
val upperBound = classifier.owner.superTypes.singleOrNull() ?:
val upperBound = classifier.owner.superTypes.firstOrNull() ?:
TODO("${classifier.descriptor} : ${classifier.descriptor.upperBounds}")
if (this.hasQuestionMark) {
+6
View File
@@ -574,6 +574,12 @@ task unchecked_cast3(type: RunKonanTest) {
source = "codegen/basics/unchecked_cast3.kt"
}
task unchecked_cast4(type: RunKonanTest) {
expectedFail = (project.testTarget == 'wasm32') // Uses exceptions.
goldValue = "Ok\n"
source = "codegen/basics/unchecked_cast4.kt"
}
task null_check(type: RunKonanTest) {
source = "codegen/basics/null_check.kt"
}
@@ -0,0 +1,31 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.basics.unchecked_cast4
import kotlin.test.*
@Test
fun runTest() {
CI1I2().uncheckedCast<CI1I2>()
CI1I2().uncheckedCast<OtherCI1I2>()
assertFailsWith<ClassCastException> {
Any().uncheckedCast<CI1I2>()
}
println("Ok")
}
fun <R : C> Any?.uncheckedCast() where R : I1, R : I2 {
this as R
}
interface I1
interface I2
open class C
class CI1I2 : C(), I1, I2
class OtherCI1I2 : C(), I1, I2