[FIR-TEST] Add new testdata generated after changes in previous commit
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
sealed class Base
|
||||
|
||||
class Derived: Base() {
|
||||
class Derived2: Base()
|
||||
}
|
||||
|
||||
fun test() {
|
||||
class Local: Base()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
sealed class Sealed(val x: Int) {
|
||||
object First: Sealed(12)
|
||||
open class NonFirst(x: Int, val y: Int): Sealed(x) {
|
||||
object Second: NonFirst(34, 2)
|
||||
object Third: NonFirst(56, 3)
|
||||
// It's ALLOWED to inherit Sealed also here
|
||||
object Fourth: Sealed(78)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
sealed class Stmt
|
||||
|
||||
class ForStmt : Stmt()
|
||||
|
||||
sealed class Expr : Stmt() {
|
||||
object BinExpr : Expr()
|
||||
}
|
||||
|
||||
fun test(x: Stmt): String =
|
||||
when (x) {
|
||||
is Expr -> "expr"
|
||||
is Stmt -> "stmt"
|
||||
}
|
||||
|
||||
fun test2(x: Stmt): String =
|
||||
when (x) {
|
||||
is Expr -> "expr"
|
||||
}
|
||||
|
||||
fun test3(x: Expr): String =
|
||||
when (x) {
|
||||
is Stmt -> "stmt"
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
sealed class Base {
|
||||
sealed class A : Base() {
|
||||
object A1 : A()
|
||||
sealed class A2 : A()
|
||||
}
|
||||
sealed class B : Base() {
|
||||
sealed class B1 : B()
|
||||
object B2 : B()
|
||||
}
|
||||
|
||||
fun foo() = when (this) {
|
||||
is A -> 1
|
||||
is B.B1 -> 2
|
||||
B.B2 -> 3
|
||||
// No else required
|
||||
}
|
||||
|
||||
fun bar() = when (this) {
|
||||
is A -> 1
|
||||
is B.B1 -> 2
|
||||
}
|
||||
|
||||
fun baz() = when (this) {
|
||||
is A -> 1
|
||||
B.B2 -> 3
|
||||
// No else required (no possible B1 instances)
|
||||
}
|
||||
|
||||
fun negated() = when (this) {
|
||||
!is A -> 1
|
||||
A.A1 -> 2
|
||||
is A.A2 -> 3
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
sealed class A
|
||||
sealed class B : A()
|
||||
|
||||
class C : B()
|
||||
class D : B()
|
||||
|
||||
fun test(a: A): Any {
|
||||
return when (a) {
|
||||
is C -> ""
|
||||
is D -> ""
|
||||
}
|
||||
}
|
||||
|
||||
fun test2(a: A): Any {
|
||||
return when (a) {
|
||||
is B -> ""
|
||||
}
|
||||
}
|
||||
|
||||
fun test3(a: A): Any {
|
||||
return when (a) {
|
||||
is D -> ""
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
sealed class Sealed(val x: Int) {
|
||||
object First: Sealed(12)
|
||||
open class NonFirst(x: Int, val y: Int): Sealed(x) {
|
||||
object Second: NonFirst(34, 2)
|
||||
object Third: NonFirst(56, 3)
|
||||
}
|
||||
}
|
||||
|
||||
fun foo(s: Sealed): Int {
|
||||
return when(s) {
|
||||
is Sealed.First -> 1
|
||||
is Sealed.NonFirst -> 0
|
||||
// no else required
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
sealed class Sealed() {
|
||||
object First: Sealed()
|
||||
open class NonFirst: Sealed() {
|
||||
object Second: NonFirst()
|
||||
object Third: NonFirst()
|
||||
// It's ALLOWED to inherit Sealed also from here
|
||||
object Fourth: Sealed()
|
||||
}
|
||||
}
|
||||
|
||||
fun foo(s: Sealed) = when(s) {
|
||||
Sealed.First -> 1
|
||||
is Sealed.NonFirst -> 2
|
||||
Sealed.NonFirst.Fourth -> 4
|
||||
// no else required
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
sealed class Sealed() {
|
||||
object First: Sealed()
|
||||
open class NonFirst: Sealed() {
|
||||
class NonSecond: NonFirst() {
|
||||
object Third: Sealed()
|
||||
class NonThird: Sealed() {
|
||||
object Fourth: NonFirst()
|
||||
class Fifth: Sealed()
|
||||
}
|
||||
}
|
||||
object Second: Sealed()
|
||||
}
|
||||
}
|
||||
|
||||
fun foo(s: Sealed) = when(s) {
|
||||
Sealed.First -> 1
|
||||
is Sealed.NonFirst -> 2
|
||||
Sealed.NonFirst.Second -> 4
|
||||
Sealed.NonFirst.NonSecond.Third -> 6
|
||||
is Sealed.NonFirst.NonSecond.NonThird -> 8
|
||||
is Sealed.NonFirst.NonSecond.NonThird.Fifth -> 10
|
||||
// no else required
|
||||
}
|
||||
|
||||
fun fooWithElse(s: Sealed) = when(s) {
|
||||
Sealed.First -> 1
|
||||
Sealed.NonFirst.NonSecond.Third -> 6
|
||||
is Sealed.NonFirst.NonSecond.NonThird.Fifth -> 10
|
||||
else -> 0
|
||||
}
|
||||
|
||||
fun fooWithoutElse(s: Sealed) = when(s) {
|
||||
Sealed.First -> 1
|
||||
is Sealed.NonFirst -> 2
|
||||
Sealed.NonFirst.NonSecond.Third -> 6
|
||||
is Sealed.NonFirst.NonSecond.NonThird -> 8
|
||||
is Sealed.NonFirst.NonSecond.NonThird.Fifth -> 10
|
||||
}
|
||||
|
||||
fun barWithoutElse(s: Sealed) = when(s) {
|
||||
Sealed.First -> 1
|
||||
is Sealed.NonFirst -> 2
|
||||
Sealed.NonFirst.Second -> 4
|
||||
is Sealed.NonFirst.NonSecond.NonThird -> 8
|
||||
is Sealed.NonFirst.NonSecond.NonThird.Fifth -> 10
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
sealed class Sealed(val x: Int) {
|
||||
object First: Sealed(12)
|
||||
open class NonFirst(x: Int, val y: Int): Sealed(x) {
|
||||
object Second: NonFirst(34, 2)
|
||||
object Third: NonFirst(56, 3)
|
||||
}
|
||||
}
|
||||
|
||||
fun foo(s: Sealed): Int {
|
||||
return when(s) {
|
||||
is Sealed.First -> 1
|
||||
!is Sealed.First -> 0
|
||||
// no else required
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
sealed class Sealed(val x: Int) {
|
||||
object First: Sealed(12)
|
||||
open class NonFirst(x: Int, val y: Int): Sealed(x) {
|
||||
object Second: NonFirst(34, 2)
|
||||
object Third: NonFirst(56, 3)
|
||||
}
|
||||
object Last: Sealed(78)
|
||||
}
|
||||
|
||||
fun foo(s: Sealed): Int {
|
||||
return when(s) {
|
||||
!is Sealed.First -> 1
|
||||
!is Sealed.Last -> 0
|
||||
// no else required
|
||||
}
|
||||
}
|
||||
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
sealed class Sealed {
|
||||
object First: Sealed()
|
||||
sealed class NonFirst {
|
||||
object Second: NonFirst()
|
||||
object Third: NonFirst()
|
||||
object Fourth: Sealed()
|
||||
}
|
||||
}
|
||||
|
||||
fun foo(s: Sealed, nf: Sealed.NonFirst): Int {
|
||||
val si = when(s) {
|
||||
Sealed.First -> 1
|
||||
Sealed.NonFirst.Fourth -> 4
|
||||
}
|
||||
val nfi = when(nf) {
|
||||
Sealed.NonFirst.Second -> 2
|
||||
Sealed.NonFirst.Third -> 3
|
||||
}
|
||||
return si <!UNRESOLVED_REFERENCE!>+<!> nfi
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
sealed class Sealed(val x: Int) {
|
||||
object First: Sealed(12)
|
||||
open class NonFirst(x: Int, val y: Int): Sealed(x) {
|
||||
object Second: NonFirst(34, 2)
|
||||
object Third: NonFirst(56, 3)
|
||||
}
|
||||
}
|
||||
|
||||
fun foo(s: Sealed?): Int {
|
||||
return when(s) {
|
||||
is Sealed.First -> 1
|
||||
is Sealed.NonFirst -> 0
|
||||
null -> -1
|
||||
// no else required
|
||||
}
|
||||
}
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
sealed class Sealed(val x: Int) {
|
||||
data class Tuple(val x: Int, val y: Int)
|
||||
object First: Sealed(12)
|
||||
open class NonFirst(tuple: Tuple): Sealed(tuple.x) {
|
||||
val y: Int = tuple.y
|
||||
object Second: NonFirst(Tuple(34, 2))
|
||||
object Third: NonFirst(Tuple(56, 3))
|
||||
}
|
||||
}
|
||||
|
||||
fun foo(s: Sealed): Int {
|
||||
return when(s) {
|
||||
is Sealed.First -> 1
|
||||
is Sealed.NonFirst -> 0
|
||||
// no else required
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
sealed class Sealed(val x: Int) {
|
||||
object First: Sealed(12)
|
||||
open class NonFirst(x: Int, val y: Int): Sealed(x) {
|
||||
object Second: NonFirst(34, 2)
|
||||
object Third: NonFirst(56, 3)
|
||||
}
|
||||
}
|
||||
|
||||
fun foo(s: Sealed): Int {
|
||||
return when(s) {
|
||||
is Sealed.NonFirst -> 0
|
||||
else -> -1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
sealed class Sealed {
|
||||
object First: Sealed()
|
||||
open class NonFirst: Sealed() {
|
||||
object Second: NonFirst()
|
||||
object Third: NonFirst()
|
||||
fun foo(): Int {
|
||||
val s = object: Sealed() {}
|
||||
class Local: Sealed() {}
|
||||
return s.hashCode()
|
||||
}
|
||||
}
|
||||
val p: Sealed = object: Sealed() {}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fun foo() {
|
||||
sealed class My
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
// See KT-10648: Exhaustiveness check does not work with nested sealed hierarchy
|
||||
sealed class Base {
|
||||
sealed class A : Base() {
|
||||
class A1 : A()
|
||||
class A2 : A()
|
||||
}
|
||||
sealed class B : Base() {
|
||||
class B1 : B()
|
||||
class B2 : B()
|
||||
}
|
||||
}
|
||||
|
||||
fun foo(b: Base) = when (b) {
|
||||
is Base.A -> when(b) {
|
||||
is Base.A.A1 -> 1
|
||||
is Base.A.A2 -> 2
|
||||
}
|
||||
is Base.B -> when(b) {
|
||||
is Base.B.B1 -> 3
|
||||
is Base.B.B2 -> 4
|
||||
}
|
||||
}
|
||||
|
||||
fun bar(b: Base?) = if (b == null) 0 else when (b) {
|
||||
is Base.A -> when(b) {
|
||||
is Base.A.A1 -> 1
|
||||
is Base.A.A2 -> 2
|
||||
}
|
||||
is Base.B -> when(b) {
|
||||
is Base.B.B1 -> 3
|
||||
is Base.B.B2 -> 4
|
||||
}
|
||||
}
|
||||
|
||||
fun gav(b: Base?) = when (b) {
|
||||
null -> 0
|
||||
is Base.A -> when(b) {
|
||||
is Base.A.A1 -> 1
|
||||
is Base.A.A2 -> 2
|
||||
}
|
||||
is Base.B -> when(b) {
|
||||
is Base.B.B1 -> 3
|
||||
is Base.B.B2 -> 4
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
sealed class Base {
|
||||
fun foo() = Base()
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
class A {
|
||||
sealed class Base
|
||||
}
|
||||
|
||||
class Derived : A.Base()
|
||||
|
||||
fun test() {
|
||||
class DerivedLocal : A.Base()
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
sealed enum class SealedEnum {
|
||||
FIRST,
|
||||
SECOND;
|
||||
|
||||
class Derived: SealedEnum()
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
final sealed class Base {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
sealed interface Base {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
sealed object Sealed {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
open sealed class Base {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
sealed class Sealed(val x: Int) {
|
||||
object First: Sealed(12)
|
||||
open class NonFirst(x: Int, val y: Int): Sealed(x) {
|
||||
object Second: NonFirst(34, 2)
|
||||
object Third: NonFirst(56, 3)
|
||||
}
|
||||
}
|
||||
|
||||
fun foo(s: Sealed): Int {
|
||||
return when(s) {
|
||||
is Sealed.NonFirst -> 0
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
sealed class Sealed(val x: Int) {
|
||||
object First: Sealed(12)
|
||||
open class NonFirst(x: Int, val y: Int): Sealed(x) {
|
||||
object Second: NonFirst(34, 2)
|
||||
object Third: NonFirst(56, 3)
|
||||
}
|
||||
}
|
||||
|
||||
fun foo(s: Sealed): Int {
|
||||
return when(s) {
|
||||
!is Sealed.NonFirst -> 1
|
||||
}
|
||||
}
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
sealed class Sealed(val x: Int) {
|
||||
interface ITuple {
|
||||
val x: Int
|
||||
val y: Int
|
||||
}
|
||||
class Tuple(override val x: Int, override val y: Int): ITuple
|
||||
object First: Sealed(12)
|
||||
open class NonFirst(tuple: Tuple): Sealed(tuple.x), ITuple {
|
||||
override val y: Int = tuple.y
|
||||
object Second: NonFirst(Tuple(34, 2))
|
||||
class Third: NonFirst(Tuple(56, 3))
|
||||
}
|
||||
}
|
||||
|
||||
fun foo(s: Sealed): Int {
|
||||
return when(s) {
|
||||
is Sealed.First -> 1
|
||||
!is Sealed.ITuple -> 0
|
||||
// else required
|
||||
}
|
||||
}
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
sealed class Sealed {
|
||||
object First: Sealed()
|
||||
open class NonFirst: Sealed() {
|
||||
object Second: NonFirst()
|
||||
object Third: NonFirst()
|
||||
}
|
||||
}
|
||||
|
||||
fun foo(s: Sealed): Int {
|
||||
return when(s) {
|
||||
is Sealed.First -> 1
|
||||
!is Any -> 0
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
sealed class Sealed protected constructor(val x: Int) {
|
||||
object FIRST : Sealed()
|
||||
|
||||
public constructor(): this(42)
|
||||
|
||||
constructor(y: Int, z: Int): this(y + z)
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// See KT-9244
|
||||
|
||||
sealed class Foo {
|
||||
class Bar : Foo()
|
||||
class Baz : Foo()
|
||||
}
|
||||
|
||||
// The following warning seems incorrect here
|
||||
// "Foo is a final type, and thus a value of the type parameter is predetermined"
|
||||
fun <T : Foo> doit(arg: T): T = arg
|
||||
@@ -0,0 +1,20 @@
|
||||
sealed class Operation(val left: Int, val right: Int) {
|
||||
abstract fun exec(): Int
|
||||
class Plus(left: Int, right: Int): Operation(left, right) {
|
||||
override fun exec(): Int = left + right
|
||||
}
|
||||
class Minus(left: Int, right: Int): Operation(left, right) {
|
||||
override fun exec(): Int = left - right
|
||||
}
|
||||
class Times(left: Int, right: Int): Operation(left, right) {
|
||||
override fun exec(): Int = left * right
|
||||
}
|
||||
class Slash(left: Int, right: Int): Operation(left, right) {
|
||||
override fun exec(): Int = left / right
|
||||
}
|
||||
}
|
||||
|
||||
fun priority(op: Operation) = when(op) {
|
||||
is Operation.Plus, is Operation.Minus -> 1
|
||||
is Operation.Times, is Operation.Slash -> 2
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
abstract sealed class Base {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
sealed class Tree {
|
||||
object Empty: Tree()
|
||||
class Leaf(val x: Int): Tree()
|
||||
class Node(val left: Tree, val right: Tree): Tree()
|
||||
|
||||
fun max(): Int {
|
||||
when(this) {
|
||||
is Empty -> return -1
|
||||
is Leaf -> return this.x
|
||||
is Node -> return this.left.max()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
sealed class Tree {
|
||||
object Empty: Tree()
|
||||
class Leaf(val x: Int): Tree()
|
||||
class Node(val left: Tree, val right: Tree): Tree()
|
||||
|
||||
fun max(): Int = when(this) {
|
||||
is Empty -> -1
|
||||
is Leaf -> this.x
|
||||
is Node -> this.left.max()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
sealed class Tree {
|
||||
object Empty: Tree()
|
||||
class Leaf(val x: Int): Tree()
|
||||
class Node(val left: Tree, val right: Tree): Tree()
|
||||
|
||||
fun max(): Int = when(this) {
|
||||
Empty -> -1
|
||||
is Leaf -> this.x
|
||||
is Node -> this.left.max()
|
||||
}
|
||||
|
||||
fun maxIsClass(): Int = when(this) {
|
||||
Empty -> -1
|
||||
Leaf -> 0
|
||||
is Node -> this.left.max()
|
||||
}
|
||||
|
||||
fun maxWithElse(): Int = when(this) {
|
||||
is Leaf -> this.x
|
||||
is Node -> this.left.max()
|
||||
else -> -1
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION
|
||||
sealed class Sealed {
|
||||
|
||||
}
|
||||
|
||||
fun foo(s: Sealed): Int {
|
||||
return when(s) {
|
||||
// We do not return anything, so else branch must be here
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
interface Parent
|
||||
interface Child : Parent
|
||||
|
||||
sealed class Page : Parent {
|
||||
object One : Page(), Child
|
||||
object Two : Page(), Child
|
||||
}
|
||||
|
||||
// Ok: page is a Parent so it can be easily a Child
|
||||
fun test(page: Page): Boolean = page is Child
|
||||
Reference in New Issue
Block a user