146 lines
2.7 KiB
Plaintext
146 lines
2.7 KiB
Plaintext
class A() {
|
|
fun foo() {}
|
|
}
|
|
|
|
class B() : A() {
|
|
fun bar() {}
|
|
}
|
|
|
|
fun f9() {
|
|
val a : A?
|
|
a?.foo()
|
|
a?.<error>bar</error>()
|
|
if (a is B) {
|
|
<info descr="Automatically cast to B">a</info>.bar()
|
|
a.foo()
|
|
}
|
|
a?.foo()
|
|
a?.<error>bar</error>()
|
|
if (!(a is B)) {
|
|
a?.<error>bar</error>()
|
|
a?.foo()
|
|
}
|
|
if (!(a is B) || <info descr="Automatically cast to B">a</info>.bar() == ()) {
|
|
a?.<error>bar</error>()
|
|
}
|
|
if (!(a is B)) {
|
|
return;
|
|
}
|
|
<info descr="Automatically cast to B">a</info>.bar()
|
|
a.foo()
|
|
}
|
|
|
|
fun f10() {
|
|
val a : A?
|
|
if (!(a is B)) {
|
|
return;
|
|
}
|
|
if (!(a is B)) {
|
|
return;
|
|
}
|
|
}
|
|
|
|
class C() : A() {
|
|
fun bar() {
|
|
|
|
}
|
|
}
|
|
|
|
fun f10(a : A?) {
|
|
if (a is B) {
|
|
if (a is C) {
|
|
<info descr="Automatically cast to C">a</info>.bar();
|
|
}
|
|
}
|
|
}
|
|
|
|
fun f11(a : A?) {
|
|
when (a) {
|
|
is B => <info descr="Automatically cast to B">a</info>.bar()
|
|
is A => a.foo()
|
|
is Any => a.foo()
|
|
is Any? => a.<error>bar</error>()
|
|
else => a?.foo()
|
|
}
|
|
}
|
|
|
|
fun f12(a : A?) {
|
|
when (a) {
|
|
is B => <info descr="Automatically cast to B">a</info>.bar()
|
|
is A => a.foo()
|
|
is Any => a.foo();
|
|
is Any? => a.<error>bar</error>()
|
|
is val c : <error>B</error> => c.foo()
|
|
is val c is C => <info descr="Automatically cast to C">c</info>.bar()
|
|
is val c is C => <info descr="Automatically cast to C">a</info>.bar()
|
|
else => a?.foo()
|
|
}
|
|
|
|
if (a is val b) {
|
|
a?.<error>bar</error>()
|
|
b?.foo()
|
|
}
|
|
if (a is val b is B) {
|
|
b.foo()
|
|
<info descr="Automatically cast to B">a</info>.bar()
|
|
<info descr="Automatically cast to B">b</info>.bar()
|
|
}
|
|
}
|
|
|
|
fun f13(a : A?) {
|
|
if (a is val c is B) {
|
|
c.foo()
|
|
<info descr="Automatically cast to B">c</info>.bar()
|
|
}
|
|
else {
|
|
a?.foo()
|
|
<error>c</error>.bar()
|
|
}
|
|
|
|
a?.foo()
|
|
if (!(a is val c is B)) {
|
|
a?.foo()
|
|
<error>c</error>.bar()
|
|
}
|
|
else {
|
|
a.foo()
|
|
<info descr="Automatically cast to B">c</info>.bar()
|
|
}
|
|
|
|
a?.foo()
|
|
if (a is val c is B && a.foo() == () && <info descr="Automatically cast to B">c</info>.bar() == ()) {
|
|
c.foo()
|
|
<info descr="Automatically cast to B">c</info>.bar()
|
|
}
|
|
else {
|
|
a?.foo()
|
|
<error>c</error>.bar()
|
|
}
|
|
|
|
// a?.foo()
|
|
// if ((a is val c is B) || (a is val c is A)) {
|
|
// c.foo()
|
|
// c.bar()
|
|
// }
|
|
// else {
|
|
// a?.foo()
|
|
// c.bar()
|
|
// }
|
|
|
|
if (!(a is val c is B)) return
|
|
<info descr="Automatically cast to B">a</info>.bar()
|
|
c.foo()
|
|
<info descr="Automatically cast to B">c</info>.bar()
|
|
}
|
|
|
|
fun f14(a : A?) {
|
|
while (!(a is val c is B)) {
|
|
}
|
|
<info descr="Automatically cast to B">c</info>.bar()
|
|
}
|
|
fun f15(a : A?) {
|
|
do {
|
|
} while (!(a is val c is B))
|
|
<info descr="Automatically cast to B">c</info>.bar()
|
|
}
|