FIR: Support exhaustive whens on subjects of intersection type
This commit is contained in:
+2
-2
@@ -10,7 +10,7 @@ object CC : C()
|
||||
fun foo(a: A) {
|
||||
if (a is B) {
|
||||
if (a is C) {
|
||||
val t = <!NO_ELSE_IN_WHEN!>when<!> (a) {
|
||||
val t = when (a) {
|
||||
is CC -> "CC"
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ fun foo(a: A) {
|
||||
fun foo2(a: A) {
|
||||
if (a is C) {
|
||||
if (a is B) {
|
||||
val t = <!NO_ELSE_IN_WHEN!>when<!> (a) {
|
||||
val t = when (a) {
|
||||
is CC -> "CC"
|
||||
}
|
||||
}
|
||||
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
sealed class A {
|
||||
class A1 : A()
|
||||
class A2 : A()
|
||||
}
|
||||
|
||||
sealed class B {
|
||||
class B1 : B()
|
||||
class B2 : B()
|
||||
}
|
||||
|
||||
fun foo(a: A) {
|
||||
if (a !is B) return
|
||||
|
||||
when (a) {
|
||||
is A.A1 -> ""
|
||||
is A.A2 -> "v"
|
||||
}.length
|
||||
|
||||
when (a) {
|
||||
is A.A1 -> ""
|
||||
is A.A2 -> "v"
|
||||
}.length // OK
|
||||
|
||||
when (a) {
|
||||
is A.A1 -> ""
|
||||
is A.A2 -> "v"
|
||||
is B.B1 -> "..." // should be warning: unreachable code
|
||||
}.length // OK
|
||||
|
||||
when (a) {
|
||||
is A.A1 -> ""
|
||||
is B.B1 -> "..."
|
||||
is A.A2 -> "v"
|
||||
}.length // OK
|
||||
|
||||
<!NO_ELSE_IN_WHEN!>when<!> (a) {
|
||||
is A.A1 -> ""
|
||||
is B.B1 -> "..."
|
||||
}.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
sealed class A {
|
||||
class A1 : A()
|
||||
class A2 : A()
|
||||
}
|
||||
|
||||
sealed class B {
|
||||
class B1 : B()
|
||||
class B2 : B()
|
||||
}
|
||||
|
||||
fun foo(a: A) {
|
||||
if (a !is B) return
|
||||
|
||||
<!NO_ELSE_IN_WHEN!>when<!> (<!DEBUG_INFO_SMARTCAST!>a<!>) {
|
||||
is A.A1 -> ""
|
||||
is A.A2 -> "v"
|
||||
}.length
|
||||
|
||||
<!NO_ELSE_IN_WHEN!>when<!> (<!DEBUG_INFO_SMARTCAST!>a<!>) {
|
||||
is A.A1 -> ""
|
||||
is A.A2 -> "v"
|
||||
}.length // OK
|
||||
|
||||
<!NO_ELSE_IN_WHEN!>when<!> (<!DEBUG_INFO_SMARTCAST!>a<!>) {
|
||||
is A.A1 -> ""
|
||||
is A.A2 -> "v"
|
||||
is <!INCOMPATIBLE_TYPES!>B.B1<!> -> "..." // should be warning: unreachable code
|
||||
}.length // OK
|
||||
|
||||
<!NO_ELSE_IN_WHEN!>when<!> (<!DEBUG_INFO_SMARTCAST!>a<!>) {
|
||||
is A.A1 -> ""
|
||||
is <!INCOMPATIBLE_TYPES!>B.B1<!> -> "..."
|
||||
is A.A2 -> "v"
|
||||
}.length // OK
|
||||
|
||||
<!NO_ELSE_IN_WHEN!>when<!> (<!DEBUG_INFO_SMARTCAST!>a<!>) {
|
||||
is A.A1 -> ""
|
||||
is <!INCOMPATIBLE_TYPES!>B.B1<!> -> "..."
|
||||
}.length
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
package
|
||||
|
||||
public fun foo(/*0*/ a: A): kotlin.Unit
|
||||
|
||||
public sealed class A {
|
||||
protected constructor A()
|
||||
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
|
||||
|
||||
public final class A1 : A {
|
||||
public constructor A1()
|
||||
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
|
||||
}
|
||||
|
||||
public final class A2 : A {
|
||||
public constructor A2()
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class B {
|
||||
protected constructor B()
|
||||
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
|
||||
|
||||
public final class B1 : B {
|
||||
public constructor B1()
|
||||
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
|
||||
}
|
||||
|
||||
public final class B2 : B {
|
||||
public constructor B2()
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// SKIP_TXT
|
||||
// FIR_IDENTICAL
|
||||
// !CHECK_TYPE
|
||||
|
||||
sealed class KtClassifierSymbol
|
||||
|
||||
interface KtNamedSymbol
|
||||
|
||||
abstract class KtTypeParameterSymbol : KtClassifierSymbol() {}
|
||||
|
||||
sealed class KtClassLikeSymbol : KtClassifierSymbol() {}
|
||||
|
||||
fun foo(symbol: KtClassifierSymbol) {
|
||||
if (symbol !is KtNamedSymbol) return
|
||||
val x = when (symbol) {
|
||||
is KtClassLikeSymbol -> "1"
|
||||
is KtTypeParameterSymbol -> "2"
|
||||
}
|
||||
|
||||
x checkType { _<String>() }
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package
|
||||
|
||||
public fun foo(/*0*/ symbol: KtClassifierSymbol): kotlin.Unit
|
||||
|
||||
public sealed class KtClassLikeSymbol : KtClassifierSymbol {
|
||||
protected constructor KtClassLikeSymbol()
|
||||
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
|
||||
}
|
||||
|
||||
public sealed class KtClassifierSymbol {
|
||||
protected constructor KtClassifierSymbol()
|
||||
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
|
||||
}
|
||||
|
||||
public interface KtNamedSymbol {
|
||||
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
|
||||
}
|
||||
|
||||
public abstract class KtTypeParameterSymbol : KtClassifierSymbol {
|
||||
public constructor KtTypeParameterSymbol()
|
||||
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