Introduction of CastedClassReceiver and its handling in codegen #KT-6744 Fixed

ClassReceiver converted to Kotlin
Also #KT-7617 Fixed
This commit is contained in:
Mikhail Glukhikh
2015-11-10 16:27:58 +03:00
parent e1134b278c
commit 0d35033106
15 changed files with 219 additions and 58 deletions
@@ -0,0 +1,17 @@
open class SuperFoo {
public fun bar(): String {
if (this is Foo) {
superFoo() // Smart cast
return baz() // Cannot be cast
}
return baz()
}
public fun baz() = "OK"
}
class Foo : SuperFoo() {
public fun superFoo() {}
}
fun box(): String = Foo().bar()
@@ -0,0 +1,7 @@
class A {
fun foo() = "OK"
}
fun A?.bar() = if (this != null) foo() else "FAIL"
fun box() = A().bar()
@@ -0,0 +1,20 @@
open class A {
open val a = "OK"
}
class B : A() {
override val a = "FAIL"
fun foo() = "CRUSH"
}
class C {
fun A?.complex(): String {
if (this is B) return foo()
else if (this != null) return a
else return "???"
}
fun bar() = A().complex()
}
fun box() = C().bar()
@@ -0,0 +1,13 @@
open class A {
class B : A() {
val a = "FAIL"
}
fun foo(): String {
if (this is B) return a
return "OK"
}
}
fun box(): String = A().foo()
@@ -0,0 +1,11 @@
open class A {
fun f(): String =
when (this) {
is B -> x
else -> "FAIL"
}
}
class B(val x: String) : A()
fun box() = B("OK").f()
@@ -0,0 +1,13 @@
open class A {
open fun foo() = "FAIL"
fun bar() = if (this is C) foo() else foo()
}
open class B : A()
open class C : B() {
override fun foo() = "OK"
}
fun box() = C().bar()