diff --git a/compiler/testData/ir/irText/classes/annotationClasses.fir.kt.txt b/compiler/testData/ir/irText/classes/annotationClasses.fir.kt.txt new file mode 100644 index 00000000000..d6e3ed1c3ef --- /dev/null +++ b/compiler/testData/ir/irText/classes/annotationClasses.fir.kt.txt @@ -0,0 +1,31 @@ +annotation class Test1 : Annotation { + constructor(x: Int) /* primary */ + val x: Int + field = x + get + +} + +annotation class Test2 : Annotation { + constructor(x: Int = 0) /* primary */ + val x: Int + field = x + get + +} + +annotation class Test3 : Annotation { + constructor(x: Test1) /* primary */ + val x: Test1 + field = x + get + +} + +annotation class Test4 : Annotation { + constructor(vararg xs: Int) /* primary */ + val xs: IntArray + field = xs + get + +} diff --git a/compiler/testData/ir/irText/classes/argumentReorderingInDelegatingConstructorCall.fir.kt.txt b/compiler/testData/ir/irText/classes/argumentReorderingInDelegatingConstructorCall.fir.kt.txt new file mode 100644 index 00000000000..feb8a4114e0 --- /dev/null +++ b/compiler/testData/ir/irText/classes/argumentReorderingInDelegatingConstructorCall.fir.kt.txt @@ -0,0 +1,44 @@ +open class Base { + constructor(x: Int, y: Int) /* primary */ { + super/*Any*/() + /* () */ + + } + + val x: Int + field = x + get + + val y: Int + field = y + get + +} + +class Test1 : Base { + constructor(xx: Int, yy: Int) /* primary */ { + { // BLOCK + super/*Base*/(x = xx, y = yy) + } + /* () */ + + } + +} + +class Test2 : Base { + constructor(xx: Int, yy: Int) { + { // BLOCK + super/*Base*/(x = xx, y = yy) + } + /* () */ + + } + + constructor(xxx: Int, yyy: Int, a: Any) { + { // BLOCK + this/*Test2*/(xx = xxx, yy = yyy) + } + } + +} diff --git a/compiler/testData/ir/irText/classes/classes.fir.kt.txt b/compiler/testData/ir/irText/classes/classes.fir.kt.txt new file mode 100644 index 00000000000..f414e52079e --- /dev/null +++ b/compiler/testData/ir/irText/classes/classes.fir.kt.txt @@ -0,0 +1,39 @@ +class TestClass { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +interface TestInterface { + +} + +object TestObject { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +annotation class TestAnnotationClass : Annotation { + constructor() /* primary */ + +} + +enum class TestEnumClass : Enum { + private constructor() /* primary */ { + super/*Enum*/() + /* () */ + + } + + fun values(): Array /* Synthetic body for ENUM_VALUES */ + + fun valueOf(value: String): TestEnumClass /* Synthetic body for ENUM_VALUEOF */ + +} diff --git a/compiler/testData/ir/irText/classes/cloneable.fir.kt.txt b/compiler/testData/ir/irText/classes/cloneable.fir.kt.txt new file mode 100644 index 00000000000..d5d61aabac7 --- /dev/null +++ b/compiler/testData/ir/irText/classes/cloneable.fir.kt.txt @@ -0,0 +1,34 @@ +class A : Cloneable { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +interface I : Cloneable { + +} + +class C : I { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +class OC : I { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + protected override fun clone(): OC { + return OC() + } + +} diff --git a/compiler/testData/ir/irText/classes/dataClassWithArrayMembers.fir.kt.txt b/compiler/testData/ir/irText/classes/dataClassWithArrayMembers.fir.kt.txt new file mode 100644 index 00000000000..065d0ceeae6 --- /dev/null +++ b/compiler/testData/ir/irText/classes/dataClassWithArrayMembers.fir.kt.txt @@ -0,0 +1,228 @@ +data class Test1 { + constructor(stringArray: Array, charArray: CharArray, booleanArray: BooleanArray, byteArray: ByteArray, shortArray: ShortArray, intArray: IntArray, longArray: LongArray, floatArray: FloatArray, doubleArray: DoubleArray) /* primary */ { + super/*Any*/() + /* () */ + + } + + val stringArray: Array + field = stringArray + get + + val charArray: CharArray + field = charArray + get + + val booleanArray: BooleanArray + field = booleanArray + get + + val byteArray: ByteArray + field = byteArray + get + + val shortArray: ShortArray + field = shortArray + get + + val intArray: IntArray + field = intArray + get + + val longArray: LongArray + field = longArray + get + + val floatArray: FloatArray + field = floatArray + get + + val doubleArray: DoubleArray + field = doubleArray + get + + fun component1(): Array { + return .#stringArray + } + + fun component2(): CharArray { + return .#charArray + } + + fun component3(): BooleanArray { + return .#booleanArray + } + + fun component4(): ByteArray { + return .#byteArray + } + + fun component5(): ShortArray { + return .#shortArray + } + + fun component6(): IntArray { + return .#intArray + } + + fun component7(): LongArray { + return .#longArray + } + + fun component8(): FloatArray { + return .#floatArray + } + + fun component9(): DoubleArray { + return .#doubleArray + } + + fun copy(stringArray: Array = .#stringArray, charArray: CharArray = .#charArray, booleanArray: BooleanArray = .#booleanArray, byteArray: ByteArray = .#byteArray, shortArray: ShortArray = .#shortArray, intArray: IntArray = .#intArray, longArray: LongArray = .#longArray, floatArray: FloatArray = .#floatArray, doubleArray: DoubleArray = .#doubleArray): Test1 { + return Test1(stringArray = stringArray, charArray = charArray, booleanArray = booleanArray, byteArray = byteArray, shortArray = shortArray, intArray = intArray, longArray = longArray, floatArray = floatArray, doubleArray = doubleArray) + } + + override fun equals(other: Any?): Boolean { + when { + EQEQEQ(arg0 = , arg1 = other) -> return true + } + when { + other !is Test1 -> return false + } + val tmp0_other_with_cast: Test1 = other as Test1 + when { + EQEQ(arg0 = .#stringArray, arg1 = tmp0_other_with_cast.#stringArray).not() -> return false + } + when { + EQEQ(arg0 = .#charArray, arg1 = tmp0_other_with_cast.#charArray).not() -> return false + } + when { + EQEQ(arg0 = .#booleanArray, arg1 = tmp0_other_with_cast.#booleanArray).not() -> return false + } + when { + EQEQ(arg0 = .#byteArray, arg1 = tmp0_other_with_cast.#byteArray).not() -> return false + } + when { + EQEQ(arg0 = .#shortArray, arg1 = tmp0_other_with_cast.#shortArray).not() -> return false + } + when { + EQEQ(arg0 = .#intArray, arg1 = tmp0_other_with_cast.#intArray).not() -> return false + } + when { + EQEQ(arg0 = .#longArray, arg1 = tmp0_other_with_cast.#longArray).not() -> return false + } + when { + EQEQ(arg0 = .#floatArray, arg1 = tmp0_other_with_cast.#floatArray).not() -> return false + } + when { + EQEQ(arg0 = .#doubleArray, arg1 = tmp0_other_with_cast.#doubleArray).not() -> return false + } + return true + } + + override fun hashCode(): Int { + var result: Int = dataClassArrayMemberHashCode(arg0 = .#stringArray) + result = result.times(other = 31).plus(other = dataClassArrayMemberHashCode(arg0 = .#charArray)) + result = result.times(other = 31).plus(other = dataClassArrayMemberHashCode(arg0 = .#booleanArray)) + result = result.times(other = 31).plus(other = dataClassArrayMemberHashCode(arg0 = .#byteArray)) + result = result.times(other = 31).plus(other = dataClassArrayMemberHashCode(arg0 = .#shortArray)) + result = result.times(other = 31).plus(other = dataClassArrayMemberHashCode(arg0 = .#intArray)) + result = result.times(other = 31).plus(other = dataClassArrayMemberHashCode(arg0 = .#longArray)) + result = result.times(other = 31).plus(other = dataClassArrayMemberHashCode(arg0 = .#floatArray)) + result = result.times(other = 31).plus(other = dataClassArrayMemberHashCode(arg0 = .#doubleArray)) + return result + } + + override fun toString(): String { + return "Test1(" + "stringArray=" + dataClassArrayMemberToString(arg0 = .#stringArray) + ", " + "charArray=" + dataClassArrayMemberToString(arg0 = .#charArray) + ", " + "booleanArray=" + dataClassArrayMemberToString(arg0 = .#booleanArray) + ", " + "byteArray=" + dataClassArrayMemberToString(arg0 = .#byteArray) + ", " + "shortArray=" + dataClassArrayMemberToString(arg0 = .#shortArray) + ", " + "intArray=" + dataClassArrayMemberToString(arg0 = .#intArray) + ", " + "longArray=" + dataClassArrayMemberToString(arg0 = .#longArray) + ", " + "floatArray=" + dataClassArrayMemberToString(arg0 = .#floatArray) + ", " + "doubleArray=" + dataClassArrayMemberToString(arg0 = .#doubleArray) + ")" + } + +} + +data class Test2 { + constructor(genericArray: Array) /* primary */ { + super/*Any*/() + /* () */ + + } + + val genericArray: Array + field = genericArray + get + + fun component1(): Array { + return .#genericArray + } + + fun copy(genericArray: Array = .#genericArray): Test2 { + return Test2(genericArray = genericArray) + } + + override fun equals(other: Any?): Boolean { + when { + EQEQEQ(arg0 = , arg1 = other) -> return true + } + when { + other !is Test2 -> return false + } + val tmp0_other_with_cast: Test2 = other as Test2 + when { + EQEQ(arg0 = .#genericArray, arg1 = tmp0_other_with_cast.#genericArray).not() -> return false + } + return true + } + + override fun hashCode(): Int { + return dataClassArrayMemberHashCode(arg0 = .#genericArray) + } + + override fun toString(): String { + return "Test2(" + "genericArray=" + dataClassArrayMemberToString(arg0 = .#genericArray) + ")" + } + +} + +data class Test3 { + constructor(anyArrayN: Array?) /* primary */ { + super/*Any*/() + /* () */ + + } + + val anyArrayN: Array? + field = anyArrayN + get + + fun component1(): Array? { + return .#anyArrayN + } + + fun copy(anyArrayN: Array? = .#anyArrayN): Test3 { + return Test3(anyArrayN = anyArrayN) + } + + override fun equals(other: Any?): Boolean { + when { + EQEQEQ(arg0 = , arg1 = other) -> return true + } + when { + other !is Test3 -> return false + } + val tmp0_other_with_cast: Test3 = other as Test3 + when { + EQEQ(arg0 = .#anyArrayN, arg1 = tmp0_other_with_cast.#anyArrayN).not() -> return false + } + return true + } + + override fun hashCode(): Int { + return when { + EQEQ(arg0 = .#anyArrayN, arg1 = null) -> 0 + else -> dataClassArrayMemberHashCode(arg0 = .#anyArrayN) + } + } + + override fun toString(): String { + return "Test3(" + "anyArrayN=" + dataClassArrayMemberToString(arg0 = .#anyArrayN) + ")" + } + +} diff --git a/compiler/testData/ir/irText/classes/dataClasses.fir.kt.txt b/compiler/testData/ir/irText/classes/dataClasses.fir.kt.txt new file mode 100644 index 00000000000..9203bc4657f --- /dev/null +++ b/compiler/testData/ir/irText/classes/dataClasses.fir.kt.txt @@ -0,0 +1,199 @@ +data class Test1 { + constructor(x: Int, y: String, z: Any) /* primary */ { + super/*Any*/() + /* () */ + + } + + val x: Int + field = x + get + + val y: String + field = y + get + + val z: Any + field = z + get + + fun component1(): Int { + return .#x + } + + fun component2(): String { + return .#y + } + + fun component3(): Any { + return .#z + } + + fun copy(x: Int = .#x, y: String = .#y, z: Any = .#z): Test1 { + return Test1(x = x, y = y, z = z) + } + + override fun equals(other: Any?): Boolean { + when { + EQEQEQ(arg0 = , arg1 = other) -> return true + } + when { + other !is Test1 -> return false + } + val tmp0_other_with_cast: Test1 = other as Test1 + when { + EQEQ(arg0 = .#x, arg1 = tmp0_other_with_cast.#x).not() -> return false + } + when { + EQEQ(arg0 = .#y, arg1 = tmp0_other_with_cast.#y).not() -> return false + } + when { + EQEQ(arg0 = .#z, arg1 = tmp0_other_with_cast.#z).not() -> return false + } + return true + } + + override fun hashCode(): Int { + var result: Int = .#x.hashCode() + result = result.times(other = 31).plus(other = .#y.hashCode()) + result = result.times(other = 31).plus(other = .#z.hashCode()) + return result + } + + override fun toString(): String { + return "Test1(" + "x=" + .#x + ", " + "y=" + .#y + ", " + "z=" + .#z + ")" + } + +} + +data class Test2 { + constructor(x: Any?) /* primary */ { + super/*Any*/() + /* () */ + + } + + val x: Any? + field = x + get + + fun component1(): Any? { + return .#x + } + + fun copy(x: Any? = .#x): Test2 { + return Test2(x = x) + } + + override fun equals(other: Any?): Boolean { + when { + EQEQEQ(arg0 = , arg1 = other) -> return true + } + when { + other !is Test2 -> return false + } + val tmp0_other_with_cast: Test2 = other as Test2 + when { + EQEQ(arg0 = .#x, arg1 = tmp0_other_with_cast.#x).not() -> return false + } + return true + } + + override fun hashCode(): Int { + return when { + EQEQ(arg0 = .#x, arg1 = null) -> 0 + else -> .#x.hashCode() + } + } + + override fun toString(): String { + return "Test2(" + "x=" + .#x + ")" + } + +} + +data class Test3 { + constructor(d: Double, dn: Double?, f: Float, df: Float?) /* primary */ { + super/*Any*/() + /* () */ + + } + + val d: Double + field = d + get + + val dn: Double? + field = dn + get + + val f: Float + field = f + get + + val df: Float? + field = df + get + + fun component1(): Double { + return .#d + } + + fun component2(): Double? { + return .#dn + } + + fun component3(): Float { + return .#f + } + + fun component4(): Float? { + return .#df + } + + fun copy(d: Double = .#d, dn: Double? = .#dn, f: Float = .#f, df: Float? = .#df): Test3 { + return Test3(d = d, dn = dn, f = f, df = df) + } + + override fun equals(other: Any?): Boolean { + when { + EQEQEQ(arg0 = , arg1 = other) -> return true + } + when { + other !is Test3 -> return false + } + val tmp0_other_with_cast: Test3 = other as Test3 + when { + EQEQ(arg0 = .#d, arg1 = tmp0_other_with_cast.#d).not() -> return false + } + when { + EQEQ(arg0 = .#dn, arg1 = tmp0_other_with_cast.#dn).not() -> return false + } + when { + EQEQ(arg0 = .#f, arg1 = tmp0_other_with_cast.#f).not() -> return false + } + when { + EQEQ(arg0 = .#df, arg1 = tmp0_other_with_cast.#df).not() -> return false + } + return true + } + + override fun hashCode(): Int { + var result: Int = .#d.hashCode() + result = result.times(other = 31).plus(other = when { + EQEQ(arg0 = .#dn, arg1 = null) -> 0 + else -> .#dn.hashCode() + }) + result = result.times(other = 31).plus(other = .#f.hashCode()) + result = result.times(other = 31).plus(other = when { + EQEQ(arg0 = .#df, arg1 = null) -> 0 + else -> .#df.hashCode() + }) + return result + } + + override fun toString(): String { + return "Test3(" + "d=" + .#d + ", " + "dn=" + .#dn + ", " + "f=" + .#f + ", " + "df=" + .#df + ")" + } + +} diff --git a/compiler/testData/ir/irText/classes/dataClassesGeneric.fir.kt.txt b/compiler/testData/ir/irText/classes/dataClassesGeneric.fir.kt.txt new file mode 100644 index 00000000000..d932e4fc785 --- /dev/null +++ b/compiler/testData/ir/irText/classes/dataClassesGeneric.fir.kt.txt @@ -0,0 +1,174 @@ +data class Test1 { + constructor(x: T) /* primary */ { + super/*Any*/() + /* () */ + + } + + val x: T + field = x + get + + fun component1(): T { + return .#x + } + + fun copy(x: T = .#x): Test1 { + return Test1(x = x) + } + + override fun equals(other: Any?): Boolean { + when { + EQEQEQ(arg0 = , arg1 = other) -> return true + } + when { + other !is Test1 -> return false + } + val tmp0_other_with_cast: Test1 = other as Test1 + when { + EQEQ(arg0 = .#x, arg1 = tmp0_other_with_cast.#x).not() -> return false + } + return true + } + + override fun hashCode(): Int { + return when { + EQEQ(arg0 = .#x, arg1 = null) -> 0 + else -> .#x.hashCode() + } + } + + override fun toString(): String { + return "Test1(" + "x=" + .#x + ")" + } + +} + +data class Test2 { + constructor(x: T) /* primary */ { + super/*Any*/() + /* () */ + + } + + val x: T + field = x + get + + fun component1(): T { + return .#x + } + + fun copy(x: T = .#x): Test2 { + return Test2(x = x) + } + + override fun equals(other: Any?): Boolean { + when { + EQEQEQ(arg0 = , arg1 = other) -> return true + } + when { + other !is Test2 -> return false + } + val tmp0_other_with_cast: Test2 = other as Test2 + when { + EQEQ(arg0 = .#x, arg1 = tmp0_other_with_cast.#x).not() -> return false + } + return true + } + + override fun hashCode(): Int { + return .#x.hashCode() + } + + override fun toString(): String { + return "Test2(" + "x=" + .#x + ")" + } + +} + +data class Test3 { + constructor(x: List) /* primary */ { + super/*Any*/() + /* () */ + + } + + val x: List + field = x + get + + fun component1(): List { + return .#x + } + + fun copy(x: List = .#x): Test3 { + return Test3(x = x) + } + + override fun equals(other: Any?): Boolean { + when { + EQEQEQ(arg0 = , arg1 = other) -> return true + } + when { + other !is Test3 -> return false + } + val tmp0_other_with_cast: Test3 = other as Test3 + when { + EQEQ(arg0 = .#x, arg1 = tmp0_other_with_cast.#x).not() -> return false + } + return true + } + + override fun hashCode(): Int { + return .#x.hashCode() + } + + override fun toString(): String { + return "Test3(" + "x=" + .#x + ")" + } + +} + +data class Test4 { + constructor(x: List) /* primary */ { + super/*Any*/() + /* () */ + + } + + val x: List + field = x + get + + fun component1(): List { + return .#x + } + + fun copy(x: List = .#x): Test4 { + return Test4(x = x) + } + + override fun equals(other: Any?): Boolean { + when { + EQEQEQ(arg0 = , arg1 = other) -> return true + } + when { + other !is Test4 -> return false + } + val tmp0_other_with_cast: Test4 = other as Test4 + when { + EQEQ(arg0 = .#x, arg1 = tmp0_other_with_cast.#x).not() -> return false + } + return true + } + + override fun hashCode(): Int { + return .#x.hashCode() + } + + override fun toString(): String { + return "Test4(" + "x=" + .#x + ")" + } + +} diff --git a/compiler/testData/ir/irText/classes/delegatedGenericImplementation.fir.kt.txt b/compiler/testData/ir/irText/classes/delegatedGenericImplementation.fir.kt.txt new file mode 100644 index 00000000000..12ed623bf64 --- /dev/null +++ b/compiler/testData/ir/irText/classes/delegatedGenericImplementation.fir.kt.txt @@ -0,0 +1,73 @@ +interface IBase { + abstract fun foo(a: A, b: B) + abstract val C.id: Map? + abstract get + + abstract var List.x: D? + abstract get + abstract set + +} + +class Test1 : IBase { + constructor(i: IBase) /* primary */ { + super/*Any*/() + /* () */ + + .#<$$delegate_0> = i + } + + override fun foo(a: E, b: B) { + .#<$$delegate_0>.foo(a = a, b = b) + } + + override val C.id: Map? + override get(): Map? { + return (.#<$$delegate_0>, ).() + } + + override var List.x: D? + override get(): D? { + return (.#<$$delegate_0>, ).() + } + override set(: D?) { + (.#<$$delegate_0>, ).( = ) + } + + local /*final field*/ val <$$delegate_0>: IBase + +} + +class Test2 : IBase { + constructor(j: IBase) /* primary */ { + super/*Any*/() + /* () */ + + .#<$$delegate_0> = j + } + + var j: IBase + field = j + get + set + + override fun foo(a: String, b: B) { + .#<$$delegate_0>.foo(a = a, b = b) + } + + override val C.id: Map? + override get(): Map? { + return (.#<$$delegate_0>, ).() + } + + override var List.x: D? + override get(): D? { + return (.#<$$delegate_0>, ).() + } + override set(: D?) { + (.#<$$delegate_0>, ).( = ) + } + + local /*final field*/ val <$$delegate_0>: IBase + +} diff --git a/compiler/testData/ir/irText/classes/delegatedImplementation.fir.kt.txt b/compiler/testData/ir/irText/classes/delegatedImplementation.fir.kt.txt new file mode 100644 index 00000000000..ef0e829ad86 --- /dev/null +++ b/compiler/testData/ir/irText/classes/delegatedImplementation.fir.kt.txt @@ -0,0 +1,154 @@ +interface IBase { + abstract fun foo(x: Int, s: String) + abstract fun bar(): Int + abstract fun String.qux() + +} + +object BaseImpl : IBase { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + override fun foo(x: Int, s: String) { + } + + override fun bar(): Int { + return 42 + } + + override fun String.qux() { + } + +} + +interface IOther { + abstract val x: String + abstract get + + abstract var y: Int + abstract get + abstract set + + abstract val Byte.z1: Int + abstract get + + abstract var Byte.z2: Int + abstract get + abstract set + +} + +fun otherImpl(x0: String, y0: Int): IOther { + return { // BLOCK + local class : IOther { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + override val x: String + field = x0 + override get + + override var y: Int + field = y0 + override get + override set + + override val Byte.z1: Int + override get(): Int { + return 1 + } + + override var Byte.z2: Int + override get(): Int { + return 2 + } + override set(value: Int) { + } + + } + + () + } +} + +class Test1 : IBase { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + .#<$$delegate_0> = BaseImpl + } + + override fun foo(x: Int, s: String) { + .#<$$delegate_0>.foo(x = x, s = s) + } + + override fun bar(): Int { + return .#<$$delegate_0>.bar() + } + + override fun String.qux() { + (.#<$$delegate_0>, ).qux() + } + + local /*final field*/ val <$$delegate_0>: IBase + +} + +class Test2 : IBase, IOther { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + .#<$$delegate_0> = BaseImpl + .#<$$delegate_1> = otherImpl(x0 = "", y0 = 42) + } + + override fun foo(x: Int, s: String) { + .#<$$delegate_0>.foo(x = x, s = s) + } + + override fun bar(): Int { + return .#<$$delegate_0>.bar() + } + + override fun String.qux() { + (.#<$$delegate_0>, ).qux() + } + + local /*final field*/ val <$$delegate_0>: IBase + override val x: String + override get(): String { + return .#<$$delegate_1>.() + } + + override var y: Int + override get(): Int { + return .#<$$delegate_1>.() + } + override set(: Int) { + .#<$$delegate_1>.( = ) + } + + override val Byte.z1: Int + override get(): Int { + return (.#<$$delegate_1>, ).() + } + + override var Byte.z2: Int + override get(): Int { + return (.#<$$delegate_1>, ).() + } + override set(: Int) { + (.#<$$delegate_1>, ).( = ) + } + + local /*final field*/ val <$$delegate_1>: IOther + +} diff --git a/compiler/testData/ir/irText/classes/delegatedImplementationOfJavaInterface.fir.kt.txt b/compiler/testData/ir/irText/classes/delegatedImplementationOfJavaInterface.fir.kt.txt new file mode 100644 index 00000000000..8bf95831780 --- /dev/null +++ b/compiler/testData/ir/irText/classes/delegatedImplementationOfJavaInterface.fir.kt.txt @@ -0,0 +1,39 @@ +class Test : J { + constructor(j: J) /* primary */ { + super/*Any*/() + /* () */ + + .#<$$delegate_0> = j + } + + private val j: J + field = j + private get + + override fun takeNotNull(x: @EnhancedNullability String) { + .#<$$delegate_0>.takeNotNull(x = x) + } + + override fun takeNullable(x: @FlexibleNullability String?) { + .#<$$delegate_0>.takeNullable(x = x) + } + + override fun takeFlexible(x: String?) { + .#<$$delegate_0>.takeFlexible(x = x) + } + + override fun returnNotNull(): @EnhancedNullability String { + return .#<$$delegate_0>.returnNotNull() + } + + override fun returnNullable(): @FlexibleNullability String? { + return .#<$$delegate_0>.returnNullable() + } + + override fun returnsFlexible(): String? { + return .#<$$delegate_0>.returnsFlexible() + } + + local /*final field*/ val <$$delegate_0>: J + +} diff --git a/compiler/testData/ir/irText/classes/delegatedImplementationWithExplicitOverride.fir.kt.txt b/compiler/testData/ir/irText/classes/delegatedImplementationWithExplicitOverride.fir.kt.txt new file mode 100644 index 00000000000..fba073af5c8 --- /dev/null +++ b/compiler/testData/ir/irText/classes/delegatedImplementationWithExplicitOverride.fir.kt.txt @@ -0,0 +1,39 @@ +interface IFooBar { + abstract fun foo() + abstract fun bar() + +} + +object FooBarImpl : IFooBar { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + override fun foo() { + } + + override fun bar() { + } + +} + +class C : IFooBar { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + .#<$$delegate_0> = FooBarImpl + } + + override fun bar() { + } + + override fun foo() { + .#<$$delegate_0>.foo() + } + + local /*final field*/ val <$$delegate_0>: IFooBar + +} diff --git a/compiler/testData/ir/irText/classes/delegatingConstructorCallToTypeAliasConstructor.fir.kt.txt b/compiler/testData/ir/irText/classes/delegatingConstructorCallToTypeAliasConstructor.fir.kt.txt new file mode 100644 index 00000000000..3fce7ec5c13 --- /dev/null +++ b/compiler/testData/ir/irText/classes/delegatingConstructorCallToTypeAliasConstructor.fir.kt.txt @@ -0,0 +1,32 @@ +typealias CT = Cell +typealias CStr = Cell +open class Cell { + constructor(value: T) /* primary */ { + super/*Any*/() + /* () */ + + } + + val value: T + field = value + get + +} + +class C1 : Cell { + constructor() /* primary */ { + super/*Cell*/(value = "O") + /* () */ + + } + +} + +class C2 : Cell { + constructor() /* primary */ { + super/*Cell*/(value = "K") + /* () */ + + } + +} diff --git a/compiler/testData/ir/irText/classes/delegatingConstructorCallsInSecondaryConstructors.fir.kt.txt b/compiler/testData/ir/irText/classes/delegatingConstructorCallsInSecondaryConstructors.fir.kt.txt new file mode 100644 index 00000000000..4aa34fe4a53 --- /dev/null +++ b/compiler/testData/ir/irText/classes/delegatingConstructorCallsInSecondaryConstructors.fir.kt.txt @@ -0,0 +1,27 @@ +open class Base { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +class Test : Base { + constructor() { + super/*Base*/() + /* () */ + + } + + constructor(xx: Int) { + super/*Base*/() + /* () */ + + } + + constructor(xx: Short) { + this/*Test*/() + } + +} diff --git a/compiler/testData/ir/irText/classes/enum.fir.kt.txt b/compiler/testData/ir/irText/classes/enum.fir.kt.txt new file mode 100644 index 00000000000..f162b559184 --- /dev/null +++ b/compiler/testData/ir/irText/classes/enum.fir.kt.txt @@ -0,0 +1,174 @@ +enum class TestEnum1 : Enum { + private constructor() /* primary */ { + super/*Enum*/() + /* () */ + + } + + TEST1 = TestEnum1() + + TEST2 = TestEnum1() + + fun values(): Array /* Synthetic body for ENUM_VALUES */ + + fun valueOf(value: String): TestEnum1 /* Synthetic body for ENUM_VALUEOF */ + +} + +open enum class TestEnum2 : Enum { + private constructor(x: Int) /* primary */ { + super/*Enum*/() + /* () */ + + } + + val x: Int + field = x + get + + TEST1 = TestEnum2(x = 1) + + TEST2 = TestEnum2(x = 2) + + TEST3 = TestEnum2(x = 3) + + fun values(): Array /* Synthetic body for ENUM_VALUES */ + + fun valueOf(value: String): TestEnum2 /* Synthetic body for ENUM_VALUEOF */ + +} + +abstract enum class TestEnum3 : Enum { + private constructor() /* primary */ { + super/*Enum*/() + /* () */ + + } + + TEST = TEST() + private enum entry class TEST : TestEnum3 { + private constructor() /* primary */ { + super/*TestEnum3*/() + /* () */ + + } + + override fun foo() { + println(message = "Hello, world!") + } + + } + + abstract fun foo() + fun values(): Array /* Synthetic body for ENUM_VALUES */ + + fun valueOf(value: String): TestEnum3 /* Synthetic body for ENUM_VALUEOF */ + +} + +abstract enum class TestEnum4 : Enum { + private constructor(x: Int) /* primary */ { + super/*Enum*/() + /* () */ + + } + + val x: Int + field = x + get + + TEST1 = TEST1() + private enum entry class TEST1 : TestEnum4 { + private constructor() /* primary */ { + super/*TestEnum4*/(x = 1) + /* () */ + + } + + override fun foo() { + println(message = TestEnum4.TEST1) + } + + } + + TEST2 = TEST2() + private enum entry class TEST2 : TestEnum4 { + private constructor() /* primary */ { + super/*TestEnum4*/(x = 2) + /* () */ + + } + + val z: Int + get + + init { + .#z = .() + } + + override fun foo() { + println(message = TestEnum4.TEST2) + } + + } + + abstract fun foo() + fun values(): Array /* Synthetic body for ENUM_VALUES */ + + fun valueOf(value: String): TestEnum4 /* Synthetic body for ENUM_VALUEOF */ + +} + +open enum class TestEnum5 : Enum { + private constructor(x: Int = 0) /* primary */ { + super/*Enum*/() + /* () */ + + } + + val x: Int + field = x + get + + TEST1 = TestEnum5() + + TEST2 = TestEnum5() + + TEST3 = TestEnum5(x = 0) + + fun values(): Array /* Synthetic body for ENUM_VALUES */ + + fun valueOf(value: String): TestEnum5 /* Synthetic body for ENUM_VALUEOF */ + +} + +fun f(): Int { + return 1 +} + +open enum class TestEnum6 : Enum { + private constructor(x: Int, y: Int) /* primary */ { + super/*Enum*/() + /* () */ + + } + + val x: Int + field = x + get + + val y: Int + field = y + get + + TEST = { // BLOCK + val tmp0_y: Int = f() + val tmp1_x: Int = f() + TestEnum6(x = tmp1_x, y = tmp0_y) + } + + fun values(): Array /* Synthetic body for ENUM_VALUES */ + + fun valueOf(value: String): TestEnum6 /* Synthetic body for ENUM_VALUEOF */ + +} diff --git a/compiler/testData/ir/irText/classes/enumClassModality.fir.kt.txt b/compiler/testData/ir/irText/classes/enumClassModality.fir.kt.txt new file mode 100644 index 00000000000..d8342c49ad4 --- /dev/null +++ b/compiler/testData/ir/irText/classes/enumClassModality.fir.kt.txt @@ -0,0 +1,165 @@ +enum class TestFinalEnum1 : Enum { + private constructor() /* primary */ { + super/*Enum*/() + /* () */ + + } + + X1 = TestFinalEnum1() + + fun values(): Array /* Synthetic body for ENUM_VALUES */ + + fun valueOf(value: String): TestFinalEnum1 /* Synthetic body for ENUM_VALUEOF */ + +} + +open enum class TestFinalEnum2 : Enum { + private constructor(x: Int) /* primary */ { + super/*Enum*/() + /* () */ + + } + + val x: Int + field = x + get + + X1 = TestFinalEnum2(x = 1) + + fun values(): Array /* Synthetic body for ENUM_VALUES */ + + fun valueOf(value: String): TestFinalEnum2 /* Synthetic body for ENUM_VALUEOF */ + +} + +enum class TestFinalEnum3 : Enum { + private constructor() /* primary */ { + super/*Enum*/() + /* () */ + + } + + X1 = TestFinalEnum3() + + fun doStuff() { + } + + fun values(): Array /* Synthetic body for ENUM_VALUES */ + + fun valueOf(value: String): TestFinalEnum3 /* Synthetic body for ENUM_VALUEOF */ + +} + +open enum class TestOpenEnum1 : Enum { + private constructor() /* primary */ { + super/*Enum*/() + /* () */ + + } + + X1 = X1() + private enum entry class X1 : TestOpenEnum1 { + private constructor() /* primary */ { + super/*TestOpenEnum1*/() + /* () */ + + } + + override fun toString(): String { + return "X1" + } + + } + + fun values(): Array /* Synthetic body for ENUM_VALUES */ + + fun valueOf(value: String): TestOpenEnum1 /* Synthetic body for ENUM_VALUEOF */ + +} + +open enum class TestOpenEnum2 : Enum { + private constructor() /* primary */ { + super/*Enum*/() + /* () */ + + } + + X1 = X1() + private enum entry class X1 : TestOpenEnum2 { + private constructor() /* primary */ { + super/*TestOpenEnum2*/() + /* () */ + + } + + override fun foo() { + } + + } + + open fun foo() { + } + + fun values(): Array /* Synthetic body for ENUM_VALUES */ + + fun valueOf(value: String): TestOpenEnum2 /* Synthetic body for ENUM_VALUEOF */ + +} + +abstract enum class TestAbstractEnum1 : Enum { + private constructor() /* primary */ { + super/*Enum*/() + /* () */ + + } + + X1 = X1() + private enum entry class X1 : TestAbstractEnum1 { + private constructor() /* primary */ { + super/*TestAbstractEnum1*/() + /* () */ + + } + + override fun foo() { + } + + } + + abstract fun foo() + fun values(): Array /* Synthetic body for ENUM_VALUES */ + + fun valueOf(value: String): TestAbstractEnum1 /* Synthetic body for ENUM_VALUEOF */ + +} + +interface IFoo { + abstract fun foo() + +} + +open enum class TestAbstractEnum2 : IFoo, Enum { + private constructor() /* primary */ { + super/*Enum*/() + /* () */ + + } + + X1 = X1() + private enum entry class X1 : TestAbstractEnum2 { + private constructor() /* primary */ { + super/*TestAbstractEnum2*/() + /* () */ + + } + + override fun foo() { + } + + } + + fun values(): Array /* Synthetic body for ENUM_VALUES */ + + fun valueOf(value: String): TestAbstractEnum2 /* Synthetic body for ENUM_VALUEOF */ + +} diff --git a/compiler/testData/ir/irText/classes/enumWithMultipleCtors.fir.kt.txt b/compiler/testData/ir/irText/classes/enumWithMultipleCtors.fir.kt.txt new file mode 100644 index 00000000000..461e99bf1b0 --- /dev/null +++ b/compiler/testData/ir/irText/classes/enumWithMultipleCtors.fir.kt.txt @@ -0,0 +1,60 @@ +open enum class A : Enum { + X = A(arg = "asd") + + Y = Y() + private enum entry class Y : A { + private constructor() /* primary */ { + super/*A*/() + /* () */ + + } + + override fun f(): String { + return super.f().plus(other = "#Y") + } + + } + + Z = A(x = 5) + + val prop1: String + get + + val prop2: String + field = "const2" + get + + var prop3: String + field = "" + get + set + + private constructor(arg: String) { + super/*Enum*/() + /* () */ + + .#prop1 = arg + } + + private constructor() { + super/*Enum*/() + /* () */ + + .#prop1 = "default" + .( = "empty") + } + + private constructor(x: Int) { + this/*A*/(arg = x.toString()) + .( = "int") + } + + open fun f(): String { + return .().toString() + "#" + .().toString() + "#" + .().toString() + } + + fun values(): Array /* Synthetic body for ENUM_VALUES */ + + fun valueOf(value: String): A /* Synthetic body for ENUM_VALUEOF */ + +} diff --git a/compiler/testData/ir/irText/classes/enumWithSecondaryCtor.fir.kt.txt b/compiler/testData/ir/irText/classes/enumWithSecondaryCtor.fir.kt.txt new file mode 100644 index 00000000000..e9f1098f803 --- /dev/null +++ b/compiler/testData/ir/irText/classes/enumWithSecondaryCtor.fir.kt.txt @@ -0,0 +1,97 @@ +open enum class Test0 : Enum { + private constructor(x: Int) /* primary */ { + super/*Enum*/() + /* () */ + + } + + val x: Int + field = x + get + + ZERO = Test0() + + private constructor() { + this/*Test0*/(x = 0) + } + + fun values(): Array /* Synthetic body for ENUM_VALUES */ + + fun valueOf(value: String): Test0 /* Synthetic body for ENUM_VALUEOF */ + +} + +open enum class Test1 : Enum { + private constructor(x: Int) /* primary */ { + super/*Enum*/() + /* () */ + + } + + val x: Int + field = x + get + + ZERO = Test1() + + ONE = Test1(x = 1) + + private constructor() { + this/*Test1*/(x = 0) + } + + fun values(): Array /* Synthetic body for ENUM_VALUES */ + + fun valueOf(value: String): Test1 /* Synthetic body for ENUM_VALUEOF */ + +} + +abstract enum class Test2 : Enum { + private constructor(x: Int) /* primary */ { + super/*Enum*/() + /* () */ + + } + + val x: Int + field = x + get + + ZERO = ZERO() + private enum entry class ZERO : Test2 { + private constructor() /* primary */ { + super/*Test2*/() + /* () */ + + } + + override fun foo() { + println(message = "ZERO") + } + + } + + ONE = ONE() + private enum entry class ONE : Test2 { + private constructor() /* primary */ { + super/*Test2*/(x = 1) + /* () */ + + } + + override fun foo() { + println(message = "ONE") + } + + } + + private constructor() { + this/*Test2*/(x = 0) + } + + abstract fun foo() + fun values(): Array /* Synthetic body for ENUM_VALUES */ + + fun valueOf(value: String): Test2 /* Synthetic body for ENUM_VALUEOF */ + +} diff --git a/compiler/testData/ir/irText/classes/fakeOverridesForJavaStaticMembers.fir.kt.txt b/compiler/testData/ir/irText/classes/fakeOverridesForJavaStaticMembers.fir.kt.txt new file mode 100644 index 00000000000..f4f44ae84e1 --- /dev/null +++ b/compiler/testData/ir/irText/classes/fakeOverridesForJavaStaticMembers.fir.kt.txt @@ -0,0 +1,8 @@ +class Test : Base { + constructor() /* primary */ { + super/*Base*/() + /* () */ + + } + +} diff --git a/compiler/testData/ir/irText/classes/implicitNotNullOnDelegatedImplementation.fir.kt.txt b/compiler/testData/ir/irText/classes/implicitNotNullOnDelegatedImplementation.fir.kt.txt new file mode 100644 index 00000000000..8ae6aea8d38 --- /dev/null +++ b/compiler/testData/ir/irText/classes/implicitNotNullOnDelegatedImplementation.fir.kt.txt @@ -0,0 +1,128 @@ +interface IFoo { + abstract fun foo(): String + +} + +class K1 : JFoo { + constructor() /* primary */ { + super/*JFoo*/() + /* () */ + + } + +} + +class K2 : JFoo { + constructor() /* primary */ { + super/*JFoo*/() + /* () */ + + } + + override fun foo(): @FlexibleNullability String { + return super.foo() + } + +} + +class K3 : JUnrelatedFoo, IFoo { + constructor() /* primary */ { + super/*JUnrelatedFoo*/() + /* () */ + + } + +} + +class K4 : JUnrelatedFoo, IFoo { + constructor() /* primary */ { + super/*JUnrelatedFoo*/() + /* () */ + + } + + override fun foo(): String? { + return super.foo() + } + +} + +class TestJFoo : IFoo { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + .#<$$delegate_0> = JFoo() + } + + override fun foo(): String { + return .#<$$delegate_0>.foo() + } + + local /*final field*/ val <$$delegate_0>: IFoo + +} + +class TestK1 : IFoo { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + .#<$$delegate_0> = K1() + } + + override fun foo(): String { + return .#<$$delegate_0>.foo() + } + + local /*final field*/ val <$$delegate_0>: IFoo + +} + +class TestK2 : IFoo { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + .#<$$delegate_0> = K2() + } + + override fun foo(): String { + return .#<$$delegate_0>.foo() + } + + local /*final field*/ val <$$delegate_0>: IFoo + +} + +class TestK3 : IFoo { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + .#<$$delegate_0> = K3() + } + + override fun foo(): String { + return .#<$$delegate_0>.foo() + } + + local /*final field*/ val <$$delegate_0>: IFoo + +} + +class TestK4 : IFoo { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + .#<$$delegate_0> = K4() + } + + override fun foo(): String { + return .#<$$delegate_0>.foo() + } + + local /*final field*/ val <$$delegate_0>: IFoo + +} diff --git a/compiler/testData/ir/irText/classes/initValInLambda.fir.kt.txt b/compiler/testData/ir/irText/classes/initValInLambda.fir.kt.txt new file mode 100644 index 00000000000..727822427ed --- /dev/null +++ b/compiler/testData/ir/irText/classes/initValInLambda.fir.kt.txt @@ -0,0 +1,18 @@ +class TestInitValInLambdaCalledOnce { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + val x: Int + get + + init { + 1.run(block = local fun Int.() { + .#x = 0 + } +) + } + +} diff --git a/compiler/testData/ir/irText/classes/inlineClass.fir.kt.txt b/compiler/testData/ir/irText/classes/inlineClass.fir.kt.txt new file mode 100644 index 00000000000..f606fd6ab9f --- /dev/null +++ b/compiler/testData/ir/irText/classes/inlineClass.fir.kt.txt @@ -0,0 +1,31 @@ +inline class Test { + constructor(x: Int) /* primary */ { + super/*Any*/() + /* () */ + + } + + val x: Int + field = x + get + + override fun equals(other: Any?): Boolean { + when { + other !is Test -> return false + } + val tmp0_other_with_cast: Test = other as Test + when { + EQEQ(arg0 = .#x, arg1 = tmp0_other_with_cast.#x).not() -> return false + } + return true + } + + override fun hashCode(): Int { + return .#x.hashCode() + } + + override fun toString(): String { + return "Test(" + "x=" + .#x + ")" + } + +} diff --git a/compiler/testData/ir/irText/classes/inlineClassSyntheticMethods.fir.kt.txt b/compiler/testData/ir/irText/classes/inlineClassSyntheticMethods.fir.kt.txt new file mode 100644 index 00000000000..9e57b45e94a --- /dev/null +++ b/compiler/testData/ir/irText/classes/inlineClassSyntheticMethods.fir.kt.txt @@ -0,0 +1,60 @@ +class C { + constructor(t: T) /* primary */ { + super/*Any*/() + /* () */ + + } + + val t: T + field = t + get + + override fun hashCode(): Int { + return .() as Int + } + +} + +inline class IC { + constructor(c: C) /* primary */ { + super/*Any*/() + /* () */ + + } + + val c: C + field = c + get + + fun foo(): Int { + return .().hashCode() + } + + override fun equals(other: Any?): Boolean { + when { + other !is IC -> return false + } + val tmp0_other_with_cast: IC = other as IC + when { + EQEQ(arg0 = .#c, arg1 = tmp0_other_with_cast.#c).not() -> return false + } + return true + } + + override fun hashCode(): Int { + return .#c.hashCode() + } + + override fun toString(): String { + return "IC(" + "c=" + .#c + ")" + } + +} + +fun box(): String { + val ic: IC = IC(c = C(t = 42)) + when { + EQEQ(arg0 = ic.foo(), arg1 = 42).not() -> return "FAIL" + } + return "OK" +} diff --git a/compiler/testData/ir/irText/classes/innerClass.fir.kt.txt b/compiler/testData/ir/irText/classes/innerClass.fir.kt.txt new file mode 100644 index 00000000000..70489fb8082 --- /dev/null +++ b/compiler/testData/ir/irText/classes/innerClass.fir.kt.txt @@ -0,0 +1,26 @@ +class Outer { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + open inner class TestInnerClass { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + } + + inner class DerivedInnerClass : TestInnerClass { + constructor() /* primary */ { + .super/*TestInnerClass*/() + /* () */ + + } + + } + +} diff --git a/compiler/testData/ir/irText/classes/innerClassWithDelegatingConstructor.fir.kt.txt b/compiler/testData/ir/irText/classes/innerClassWithDelegatingConstructor.fir.kt.txt new file mode 100644 index 00000000000..67d9bb6242f --- /dev/null +++ b/compiler/testData/ir/irText/classes/innerClassWithDelegatingConstructor.fir.kt.txt @@ -0,0 +1,25 @@ +class Outer { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + inner class Inner { + constructor(x: Int) /* primary */ { + super/*Any*/() + /* () */ + + } + + val x: Int + field = x + get + + constructor() { + .this/*Inner*/(x = 0) + } + + } + +} diff --git a/compiler/testData/ir/irText/classes/kt31649.fir.kt.txt b/compiler/testData/ir/irText/classes/kt31649.fir.kt.txt new file mode 100644 index 00000000000..0947f7f3e7e --- /dev/null +++ b/compiler/testData/ir/irText/classes/kt31649.fir.kt.txt @@ -0,0 +1,80 @@ +data class TestData { + constructor(nn: Nothing?) /* primary */ { + super/*Any*/() + /* () */ + + } + + val nn: Nothing? + field = nn + get + + fun component1(): Nothing? { + return .#nn + } + + fun copy(nn: Nothing? = .#nn): TestData { + return TestData(nn = nn) + } + + override fun equals(other: Any?): Boolean { + when { + EQEQEQ(arg0 = , arg1 = other) -> return true + } + when { + other !is TestData -> return false + } + val tmp0_other_with_cast: TestData = other as TestData + when { + EQEQ(arg0 = .#nn, arg1 = tmp0_other_with_cast.#nn).not() -> return false + } + return true + } + + override fun hashCode(): Int { + return when { + EQEQ(arg0 = .#nn, arg1 = null) -> 0 + else -> .#nn.hashCode() + } + } + + override fun toString(): String { + return "TestData(" + "nn=" + .#nn + ")" + } + +} + +inline class TestInline { + constructor(nn: Nothing?) /* primary */ { + super/*Any*/() + /* () */ + + } + + val nn: Nothing? + field = nn + get + + override fun equals(other: Any?): Boolean { + when { + other !is TestInline -> return false + } + val tmp0_other_with_cast: TestInline = other as TestInline + when { + EQEQ(arg0 = .#nn, arg1 = tmp0_other_with_cast.#nn).not() -> return false + } + return true + } + + override fun hashCode(): Int { + return when { + EQEQ(arg0 = .#nn, arg1 = null) -> 0 + else -> .#nn.hashCode() + } + } + + override fun toString(): String { + return "TestInline(" + "nn=" + .#nn + ")" + } + +} diff --git a/compiler/testData/ir/irText/classes/kt43217.fir.kt.txt b/compiler/testData/ir/irText/classes/kt43217.fir.kt.txt new file mode 100644 index 00000000000..bd07aa4c60f --- /dev/null +++ b/compiler/testData/ir/irText/classes/kt43217.fir.kt.txt @@ -0,0 +1,40 @@ +class A { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + private val b: + field = { // BLOCK + local class : DoubleExpression { + private constructor() /* primary */ { + super/*DoubleExpression*/() + /* () */ + + } + + override operator fun get(): Double { + return 0.0D + } + + } + + () + } + private get + +} + +class C : DoubleExpression { + constructor() /* primary */ { + super/*DoubleExpression*/() + /* () */ + + } + + override operator fun get(): Double { + return 0.0D + } + +} diff --git a/compiler/testData/ir/irText/classes/lambdaInDataClassDefaultParameter.fir.kt.txt b/compiler/testData/ir/irText/classes/lambdaInDataClassDefaultParameter.fir.kt.txt new file mode 100644 index 00000000000..726406607bb --- /dev/null +++ b/compiler/testData/ir/irText/classes/lambdaInDataClassDefaultParameter.fir.kt.txt @@ -0,0 +1,99 @@ +data class A { + constructor(runA: @ExtensionFunctionType @ExtensionFunctionType Function2 = local fun A.(it: String) { + return Unit + } +) /* primary */ { + super/*Any*/() + /* () */ + + } + + val runA: @ExtensionFunctionType @ExtensionFunctionType Function2 + field = runA + get + + fun component1(): @ExtensionFunctionType @ExtensionFunctionType Function2 { + return .#runA + } + + fun copy(runA: @ExtensionFunctionType @ExtensionFunctionType Function2 = .#runA): A { + return A(runA = runA) + } + + override fun equals(other: Any?): Boolean { + when { + EQEQEQ(arg0 = , arg1 = other) -> return true + } + when { + other !is A -> return false + } + val tmp0_other_with_cast: A = other as A + when { + EQEQ(arg0 = .#runA, arg1 = tmp0_other_with_cast.#runA).not() -> return false + } + return true + } + + override fun hashCode(): Int { + return .#runA.hashCode() + } + + override fun toString(): String { + return "A(" + "runA=" + .#runA + ")" + } + +} + +data class B { + constructor(x: Any = { // BLOCK + local class { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + } + + () + }) /* primary */ { + super/*Any*/() + /* () */ + + } + + val x: Any + field = x + get + + fun component1(): Any { + return .#x + } + + fun copy(x: Any = .#x): B { + return B(x = x) + } + + override fun equals(other: Any?): Boolean { + when { + EQEQEQ(arg0 = , arg1 = other) -> return true + } + when { + other !is B -> return false + } + val tmp0_other_with_cast: B = other as B + when { + EQEQ(arg0 = .#x, arg1 = tmp0_other_with_cast.#x).not() -> return false + } + return true + } + + override fun hashCode(): Int { + return .#x.hashCode() + } + + override fun toString(): String { + return "B(" + "x=" + .#x + ")" + } + +} diff --git a/compiler/testData/ir/irText/classes/objectLiteralExpressions.fir.kt.txt b/compiler/testData/ir/irText/classes/objectLiteralExpressions.fir.kt.txt new file mode 100644 index 00000000000..b9886d37fce --- /dev/null +++ b/compiler/testData/ir/irText/classes/objectLiteralExpressions.fir.kt.txt @@ -0,0 +1,94 @@ +interface IFoo { + abstract fun foo() + +} + +val test1: + field = { // BLOCK + local class { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + } + + () + } + get + +val test2: IFoo + field = { // BLOCK + local class : IFoo { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + override fun foo() { + println(message = "foo") + } + + } + + () + } + get + +class Outer { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + abstract inner class Inner : IFoo { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + } + + fun test3(): Inner { + return { // BLOCK + local class : Inner { + private constructor() /* primary */ { + .super/*Inner*/() + /* () */ + + } + + override fun foo() { + println(message = "foo") + } + + } + + () + } + } + +} + +fun Outer.test4(): Inner { + return { // BLOCK + local class : Inner { + private constructor() /* primary */ { + .super/*Inner*/() + /* () */ + + } + + override fun foo() { + println(message = "foo") + } + + } + + () + } +} diff --git a/compiler/testData/ir/irText/classes/objectWithInitializers.fir.kt.txt b/compiler/testData/ir/irText/classes/objectWithInitializers.fir.kt.txt new file mode 100644 index 00000000000..2ea6b369681 --- /dev/null +++ b/compiler/testData/ir/irText/classes/objectWithInitializers.fir.kt.txt @@ -0,0 +1,28 @@ +abstract class Base { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +object Test : Base { + private constructor() /* primary */ { + super/*Base*/() + /* () */ + + } + + val x: Int + field = 1 + get + + val y: Int + get + + init { + .#y = .() + } + +} diff --git a/compiler/testData/ir/irText/classes/primaryConstructorWithSuperConstructorCall.fir.kt.txt b/compiler/testData/ir/irText/classes/primaryConstructorWithSuperConstructorCall.fir.kt.txt new file mode 100644 index 00000000000..ad72db20377 --- /dev/null +++ b/compiler/testData/ir/irText/classes/primaryConstructorWithSuperConstructorCall.fir.kt.txt @@ -0,0 +1,47 @@ +open class Base { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +class TestImplicitPrimaryConstructor : Base { + constructor() /* primary */ { + super/*Base*/() + /* () */ + + } + +} + +class TestExplicitPrimaryConstructor : Base { + constructor() /* primary */ { + super/*Base*/() + /* () */ + + } + +} + +class TestWithDelegatingConstructor : Base { + constructor(x: Int, y: Int) /* primary */ { + super/*Base*/() + /* () */ + + } + + val x: Int + field = x + get + + val y: Int + field = y + get + + constructor(x: Int) { + this/*TestWithDelegatingConstructor*/(x = x, y = 0) + } + +} diff --git a/compiler/testData/ir/irText/classes/qualifiedSuperCalls.fir.kt.txt b/compiler/testData/ir/irText/classes/qualifiedSuperCalls.fir.kt.txt new file mode 100644 index 00000000000..b6675975ff3 --- /dev/null +++ b/compiler/testData/ir/irText/classes/qualifiedSuperCalls.fir.kt.txt @@ -0,0 +1,40 @@ +interface ILeft { + fun foo() { + } + + val bar: Int + get(): Int { + return 1 + } + +} + +interface IRight { + fun foo() { + } + + val bar: Int + get(): Int { + return 2 + } + +} + +class CBoth : ILeft, IRight { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + override fun foo() { + super.foo() + super.foo() + } + + override val bar: Int + override get(): Int { + return super.().plus(other = super.()) + } + +} diff --git a/compiler/testData/ir/irText/classes/sealedClasses.fir.kt.txt b/compiler/testData/ir/irText/classes/sealedClasses.fir.kt.txt new file mode 100644 index 00000000000..2c148f51ccb --- /dev/null +++ b/compiler/testData/ir/irText/classes/sealedClasses.fir.kt.txt @@ -0,0 +1,47 @@ +sealed class Expr { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + class Const : Expr { + constructor(number: Double) /* primary */ { + super/*Expr*/() + /* () */ + + } + + val number: Double + field = number + get + + } + + class Sum : Expr { + constructor(e1: Expr, e2: Expr) /* primary */ { + super/*Expr*/() + /* () */ + + } + + val e1: Expr + field = e1 + get + + val e2: Expr + field = e2 + get + + } + + object NotANumber : Expr { + private constructor() /* primary */ { + super/*Expr*/() + /* () */ + + } + + } + +} diff --git a/compiler/testData/ir/irText/classes/secondaryConstructorWithInitializersFromClassBody.fir.kt.txt b/compiler/testData/ir/irText/classes/secondaryConstructorWithInitializersFromClassBody.fir.kt.txt new file mode 100644 index 00000000000..997168e114f --- /dev/null +++ b/compiler/testData/ir/irText/classes/secondaryConstructorWithInitializersFromClassBody.fir.kt.txt @@ -0,0 +1,47 @@ +open class Base { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +class TestProperty : Base { + val x: Int + field = 0 + get + + constructor() { + super/*Base*/() + /* () */ + + } + +} + +class TestInitBlock : Base { + val x: Int + get + + init { + .#x = 0 + } + + constructor() { + super/*Base*/() + /* () */ + + } + + constructor(z: Any) { + super/*Base*/() + /* () */ + + } + + constructor(y: Int) { + this/*TestInitBlock*/() + } + +} diff --git a/compiler/testData/ir/irText/classes/superCalls.fir.kt.txt b/compiler/testData/ir/irText/classes/superCalls.fir.kt.txt new file mode 100644 index 00000000000..abea417af69 --- /dev/null +++ b/compiler/testData/ir/irText/classes/superCalls.fir.kt.txt @@ -0,0 +1,37 @@ +open class Base { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + open fun foo() { + } + + open val bar: String + field = "" + open get + + override fun hashCode(): Int { + return super.hashCode() + } + +} + +class Derived : Base { + constructor() /* primary */ { + super/*Base*/() + /* () */ + + } + + override fun foo() { + super.foo() + } + + override val bar: String + override get(): String { + return super.() + } + +} diff --git a/compiler/testData/ir/irText/classes/superCallsComposed.fir.kt.txt b/compiler/testData/ir/irText/classes/superCallsComposed.fir.kt.txt new file mode 100644 index 00000000000..6eb02e0dfe5 --- /dev/null +++ b/compiler/testData/ir/irText/classes/superCallsComposed.fir.kt.txt @@ -0,0 +1,40 @@ +open class Base { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + open fun foo() { + } + + open val bar: String + field = "" + open get + +} + +interface BaseI { + abstract fun foo() + abstract val bar: String + abstract get + +} + +class Derived : Base, BaseI { + constructor() /* primary */ { + super/*Base*/() + /* () */ + + } + + override fun foo() { + super.foo() + } + + override val bar: String + override get(): String { + return super.() + } + +} diff --git a/compiler/testData/ir/irText/declarations/annotations/annotationsInAnnotationArguments.fir.kt.txt b/compiler/testData/ir/irText/declarations/annotations/annotationsInAnnotationArguments.fir.kt.txt new file mode 100644 index 00000000000..ac5cb764f23 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/annotations/annotationsInAnnotationArguments.fir.kt.txt @@ -0,0 +1,28 @@ +annotation class A1 : Annotation { + constructor(x: Int) /* primary */ + val x: Int + field = x + get + +} + +annotation class A2 : Annotation { + constructor(a: A1) /* primary */ + val a: A1 + field = a + get + +} + +annotation class AA : Annotation { + constructor(xs: Array) /* primary */ + val xs: Array + field = xs + get + +} + +@A2(a = A1(x = 42)) +@AA(xs = [A1(x = 1), A1(x = 2)]) +fun test() { +} diff --git a/compiler/testData/ir/irText/declarations/annotations/annotationsOnDelegatedMembers.fir.kt.txt b/compiler/testData/ir/irText/declarations/annotations/annotationsOnDelegatedMembers.fir.kt.txt new file mode 100644 index 00000000000..5d627c4940a --- /dev/null +++ b/compiler/testData/ir/irText/declarations/annotations/annotationsOnDelegatedMembers.fir.kt.txt @@ -0,0 +1,50 @@ +annotation class Ann : Annotation { + constructor() /* primary */ + +} + +interface IFoo { + @Ann + abstract val testVal: String + abstract get + + @Ann + abstract fun testFun() + @Ann + abstract val String.testExtVal: String + abstract get + + @Ann + abstract fun String.testExtFun() + +} + +class DFoo : IFoo { + constructor(d: IFoo) /* primary */ { + super/*Any*/() + /* () */ + + .#<$$delegate_0> = d + } + + override fun testFun() { + .#<$$delegate_0>.testFun() + } + + override fun String.testExtFun() { + (.#<$$delegate_0>, ).testExtFun() + } + + override val testVal: String + override get(): String { + return .#<$$delegate_0>.() + } + + override val String.testExtVal: String + override get(): String { + return (.#<$$delegate_0>, ).() + } + + local /*final field*/ val <$$delegate_0>: IFoo + +} diff --git a/compiler/testData/ir/irText/declarations/annotations/annotationsWithDefaultParameterValues.fir.kt.txt b/compiler/testData/ir/irText/declarations/annotations/annotationsWithDefaultParameterValues.fir.kt.txt new file mode 100644 index 00000000000..3e2c5ad151c --- /dev/null +++ b/compiler/testData/ir/irText/declarations/annotations/annotationsWithDefaultParameterValues.fir.kt.txt @@ -0,0 +1,31 @@ +annotation class A : Annotation { + constructor(x: String = "", y: Int = 42) /* primary */ + val x: String + field = x + get + + val y: Int + field = y + get + +} + +@A(x = "abc", y = 123) +fun test1() { +} + +@A(x = "def") +fun test2() { +} + +@A(x = "ghi") +fun test3() { +} + +@A(, y = 456) +fun test4() { +} + +@A +fun test5() { +} diff --git a/compiler/testData/ir/irText/declarations/annotations/annotationsWithVarargParameters.fir.kt.txt b/compiler/testData/ir/irText/declarations/annotations/annotationsWithVarargParameters.fir.kt.txt new file mode 100644 index 00000000000..0d5ed9fb16e --- /dev/null +++ b/compiler/testData/ir/irText/declarations/annotations/annotationsWithVarargParameters.fir.kt.txt @@ -0,0 +1,19 @@ +annotation class A : Annotation { + constructor(vararg xs: String) /* primary */ + val xs: Array + field = xs + get + +} + +@A(xs = ["abc", "def"]) +fun test1() { +} + +@A(xs = ["abc"]) +fun test2() { +} + +@A(xs = []) +fun test3() { +} diff --git a/compiler/testData/ir/irText/declarations/annotations/arrayInAnnotationArguments.fir.kt.txt b/compiler/testData/ir/irText/declarations/annotations/arrayInAnnotationArguments.fir.kt.txt new file mode 100644 index 00000000000..d03a05dbf1f --- /dev/null +++ b/compiler/testData/ir/irText/declarations/annotations/arrayInAnnotationArguments.fir.kt.txt @@ -0,0 +1,25 @@ +annotation class TestAnnWithIntArray : Annotation { + constructor(x: IntArray) /* primary */ + val x: IntArray + field = x + get + +} + +annotation class TestAnnWithStringArray : Annotation { + constructor(x: Array) /* primary */ + val x: Array + field = x + get + +} + +@TestAnnWithIntArray(x = [1, 2, 3]) +@TestAnnWithStringArray(x = ["a", "b", "c"]) +fun test1() { +} + +@TestAnnWithIntArray(x = [4, 5, 6]) +@TestAnnWithStringArray(x = ["d", "e", "f"]) +fun test2() { +} diff --git a/compiler/testData/ir/irText/declarations/annotations/classLiteralInAnnotation.fir.kt.txt b/compiler/testData/ir/irText/declarations/annotations/classLiteralInAnnotation.fir.kt.txt new file mode 100644 index 00000000000..5244da04b7a --- /dev/null +++ b/compiler/testData/ir/irText/declarations/annotations/classLiteralInAnnotation.fir.kt.txt @@ -0,0 +1,20 @@ +annotation class A : Annotation { + constructor(klass: KClass<*>) /* primary */ + val klass: KClass<*> + field = klass + get + +} + +class C { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +@A(klass = C::class) +fun test1() { +} diff --git a/compiler/testData/ir/irText/declarations/annotations/classesWithAnnotations.fir.kt.txt b/compiler/testData/ir/irText/declarations/annotations/classesWithAnnotations.fir.kt.txt new file mode 100644 index 00000000000..4bdfa727a8f --- /dev/null +++ b/compiler/testData/ir/irText/declarations/annotations/classesWithAnnotations.fir.kt.txt @@ -0,0 +1,71 @@ +annotation class TestAnn : Annotation { + constructor(x: String) /* primary */ + val x: String + field = x + get + +} + +@TestAnn(x = "class") +class TestClass { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +@TestAnn(x = "interface") +interface TestInterface { + +} + +@TestAnn(x = "object") +object TestObject { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +class Host { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + @TestAnn(x = "companion") + companion object TestCompanion { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + } + +} + +@TestAnn(x = "enum") +enum class TestEnum : Enum { + private constructor() /* primary */ { + super/*Enum*/() + /* () */ + + } + + fun values(): Array /* Synthetic body for ENUM_VALUES */ + + fun valueOf(value: String): TestEnum /* Synthetic body for ENUM_VALUEOF */ + +} + +@TestAnn(x = "annotation") +annotation class TestAnnotation : Annotation { + constructor() /* primary */ + +} diff --git a/compiler/testData/ir/irText/declarations/annotations/constExpressionsInAnnotationArguments.fir.kt.txt b/compiler/testData/ir/irText/declarations/annotations/constExpressionsInAnnotationArguments.fir.kt.txt new file mode 100644 index 00000000000..d1e9b133d95 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/annotations/constExpressionsInAnnotationArguments.fir.kt.txt @@ -0,0 +1,19 @@ +const val ONE: Int + field = 1 + get + +annotation class A : Annotation { + constructor(x: Int) /* primary */ + val x: Int + field = x + get + +} + +@A(x = 1) +fun test1() { +} + +@A(x = 2) +fun test2() { +} diff --git a/compiler/testData/ir/irText/declarations/annotations/constructorsWithAnnotations.fir.kt.txt b/compiler/testData/ir/irText/declarations/annotations/constructorsWithAnnotations.fir.kt.txt new file mode 100644 index 00000000000..d73410ec5ad --- /dev/null +++ b/compiler/testData/ir/irText/declarations/annotations/constructorsWithAnnotations.fir.kt.txt @@ -0,0 +1,22 @@ +annotation class TestAnn : Annotation { + constructor(x: Int) /* primary */ + val x: Int + field = x + get + +} + +class TestClass { + @TestAnn(x = 1) + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + @TestAnn(x = 2) + constructor(x: Int) { + this/*TestClass*/() + } + +} diff --git a/compiler/testData/ir/irText/declarations/annotations/delegateFieldWithAnnotations.fir.kt.txt b/compiler/testData/ir/irText/declarations/annotations/delegateFieldWithAnnotations.fir.kt.txt new file mode 100644 index 00000000000..50f94ade6b1 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/annotations/delegateFieldWithAnnotations.fir.kt.txt @@ -0,0 +1,13 @@ +annotation class Ann : Annotation { + constructor() /* primary */ + +} + +val test1: Int /* by */ + field = lazy(initializer = local fun (): Int { + return 42 + } +) + get(): Int { + return #test1$delegate.getValue(thisRef = null, property = ::test1) + } diff --git a/compiler/testData/ir/irText/declarations/annotations/delegatedPropertyAccessorsWithAnnotations.fir.kt.txt b/compiler/testData/ir/irText/declarations/annotations/delegatedPropertyAccessorsWithAnnotations.fir.kt.txt new file mode 100644 index 00000000000..88ae26ae9aa --- /dev/null +++ b/compiler/testData/ir/irText/declarations/annotations/delegatedPropertyAccessorsWithAnnotations.fir.kt.txt @@ -0,0 +1,47 @@ +annotation class A : Annotation { + constructor(x: String) /* primary */ + val x: String + field = x + get + +} + +class Cell { + constructor(value: Int) /* primary */ { + super/*Any*/() + /* () */ + + } + + var value: Int + field = value + get + set + + operator fun getValue(thisRef: Any?, kProp: Any?): Int { + return .() + } + + operator fun setValue(thisRef: Any?, kProp: Any?, newValue: Int) { + .( = newValue) + } + +} + +val test1: Int /* by */ + field = Cell(value = 1) + @A(x = "test1.get") + get(): Int { + return #test1$delegate.getValue(thisRef = null, kProp = ::test1) + } + +var test2: Int /* by */ + field = Cell(value = 2) + @A(x = "test2.get") + get(): Int { + return #test2$delegate.getValue(thisRef = null, kProp = ::test2) + } + @A(x = "test2.set") + set(@A(x = "test2.set.param") : Int) { + #test2$delegate.setValue(thisRef = null, kProp = ::test2, newValue = ) + } diff --git a/compiler/testData/ir/irText/declarations/annotations/enumEntriesWithAnnotations.fir.kt.txt b/compiler/testData/ir/irText/declarations/annotations/enumEntriesWithAnnotations.fir.kt.txt new file mode 100644 index 00000000000..cc33301670a --- /dev/null +++ b/compiler/testData/ir/irText/declarations/annotations/enumEntriesWithAnnotations.fir.kt.txt @@ -0,0 +1,39 @@ +annotation class TestAnn : Annotation { + constructor(x: String) /* primary */ + val x: String + field = x + get + +} + +open enum class TestEnum : Enum { + private constructor() /* primary */ { + super/*Enum*/() + /* () */ + + } + + @TestAnn(x = "ENTRY1") + ENTRY1 = TestEnum() + + @TestAnn(x = "ENTRY2") + ENTRY2 = ENTRY2() + @TestAnn(x = "ENTRY2") + private enum entry class ENTRY2 : TestEnum { + private constructor() /* primary */ { + super/*TestEnum*/() + /* () */ + + } + + val x: Int + field = 42 + get + + } + + fun values(): Array /* Synthetic body for ENUM_VALUES */ + + fun valueOf(value: String): TestEnum /* Synthetic body for ENUM_VALUEOF */ + +} diff --git a/compiler/testData/ir/irText/declarations/annotations/enumsInAnnotationArguments.fir.kt.txt b/compiler/testData/ir/irText/declarations/annotations/enumsInAnnotationArguments.fir.kt.txt new file mode 100644 index 00000000000..8b8fb80eb7d --- /dev/null +++ b/compiler/testData/ir/irText/declarations/annotations/enumsInAnnotationArguments.fir.kt.txt @@ -0,0 +1,32 @@ +enum class En : Enum { + private constructor() /* primary */ { + super/*Enum*/() + /* () */ + + } + + A = En() + + B = En() + + C = En() + + D = En() + + fun values(): Array /* Synthetic body for ENUM_VALUES */ + + fun valueOf(value: String): En /* Synthetic body for ENUM_VALUEOF */ + +} + +annotation class TestAnn : Annotation { + constructor(x: En) /* primary */ + val x: En + field = x + get + +} + +@TestAnn(x = En.A) +fun test1() { +} diff --git a/compiler/testData/ir/irText/declarations/annotations/fieldsWithAnnotations.fir.kt.txt b/compiler/testData/ir/irText/declarations/annotations/fieldsWithAnnotations.fir.kt.txt new file mode 100644 index 00000000000..65cf9cc5679 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/annotations/fieldsWithAnnotations.fir.kt.txt @@ -0,0 +1,16 @@ +annotation class TestAnn : Annotation { + constructor(x: String) /* primary */ + val x: String + field = x + get + +} + +val testVal: String + field = "a val" + get + +var testVar: String + field = "a var" + get + set diff --git a/compiler/testData/ir/irText/declarations/annotations/fileAnnotations.fir.kt.txt b/compiler/testData/ir/irText/declarations/annotations/fileAnnotations.fir.kt.txt new file mode 100644 index 00000000000..2c6453f4a48 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/annotations/fileAnnotations.fir.kt.txt @@ -0,0 +1,11 @@ +@file:A(x = "File annotation") +package test + +@Target(allowedTargets = [AnnotationTarget.FILE]) +annotation class A : Annotation { + constructor(x: String) /* primary */ + val x: String + field = x + get + +} diff --git a/compiler/testData/ir/irText/declarations/annotations/functionsWithAnnotations.fir.kt.txt b/compiler/testData/ir/irText/declarations/annotations/functionsWithAnnotations.fir.kt.txt new file mode 100644 index 00000000000..fb9f4d773c6 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/annotations/functionsWithAnnotations.fir.kt.txt @@ -0,0 +1,11 @@ +annotation class TestAnn : Annotation { + constructor(x: Int) /* primary */ + val x: Int + field = x + get + +} + +@TestAnn(x = 42) +fun testSimpleFunction() { +} diff --git a/compiler/testData/ir/irText/declarations/annotations/inheritingDeprecation.fir.kt.txt b/compiler/testData/ir/irText/declarations/annotations/inheritingDeprecation.fir.kt.txt new file mode 100644 index 00000000000..f2c20e552fc --- /dev/null +++ b/compiler/testData/ir/irText/declarations/annotations/inheritingDeprecation.fir.kt.txt @@ -0,0 +1,64 @@ +interface IFoo { + @Deprecated(message = "") + val prop: String + get(): String { + return "" + } + + @Deprecated(message = "") + val String.extProp: String + get(): String { + return "" + } + +} + +class Delegated : IFoo { + constructor(foo: IFoo) /* primary */ { + super/*Any*/() + /* () */ + + .#<$$delegate_0> = foo + } + + override val prop: String + override get(): String { + return .#<$$delegate_0>.() + } + + override val String.extProp: String + override get(): String { + return (.#<$$delegate_0>, ).() + } + + local /*final field*/ val <$$delegate_0>: IFoo + +} + +class DefaultImpl : IFoo { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +class ExplicitOverride : IFoo { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + override val prop: String + override get(): String { + return "" + } + + override val String.extProp: String + override get(): String { + return "" + } + +} diff --git a/compiler/testData/ir/irText/declarations/annotations/localDelegatedPropertiesWithAnnotations.fir.kt.txt b/compiler/testData/ir/irText/declarations/annotations/localDelegatedPropertiesWithAnnotations.fir.kt.txt new file mode 100644 index 00000000000..996e6c558a6 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/annotations/localDelegatedPropertiesWithAnnotations.fir.kt.txt @@ -0,0 +1,19 @@ +annotation class A : Annotation { + constructor(x: String) /* primary */ + val x: String + field = x + get + +} + +fun foo(m: Map) { + val test: Int + val test$delegate: Lazy = lazy(initializer = local fun (): Int { + return 42 + } +) + local get(): Int { + return test$delegate.getValue(thisRef = null, property = ::test) + } + +} diff --git a/compiler/testData/ir/irText/declarations/annotations/multipleAnnotationsInSquareBrackets.fir.kt.txt b/compiler/testData/ir/irText/declarations/annotations/multipleAnnotationsInSquareBrackets.fir.kt.txt new file mode 100644 index 00000000000..583d890bf3e --- /dev/null +++ b/compiler/testData/ir/irText/declarations/annotations/multipleAnnotationsInSquareBrackets.fir.kt.txt @@ -0,0 +1,20 @@ +annotation class A1 : Annotation { + constructor() /* primary */ + +} + +annotation class A2 : Annotation { + constructor() /* primary */ + +} + +annotation class A3 : Annotation { + constructor() /* primary */ + +} + +@A1 +@A2 +@A3 +fun test() { +} diff --git a/compiler/testData/ir/irText/declarations/annotations/primaryConstructorParameterWithAnnotations.fir.kt.txt b/compiler/testData/ir/irText/declarations/annotations/primaryConstructorParameterWithAnnotations.fir.kt.txt new file mode 100644 index 00000000000..d5cc5c32c3a --- /dev/null +++ b/compiler/testData/ir/irText/declarations/annotations/primaryConstructorParameterWithAnnotations.fir.kt.txt @@ -0,0 +1,17 @@ +annotation class Ann : Annotation { + constructor() /* primary */ + +} + +class Test { + constructor(@Ann x: Int) /* primary */ { + super/*Any*/() + /* () */ + + } + + val x: Int + field = x + get + +} diff --git a/compiler/testData/ir/irText/declarations/annotations/propertiesWithAnnotations.fir.kt.txt b/compiler/testData/ir/irText/declarations/annotations/propertiesWithAnnotations.fir.kt.txt new file mode 100644 index 00000000000..3006aada3f3 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/annotations/propertiesWithAnnotations.fir.kt.txt @@ -0,0 +1,12 @@ +annotation class TestAnn : Annotation { + constructor(x: String) /* primary */ + val x: String + field = x + get + +} + +@TestAnn(x = "testVal.property") +val testVal: String + field = "" + get diff --git a/compiler/testData/ir/irText/declarations/annotations/propertyAccessorsFromClassHeaderWithAnnotations.fir.kt.txt b/compiler/testData/ir/irText/declarations/annotations/propertyAccessorsFromClassHeaderWithAnnotations.fir.kt.txt new file mode 100644 index 00000000000..3340c0f3884 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/annotations/propertyAccessorsFromClassHeaderWithAnnotations.fir.kt.txt @@ -0,0 +1,28 @@ +annotation class A : Annotation { + constructor(x: String) /* primary */ + val x: String + field = x + get + +} + +class C { + constructor(x: Int, y: Int) /* primary */ { + super/*Any*/() + /* () */ + + } + + val x: Int + field = x + @A(x = "C.x.get") + get + + var y: Int + field = y + @A(x = "C.y.get") + get + @A(x = "C.y.set") + set + +} diff --git a/compiler/testData/ir/irText/declarations/annotations/propertyAccessorsWithAnnotations.fir.kt.txt b/compiler/testData/ir/irText/declarations/annotations/propertyAccessorsWithAnnotations.fir.kt.txt new file mode 100644 index 00000000000..441a53b5564 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/annotations/propertyAccessorsWithAnnotations.fir.kt.txt @@ -0,0 +1,34 @@ +annotation class TestAnn : Annotation { + constructor(x: String) /* primary */ + val x: String + field = x + get + +} + +val test1: String + @TestAnn(x = "test1.get") + get(): String { + return "" + } + +var test2: String + @TestAnn(x = "test2.get") + get(): String { + return "" + } + @TestAnn(x = "test2.set") + set(value: String) { + } + +val test3: String + field = "" + @TestAnn(x = "test3.get") + get + +var test4: String + field = "" + @TestAnn(x = "test4.get") + get + @TestAnn(x = "test4.set") + set diff --git a/compiler/testData/ir/irText/declarations/annotations/propertySetterParameterWithAnnotations.fir.kt.txt b/compiler/testData/ir/irText/declarations/annotations/propertySetterParameterWithAnnotations.fir.kt.txt new file mode 100644 index 00000000000..e64e83fcde1 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/annotations/propertySetterParameterWithAnnotations.fir.kt.txt @@ -0,0 +1,23 @@ +annotation class AnnParam : Annotation { + constructor() /* primary */ + +} + +var p: Int + field = 0 + get + set + +class C { + constructor(p: Int) /* primary */ { + super/*Any*/() + /* () */ + + } + + var p: Int + field = p + get + set + +} diff --git a/compiler/testData/ir/irText/declarations/annotations/receiverParameterWithAnnotations.fir.kt.txt b/compiler/testData/ir/irText/declarations/annotations/receiverParameterWithAnnotations.fir.kt.txt new file mode 100644 index 00000000000..a3fb025d70e --- /dev/null +++ b/compiler/testData/ir/irText/declarations/annotations/receiverParameterWithAnnotations.fir.kt.txt @@ -0,0 +1,31 @@ +annotation class Ann : Annotation { + constructor() /* primary */ + +} + +class A { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + fun @Ann String.f(): String { + return "" + } + + val @Ann String?.p: String + get(): String { + return "" + } + +} + +fun @Ann String?.topLevelF(): String { + return "" +} + +val @Ann String.topLevelP: String + get(): String { + return "" + } diff --git a/compiler/testData/ir/irText/declarations/annotations/spreadOperatorInAnnotationArguments.fir.kt.txt b/compiler/testData/ir/irText/declarations/annotations/spreadOperatorInAnnotationArguments.fir.kt.txt new file mode 100644 index 00000000000..72a0ed3bd66 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/annotations/spreadOperatorInAnnotationArguments.fir.kt.txt @@ -0,0 +1,11 @@ +annotation class A : Annotation { + constructor(vararg xs: String) /* primary */ + val xs: Array + field = xs + get + +} + +@A(xs = ["a", "b"]) +fun test() { +} diff --git a/compiler/testData/ir/irText/declarations/annotations/typeAliasesWithAnnotations.fir.kt.txt b/compiler/testData/ir/irText/declarations/annotations/typeAliasesWithAnnotations.fir.kt.txt new file mode 100644 index 00000000000..fca88dbbc9c --- /dev/null +++ b/compiler/testData/ir/irText/declarations/annotations/typeAliasesWithAnnotations.fir.kt.txt @@ -0,0 +1,10 @@ +@TestAnn(x = "TestTypeAlias") +typealias TestTypeAlias = String +@Target(allowedTargets = [AnnotationTarget.TYPEALIAS]) +annotation class TestAnn : Annotation { + constructor(x: String) /* primary */ + val x: String + field = x + get + +} diff --git a/compiler/testData/ir/irText/declarations/annotations/typeParametersWithAnnotations.fir.kt.txt b/compiler/testData/ir/irText/declarations/annotations/typeParametersWithAnnotations.fir.kt.txt new file mode 100644 index 00000000000..a7f3c43c166 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/annotations/typeParametersWithAnnotations.fir.kt.txt @@ -0,0 +1,8 @@ +@Target(allowedTargets = [AnnotationTarget.TYPE_PARAMETER]) +annotation class Anno : Annotation { + constructor() /* primary */ + +} + +fun foo() { +} diff --git a/compiler/testData/ir/irText/declarations/annotations/valueParametersWithAnnotations.fir.kt.txt b/compiler/testData/ir/irText/declarations/annotations/valueParametersWithAnnotations.fir.kt.txt new file mode 100644 index 00000000000..15710f9363f --- /dev/null +++ b/compiler/testData/ir/irText/declarations/annotations/valueParametersWithAnnotations.fir.kt.txt @@ -0,0 +1,23 @@ +annotation class TestAnn : Annotation { + constructor(x: String) /* primary */ + val x: String + field = x + get + +} + +fun testFun(@TestAnn(x = "testFun.x") x: Int) { +} + +class TestClassConstructor1 { + constructor(@TestAnn(x = "TestClassConstructor1.x") x: Int) /* primary */ { + super/*Any*/() + /* () */ + + } + + val xx: Int + field = x + get + +} diff --git a/compiler/testData/ir/irText/declarations/annotations/varargsInAnnotationArguments.fir.kt.txt b/compiler/testData/ir/irText/declarations/annotations/varargsInAnnotationArguments.fir.kt.txt new file mode 100644 index 00000000000..42a3957deb9 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/annotations/varargsInAnnotationArguments.fir.kt.txt @@ -0,0 +1,35 @@ +annotation class A1 : Annotation { + constructor(vararg xs: Int) /* primary */ + val xs: IntArray + field = xs + get + +} + +annotation class A2 : Annotation { + constructor(vararg xs: String) /* primary */ + val xs: Array + field = xs + get + +} + +annotation class AA : Annotation { + constructor(vararg xs: A1) /* primary */ + val xs: Array + field = xs + get + +} + +@A1(xs = [1, 2, 3]) +@A2(xs = ["a", "b", "c"]) +@AA(xs = [A1(xs = [4]), A1(xs = [5]), A1(xs = [6])]) +fun test1() { +} + +@A1(xs = []) +@A2(xs = []) +@AA(xs = []) +fun test2() { +} diff --git a/compiler/testData/ir/irText/declarations/annotations/variablesWithAnnotations.fir.kt.txt b/compiler/testData/ir/irText/declarations/annotations/variablesWithAnnotations.fir.kt.txt new file mode 100644 index 00000000000..a9c7989fc4d --- /dev/null +++ b/compiler/testData/ir/irText/declarations/annotations/variablesWithAnnotations.fir.kt.txt @@ -0,0 +1,12 @@ +annotation class TestAnn : Annotation { + constructor(x: String) /* primary */ + val x: String + field = x + get + +} + +fun foo() { + val testVal: String = "testVal" + var testVar: String = "testVar" +} diff --git a/compiler/testData/ir/irText/declarations/catchParameterInTopLevelProperty.fir.kt.txt b/compiler/testData/ir/irText/declarations/catchParameterInTopLevelProperty.fir.kt.txt new file mode 100644 index 00000000000..1be53a5cc95 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/catchParameterInTopLevelProperty.fir.kt.txt @@ -0,0 +1,7 @@ +val test: Unit + field = try { // BLOCK + } + catch (e: Throwable){ // BLOCK + } + + get diff --git a/compiler/testData/ir/irText/declarations/classLevelProperties.fir.kt.txt b/compiler/testData/ir/irText/declarations/classLevelProperties.fir.kt.txt new file mode 100644 index 00000000000..acb53720654 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/classLevelProperties.fir.kt.txt @@ -0,0 +1,56 @@ +class C { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + val test1: Int + field = 0 + get + + val test2: Int + get(): Int { + return 0 + } + + var test3: Int + field = 0 + get + set + + var test4: Int + field = 1 + get + set(value: Int) { + .#test4 = value + } + + var test5: Int + field = 1 + get + private set + + val test6: Int + field = 1 + get + + val test7: Int /* by */ + field = lazy(initializer = local fun (): Int { + return 42 + } +) + get(): Int { + return .#test7$delegate.getValue(thisRef = , property = C::test7) + } + + var test8: Int? /* by */ + field = hashMapOf() + get(): Int? { + return .#test8$delegate.getValue(thisRef = , property = C::test8) + } + set(: Int?) { + .#test8$delegate.setValue(thisRef = , property = C::test8, value = ) + } + +} diff --git a/compiler/testData/ir/irText/declarations/delegatedProperties.fir.kt.txt b/compiler/testData/ir/irText/declarations/delegatedProperties.fir.kt.txt new file mode 100644 index 00000000000..67b7211da25 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/delegatedProperties.fir.kt.txt @@ -0,0 +1,48 @@ +val test1: Int /* by */ + field = lazy(initializer = local fun (): Int { + return 42 + } +) + get(): Int { + return #test1$delegate.getValue(thisRef = null, property = ::test1) + } + +class C { + constructor(map: MutableMap) /* primary */ { + super/*Any*/() + /* () */ + + } + + val map: MutableMap + field = map + get + + val test2: Int /* by */ + field = lazy(initializer = local fun (): Int { + return 42 + } +) + get(): Int { + return .#test2$delegate.getValue(thisRef = , property = C::test2) + } + + var test3: Any /* by */ + field = .() + get(): Any { + return .#test3$delegate.getValue(thisRef = , property = C::test3) + } + set(: Any) { + .#test3$delegate.setValue(thisRef = , property = C::test3, value = ) + } + +} + +var test4: Any? /* by */ + field = hashMapOf() + get(): Any? { + return #test4$delegate.getValue(thisRef = null, property = ::test4) + } + set(: Any?) { + #test4$delegate.setValue(thisRef = null, property = ::test4, value = ) + } diff --git a/compiler/testData/ir/irText/declarations/fakeOverrides.fir.kt.txt b/compiler/testData/ir/irText/declarations/fakeOverrides.fir.kt.txt new file mode 100644 index 00000000000..35a49aaa6e7 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/fakeOverrides.fir.kt.txt @@ -0,0 +1,35 @@ +interface IFooStr { + abstract fun foo(x: String) + +} + +interface IBar { + abstract val bar: Int + abstract get + +} + +abstract class CFoo { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + fun foo(x: T) { + } + +} + +class Test1 : CFoo, IFooStr, IBar { + constructor() /* primary */ { + super/*CFoo*/() + /* () */ + + } + + override val bar: Int + field = 42 + override get + +} diff --git a/compiler/testData/ir/irText/declarations/genericDelegatedProperty.fir.kt.txt b/compiler/testData/ir/irText/declarations/genericDelegatedProperty.fir.kt.txt new file mode 100644 index 00000000000..23037eff964 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/genericDelegatedProperty.fir.kt.txt @@ -0,0 +1,33 @@ +class C { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +object Delegate { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + operator fun getValue(thisRef: Any?, kProp: Any?): Int { + return 42 + } + + operator fun setValue(thisRef: Any?, kProp: Any?, newValue: Int) { + } + +} + +var C.genericDelegatedProperty: Int /* by */ + field = Delegate + get(): Int { + return #genericDelegatedProperty$delegate.getValue(thisRef = , kProp = ::genericDelegatedProperty/*()*/) + } + set(: Int) { + #genericDelegatedProperty$delegate.setValue(thisRef = , kProp = ::genericDelegatedProperty/*()*/, newValue = ) + } diff --git a/compiler/testData/ir/irText/declarations/inlineCollectionOfInlineClass.fir.kt.txt b/compiler/testData/ir/irText/declarations/inlineCollectionOfInlineClass.fir.kt.txt new file mode 100644 index 00000000000..b2da2bf4441 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/inlineCollectionOfInlineClass.fir.kt.txt @@ -0,0 +1,108 @@ +inline class IT { + constructor(x: Int) /* primary */ { + super/*Any*/() + /* () */ + + } + + val x: Int + field = x + get + + override fun equals(other: Any?): Boolean { + when { + other !is IT -> return false + } + val tmp0_other_with_cast: IT = other as IT + when { + EQEQ(arg0 = .#x, arg1 = tmp0_other_with_cast.#x).not() -> return false + } + return true + } + + override fun hashCode(): Int { + return .#x.hashCode() + } + + override fun toString(): String { + return "IT(" + "x=" + .#x + ")" + } + +} + +inline class InlineMutableSet : MutableSet { + constructor(ms: MutableSet) /* primary */ { + super/*Any*/() + /* () */ + + } + + private val ms: MutableSet + field = ms + private get + + override val size: Int + override get(): Int { + return .().() + } + + override operator fun contains(element: IT): Boolean { + return .().contains(element = element) + } + + override fun containsAll(elements: Collection): Boolean { + return .().containsAll(elements = elements) + } + + override fun isEmpty(): Boolean { + return .().isEmpty() + } + + override fun add(element: IT): Boolean { + return .().add(element = element) + } + + override fun addAll(elements: Collection): Boolean { + return .().addAll(elements = elements) + } + + override fun clear() { + .().clear() + } + + override operator fun iterator(): MutableIterator { + return .().iterator() + } + + override fun remove(element: IT): Boolean { + return .().remove(element = element) + } + + override fun removeAll(elements: Collection): Boolean { + return .().removeAll(elements = elements) + } + + override fun retainAll(elements: Collection): Boolean { + return .().retainAll(elements = elements) + } + + override fun equals(other: Any?): Boolean { + when { + other !is InlineMutableSet -> return false + } + val tmp0_other_with_cast: InlineMutableSet = other as InlineMutableSet + when { + EQEQ(arg0 = .#ms, arg1 = tmp0_other_with_cast.#ms).not() -> return false + } + return true + } + + override fun hashCode(): Int { + return .#ms.hashCode() + } + + override fun toString(): String { + return "InlineMutableSet(" + "ms=" + .#ms + ")" + } + +} diff --git a/compiler/testData/ir/irText/declarations/kt29833.fir.kt.txt b/compiler/testData/ir/irText/declarations/kt29833.fir.kt.txt new file mode 100644 index 00000000000..793d73e0144 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/kt29833.fir.kt.txt @@ -0,0 +1,18 @@ +package interop + +object Definitions { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + const val KT_CONSTANT: String? + field = "constant" + get + + val ktValue: String? + field = #CONSTANT + get + +} diff --git a/compiler/testData/ir/irText/declarations/kt35550.fir.kt.txt b/compiler/testData/ir/irText/declarations/kt35550.fir.kt.txt new file mode 100644 index 00000000000..7ed89add857 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/kt35550.fir.kt.txt @@ -0,0 +1,24 @@ +interface I { + val T.id: T + get(): T { + return + } + +} + +class A : I { + constructor(i: I) /* primary */ { + super/*Any*/() + /* () */ + + .#<$$delegate_0> = i + } + + override val T.id: T + override get(): T { + return (.#<$$delegate_0>, ).() + } + + local /*final field*/ val <$$delegate_0>: I + +} diff --git a/compiler/testData/ir/irText/declarations/localClassWithOverrides.fir.kt.txt b/compiler/testData/ir/irText/declarations/localClassWithOverrides.fir.kt.txt new file mode 100644 index 00000000000..c346b56d7d4 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/localClassWithOverrides.fir.kt.txt @@ -0,0 +1,40 @@ +fun outer() { + local abstract class ALocal { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + abstract fun afun() + abstract val aval: Int + abstract get + + abstract var avar: Int + abstract get + abstract set + + } + + local class Local : ALocal { + constructor() /* primary */ { + super/*ALocal*/() + /* () */ + + } + + override fun afun() { + } + + override val aval: Int + field = 1 + override get + + override var avar: Int + field = 2 + override get + override set + + } + +} diff --git a/compiler/testData/ir/irText/declarations/localDelegatedProperties.fir.kt.txt b/compiler/testData/ir/irText/declarations/localDelegatedProperties.fir.kt.txt new file mode 100644 index 00000000000..bb38bedafe8 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/localDelegatedProperties.fir.kt.txt @@ -0,0 +1,29 @@ +fun test1() { + val x: Int + val x$delegate: Lazy = lazy(initializer = local fun (): Int { + return 42 + } +) + local get(): Int { + return x$delegate.getValue(thisRef = null, property = ::x) + } + + println(message = ()) +} + +fun test2() { + var x: Int? + val x$delegate: HashMap = hashMapOf() + local get(): Int? { + return x$delegate.getValue(thisRef = null, property = ::x) + } + local set(: Int?) { + x$delegate.setValue(thisRef = null, property = ::x, value = ) + } + + ( = 0) + val : Int = () /*as Int */ + ( = .inc()) + /*~> Unit */ + ( = () /*as Int */.plus(other = 1)) +} diff --git a/compiler/testData/ir/irText/declarations/localVarInDoWhile.fir.kt.txt b/compiler/testData/ir/irText/declarations/localVarInDoWhile.fir.kt.txt new file mode 100644 index 00000000000..dec2c330262 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/localVarInDoWhile.fir.kt.txt @@ -0,0 +1,5 @@ +fun foo() { + do// COMPOSITE { + val x: Int = 42 + // } while (EQEQ(arg0 = x, arg1 = 42).not()) +} diff --git a/compiler/testData/ir/irText/declarations/multiplatform/expectClassInherited.fir.kt.txt b/compiler/testData/ir/irText/declarations/multiplatform/expectClassInherited.fir.kt.txt new file mode 100644 index 00000000000..c377c786972 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/multiplatform/expectClassInherited.fir.kt.txt @@ -0,0 +1,38 @@ +expect abstract class A { + protected expect constructor() /* primary */ + expect abstract fun foo() + +} + +expect open class B : A { + expect constructor(i: Int) /* primary */ + expect override fun foo() + expect open fun bar(s: String) + +} + +abstract class A { + protected constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + abstract fun foo() + +} + +open class B : A { + constructor(i: Int) /* primary */ { + super/*A*/() + /* () */ + + } + + override fun foo() { + } + + open fun bar(s: String) { + } + +} diff --git a/compiler/testData/ir/irText/declarations/multiplatform/expectedEnumClass.fir.kt.txt b/compiler/testData/ir/irText/declarations/multiplatform/expectedEnumClass.fir.kt.txt new file mode 100644 index 00000000000..28d099e85bd --- /dev/null +++ b/compiler/testData/ir/irText/declarations/multiplatform/expectedEnumClass.fir.kt.txt @@ -0,0 +1,29 @@ +expect enum class MyEnum : Enum { + private expect constructor() /* primary */ + FOO = MyEnum() + + BAR = MyEnum() + + expect fun values(): Array + expect fun valueOf(value: String): MyEnum + +} + +enum class MyEnum : Enum { + private constructor() /* primary */ { + super/*Enum*/() + /* () */ + + } + + FOO = MyEnum() + + BAR = MyEnum() + + BAZ = MyEnum() + + fun values(): Array /* Synthetic body for ENUM_VALUES */ + + fun valueOf(value: String): MyEnum /* Synthetic body for ENUM_VALUEOF */ + +} diff --git a/compiler/testData/ir/irText/declarations/multiplatform/expectedSealedClass.fir.kt.txt b/compiler/testData/ir/irText/declarations/multiplatform/expectedSealedClass.fir.kt.txt new file mode 100644 index 00000000000..c409b307440 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/multiplatform/expectedSealedClass.fir.kt.txt @@ -0,0 +1,27 @@ +expect sealed class Ops { + private expect constructor() /* primary */ + +} + +expect class Add : Ops { + expect constructor() /* primary */ + +} + +sealed class Ops { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +class Add : Ops { + constructor() /* primary */ { + super/*Ops*/() + /* () */ + + } + +} diff --git a/compiler/testData/ir/irText/declarations/packageLevelProperties.fir.kt.txt b/compiler/testData/ir/irText/declarations/packageLevelProperties.fir.kt.txt new file mode 100644 index 00000000000..da79cbe2ac8 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/packageLevelProperties.fir.kt.txt @@ -0,0 +1,47 @@ +val test1: Int + field = 0 + get + +val test2: Int + get(): Int { + return 0 + } + +var test3: Int + field = 0 + get + set + +var test4: Int + field = 1 + get + set(value: Int) { + #test4 = value + } + +var test5: Int + field = 1 + get + private set + +val test6: Int + field = 1 + get + +val test7: Int /* by */ + field = lazy(initializer = local fun (): Int { + return 42 + } +) + get(): Int { + return #test7$delegate.getValue(thisRef = null, property = ::test7) + } + +var test8: Int? /* by */ + field = hashMapOf() + get(): Int? { + return #test8$delegate.getValue(thisRef = null, property = ::test8) + } + set(: Int?) { + #test8$delegate.setValue(thisRef = null, property = ::test8, value = ) + } diff --git a/compiler/testData/ir/irText/declarations/parameters/constructor.fir.kt.txt b/compiler/testData/ir/irText/declarations/parameters/constructor.fir.kt.txt new file mode 100644 index 00000000000..31503aa07fc --- /dev/null +++ b/compiler/testData/ir/irText/declarations/parameters/constructor.fir.kt.txt @@ -0,0 +1,80 @@ +class Test1 { + constructor(x: T1, y: T2) /* primary */ { + super/*Any*/() + /* () */ + + } + + val x: T1 + field = x + get + + val y: T2 + field = y + get + +} + +class Test2 { + constructor(x: Int, y: String) /* primary */ { + super/*Any*/() + /* () */ + + } + + val y: String + field = y + get + + inner class TestInner { + constructor(z: Z) /* primary */ { + super/*Any*/() + /* () */ + + } + + val z: Z + field = z + get + + constructor(z: Z, i: Int) { + .this/*TestInner*/(z = z) + } + + } + +} + +class Test3 { + constructor(x: Int, y: String = "") /* primary */ { + super/*Any*/() + /* () */ + + } + + val x: Int + field = x + get + + val y: String + field = y + get + +} + +class Test4 { + constructor(x: Int) /* primary */ { + super/*Any*/() + /* () */ + + } + + val x: Int + field = x + get + + constructor(x: Int, y: Int = 42) { + this/*Test4*/(x = x.plus(other = y)) + } + +} diff --git a/compiler/testData/ir/irText/declarations/parameters/dataClassMembers.fir.kt.txt b/compiler/testData/ir/irText/declarations/parameters/dataClassMembers.fir.kt.txt new file mode 100644 index 00000000000..c60bd70017d --- /dev/null +++ b/compiler/testData/ir/irText/declarations/parameters/dataClassMembers.fir.kt.txt @@ -0,0 +1,58 @@ +data class Test { + constructor(x: T, y: String = "") /* primary */ { + super/*Any*/() + /* () */ + + } + + val x: T + field = x + get + + val y: String + field = y + get + + fun component1(): T { + return .#x + } + + fun component2(): String { + return .#y + } + + fun copy(x: T = .#x, y: String = .#y): Test { + return Test(x = x, y = y) + } + + override fun equals(other: Any?): Boolean { + when { + EQEQEQ(arg0 = , arg1 = other) -> return true + } + when { + other !is Test -> return false + } + val tmp0_other_with_cast: Test = other as Test + when { + EQEQ(arg0 = .#x, arg1 = tmp0_other_with_cast.#x).not() -> return false + } + when { + EQEQ(arg0 = .#y, arg1 = tmp0_other_with_cast.#y).not() -> return false + } + return true + } + + override fun hashCode(): Int { + var result: Int = when { + EQEQ(arg0 = .#x, arg1 = null) -> 0 + else -> .#x.hashCode() + } + result = result.times(other = 31).plus(other = .#y.hashCode()) + return result + } + + override fun toString(): String { + return "Test(" + "x=" + .#x + ", " + "y=" + .#y + ")" + } + +} diff --git a/compiler/testData/ir/irText/declarations/parameters/delegatedMembers.fir.kt.txt b/compiler/testData/ir/irText/declarations/parameters/delegatedMembers.fir.kt.txt new file mode 100644 index 00000000000..f8509a6c22c --- /dev/null +++ b/compiler/testData/ir/irText/declarations/parameters/delegatedMembers.fir.kt.txt @@ -0,0 +1,33 @@ +interface IBase { + abstract fun foo(x: Int) + abstract val bar: Int + abstract get + + abstract fun qux(t: T, x: X) + +} + +class Test : IBase { + constructor(impl: IBase) /* primary */ { + super/*Any*/() + /* () */ + + .#<$$delegate_0> = impl + } + + override fun foo(x: Int) { + .#<$$delegate_0>.foo(x = x) + } + + override fun qux(t: TT, x: X) { + .#<$$delegate_0>.qux(t = t, x = x) + } + + override val bar: Int + override get(): Int { + return .#<$$delegate_0>.() + } + + local /*final field*/ val <$$delegate_0>: IBase + +} diff --git a/compiler/testData/ir/irText/declarations/parameters/lambdas.fir.kt.txt b/compiler/testData/ir/irText/declarations/parameters/lambdas.fir.kt.txt new file mode 100644 index 00000000000..e097d10a472 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/parameters/lambdas.fir.kt.txt @@ -0,0 +1,26 @@ +val test1: Function1 + field = local fun (it: String): String { + return it + } + + get + +val test2: @ExtensionFunctionType @ExtensionFunctionType Function2 + field = local fun Any.(it: Any): Int { + return it.hashCode() + } + + get + +val test3: Function2 + field = local fun (i: Int, j: Int) { + return Unit + } + + get + +val test4: Function2 + field = local fun (i: Int, j: Int) { + } + + get diff --git a/compiler/testData/ir/irText/declarations/parameters/typeParameterBeforeBound.fir.kt.txt b/compiler/testData/ir/irText/declarations/parameters/typeParameterBeforeBound.fir.kt.txt new file mode 100644 index 00000000000..7fb49758dad --- /dev/null +++ b/compiler/testData/ir/irText/declarations/parameters/typeParameterBeforeBound.fir.kt.txt @@ -0,0 +1,17 @@ +class Test1 { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +fun test2() { +} + +var Test1.test3: Unit + get() { + } + set(value: Unit) { + } diff --git a/compiler/testData/ir/irText/declarations/parameters/typeParameterBoundedBySubclass.fir.kt.txt b/compiler/testData/ir/irText/declarations/parameters/typeParameterBoundedBySubclass.fir.kt.txt new file mode 100644 index 00000000000..b070d0dcb67 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/parameters/typeParameterBoundedBySubclass.fir.kt.txt @@ -0,0 +1,38 @@ +abstract class Base1 { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +class Derived1 : Base1 { + constructor() /* primary */ { + super/*Base1*/() + /* () */ + + } + +} + +abstract class Base2 { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + fun foo(x: T) { + } + +} + +class Derived2 : Base2 { + constructor() /* primary */ { + super/*Base2*/() + /* () */ + + } + +} diff --git a/compiler/testData/ir/irText/declarations/parameters/useNextParamInLambda.fir.kt.txt b/compiler/testData/ir/irText/declarations/parameters/useNextParamInLambda.fir.kt.txt new file mode 100644 index 00000000000..ff26f4f0234 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/parameters/useNextParamInLambda.fir.kt.txt @@ -0,0 +1,25 @@ +fun f(f1: Function0 = local fun (): ErrorType /* ERROR */ { + return error("") /* ERROR CALL */ +} +, f2: Function0 = local fun (): String { + return "FAIL" +} +): String { + return f1.invoke() +} + +fun box(): String { + var result: String = "fail" + try f() + catch (e: Exception){ // BLOCK + result = "OK" + } + /*~> Unit */ + return f(, f2 = local fun (): String { + return "O" + } +).plus(other = f(f1 = local fun (): String { + return "K" + } +)) +} diff --git a/compiler/testData/ir/irText/declarations/provideDelegate/memberExtension.fir.kt.txt b/compiler/testData/ir/irText/declarations/provideDelegate/memberExtension.fir.kt.txt new file mode 100644 index 00000000000..175e23fdae8 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/provideDelegate/memberExtension.fir.kt.txt @@ -0,0 +1,39 @@ +object Host { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + class StringDelegate { + constructor(s: String) /* primary */ { + super/*Any*/() + /* () */ + + } + + val s: String + field = s + get + + operator fun getValue(receiver: String, p: Any): String { + return receiver.plus(other = .()) + } + + } + + operator fun String.provideDelegate(host: Any?, p: Any): StringDelegate { + return StringDelegate(s = ) + } + + val String.plusK: String /* by */ + field = (, "K").provideDelegate(host = , p = Host::plusK) + get(): String { + return .#plusK$delegate.getValue(receiver = , p = Host::plusK) + } + + val ok: String + field = (, "O").() + get + +} diff --git a/compiler/testData/ir/irText/declarations/typeAlias.fir.kt.txt b/compiler/testData/ir/irText/declarations/typeAlias.fir.kt.txt new file mode 100644 index 00000000000..f10bbf8eb16 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/typeAlias.fir.kt.txt @@ -0,0 +1,14 @@ +typealias Test1 = String +fun foo() { + { // BLOCK + } +} + +class C { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} diff --git a/compiler/testData/ir/irText/errors/unresolvedReference.fir.kt.txt b/compiler/testData/ir/irText/errors/unresolvedReference.fir.kt.txt new file mode 100644 index 00000000000..6194e780b11 --- /dev/null +++ b/compiler/testData/ir/irText/errors/unresolvedReference.fir.kt.txt @@ -0,0 +1,15 @@ +val test1: ErrorType /* ERROR */ + field = error("") /* ERROR CALL */ + get + +val test2: ErrorType /* ERROR */ + field = error("") /* ERROR CALL */ + get + +val test3: ErrorType /* ERROR */ + field = error("") /* ERROR CALL */56; + get + +val test4: ErrorType /* ERROR */ + field = error("") /* ERROR CALL */error("") /* ERROR EXPRESSION */; + get diff --git a/compiler/testData/ir/irText/expressions/argumentMappedWithError.fir.kt.txt b/compiler/testData/ir/irText/expressions/argumentMappedWithError.fir.kt.txt new file mode 100644 index 00000000000..f74e529006e --- /dev/null +++ b/compiler/testData/ir/irText/expressions/argumentMappedWithError.fir.kt.txt @@ -0,0 +1,11 @@ +fun Number.convert(): R { + return TODO() +} + +fun foo(arg: Number) { +} + +fun main(args: Array) { + val x: Int = 0 + foo(arg = x.convert()) +} diff --git a/compiler/testData/ir/irText/expressions/arrayAccess.fir.kt.txt b/compiler/testData/ir/irText/expressions/arrayAccess.fir.kt.txt new file mode 100644 index 00000000000..e33ba09ae54 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/arrayAccess.fir.kt.txt @@ -0,0 +1,11 @@ +val p: Int + field = 0 + get + +fun foo(): Int { + return 1 +} + +fun test(a: IntArray): Int { + return a.get(index = 0).plus(other = a.get(index = ())).plus(other = a.get(index = foo())) +} diff --git a/compiler/testData/ir/irText/expressions/arrayAssignment.fir.kt.txt b/compiler/testData/ir/irText/expressions/arrayAssignment.fir.kt.txt new file mode 100644 index 00000000000..b3e3170c83c --- /dev/null +++ b/compiler/testData/ir/irText/expressions/arrayAssignment.fir.kt.txt @@ -0,0 +1,12 @@ +fun test() { + val x: IntArray = intArrayOf(elements = [1, 2, 3]) + x.set(index = 1, value = 0) +} + +fun foo(): Int { + return 1 +} + +fun test2() { + intArrayOf(elements = [1, 2, 3]).set(index = foo(), value = 1) +} diff --git a/compiler/testData/ir/irText/expressions/arrayAugmentedAssignment1.fir.kt.txt b/compiler/testData/ir/irText/expressions/arrayAugmentedAssignment1.fir.kt.txt new file mode 100644 index 00000000000..7b081b2502e --- /dev/null +++ b/compiler/testData/ir/irText/expressions/arrayAugmentedAssignment1.fir.kt.txt @@ -0,0 +1,45 @@ +fun foo(): IntArray { + return intArrayOf(elements = [1, 2, 3]) +} + +fun bar(): Int { + return 42 +} + +class C { + constructor(x: IntArray) /* primary */ { + super/*Any*/() + /* () */ + + } + + val x: IntArray + field = x + get + +} + +fun testVariable() { + var x: IntArray = foo() + { // BLOCK + val <>: IntArray = x + val <>: Int = 0 + <>.set(index = <>, value = <>.get(index = <>).plus(other = 1)) + } +} + +fun testCall() { + { // BLOCK + val <>: IntArray = foo() + val <>: Int = bar() + <>.set(index = <>, value = <>.get(index = <>).times(other = 2)) + } +} + +fun testMember(c: C) { + val : IntArray = c.() + val : Int = 0 + val : Int = .get(index = ) + .set(index = , value = .inc()) + /*~> Unit */ +} diff --git a/compiler/testData/ir/irText/expressions/arrayAugmentedAssignment2.fir.kt.txt b/compiler/testData/ir/irText/expressions/arrayAugmentedAssignment2.fir.kt.txt new file mode 100644 index 00000000000..4c7242bb03b --- /dev/null +++ b/compiler/testData/ir/irText/expressions/arrayAugmentedAssignment2.fir.kt.txt @@ -0,0 +1,17 @@ +interface IA { + abstract operator fun get(index: String): Int + +} + +interface IB { + abstract operator fun IA.set(index: String, value: Int) + +} + +fun IB.test(a: IA) { + { // BLOCK + val <>: IA = a + val <>: String = "" + (, <>).set(index = <>, value = <>.get(index = <>).plus(other = 42)) + } +} diff --git a/compiler/testData/ir/irText/expressions/augmentedAssignment1.fir.kt.txt b/compiler/testData/ir/irText/expressions/augmentedAssignment1.fir.kt.txt new file mode 100644 index 00000000000..245950f4c16 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/augmentedAssignment1.fir.kt.txt @@ -0,0 +1,21 @@ +var p: Int + field = 0 + get + set + +fun testVariable() { + var x: Int = 0 + x = x.plus(other = 1) + x = x.minus(other = 2) + x = x.times(other = 3) + x = x.div(other = 4) + x = x.rem(other = 5) +} + +fun testProperty() { + ( = ().plus(other = 1)) + ( = ().minus(other = 2)) + ( = ().times(other = 3)) + ( = ().div(other = 4)) + ( = ().rem(other = 5)) +} diff --git a/compiler/testData/ir/irText/expressions/augmentedAssignment2.fir.kt.txt b/compiler/testData/ir/irText/expressions/augmentedAssignment2.fir.kt.txt new file mode 100644 index 00000000000..553f4cec3e5 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/augmentedAssignment2.fir.kt.txt @@ -0,0 +1,44 @@ +class A { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +operator fun A.plusAssign(s: String) { +} + +operator fun A.minusAssign(s: String) { +} + +operator fun A.timesAssign(s: String) { +} + +operator fun A.divAssign(s: String) { +} + +operator fun A.remAssign(s: String) { +} + +val p: A + field = A() + get + +fun testVariable() { + val a: A = A() + a.plusAssign(s = "+=") + a.minusAssign(s = "-=") + a.timesAssign(s = "*=") + a.divAssign(s = "/=") + a.remAssign(s = "*=") +} + +fun testProperty() { + ().plusAssign(s = "+=") + ().minusAssign(s = "-=") + ().timesAssign(s = "*=") + ().divAssign(s = "/=") + ().remAssign(s = "%=") +} diff --git a/compiler/testData/ir/irText/expressions/augmentedAssignmentWithExpression.fir.kt.txt b/compiler/testData/ir/irText/expressions/augmentedAssignmentWithExpression.fir.kt.txt new file mode 100644 index 00000000000..c4ee2156298 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/augmentedAssignmentWithExpression.fir.kt.txt @@ -0,0 +1,31 @@ +class Host { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + operator fun plusAssign(x: Int) { + } + + fun test1() { + .plusAssign(x = 1) + } + +} + +fun foo(): Host { + return Host() +} + +fun Host.test2() { + .plusAssign(x = 1) +} + +fun test3() { + foo().plusAssign(x = 1) +} + +fun test4(a: Function0) { + a.invoke().plusAssign(x = 1) +} diff --git a/compiler/testData/ir/irText/expressions/badBreakContinue.fir.kt.txt b/compiler/testData/ir/irText/expressions/badBreakContinue.fir.kt.txt new file mode 100644 index 00000000000..64d184dc86f --- /dev/null +++ b/compiler/testData/ir/irText/expressions/badBreakContinue.fir.kt.txt @@ -0,0 +1,28 @@ +fun test1() { + error("") /* ERROR EXPRESSION */ + error("") /* ERROR EXPRESSION */ +} + +fun test2() { + L1@ while (true) { // BLOCK + error("") /* ERROR EXPRESSION */ + error("") /* ERROR EXPRESSION */ + } +} + +fun test3() { + L1@ while (true) { // BLOCK + val lambda: Function0 = local fun (): Nothing { + break@L1 + continue@L1 + } + + } +} + +fun test4() { + while (error("") /* ERROR EXPRESSION */) { // BLOCK + } + while (error("") /* ERROR EXPRESSION */) { // BLOCK + } +} diff --git a/compiler/testData/ir/irText/expressions/bangbang.fir.kt.txt b/compiler/testData/ir/irText/expressions/bangbang.fir.kt.txt new file mode 100644 index 00000000000..dd8140cc05f --- /dev/null +++ b/compiler/testData/ir/irText/expressions/bangbang.fir.kt.txt @@ -0,0 +1,29 @@ +fun test1(a: Any?): Any { + return CHECK_NOT_NULL(arg0 = a) +} + +fun test2(a: Any?): Int { + return CHECK_NOT_NULL(arg0 = { // BLOCK + val tmp0_safe_receiver: Any? = a + when { + EQEQ(arg0 = tmp0_safe_receiver, arg1 = null) -> null + else -> tmp0_safe_receiver.hashCode() + } + }) +} + +fun test3(a: X): X { + return CHECK_NOT_NULL(arg0 = a) +} + +fun useString(s: String) { +} + +fun test4(a: X) { + when { + a is String? -> CHECK_NOT_NULL(arg0 = a /*as String? */) /*~> Unit */ + } + when { + a is String? -> useString(s = CHECK_NOT_NULL(arg0 = a /*as String? */)) + } +} diff --git a/compiler/testData/ir/irText/expressions/breakContinue.fir.kt.txt b/compiler/testData/ir/irText/expressions/breakContinue.fir.kt.txt new file mode 100644 index 00000000000..df1be4e5fc9 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/breakContinue.fir.kt.txt @@ -0,0 +1,34 @@ +fun test1() { + while (true) break + dobreak while (true) + while (true) continue + docontinue while (true) +} + +fun test2() { + OUTER@ while (true) { // BLOCK + INNER@ while (true) { // BLOCK + break@INNER + break@OUTER + } + break@OUTER + } + OUTER@ while (true) { // BLOCK + INNER@ while (true) { // BLOCK + continue@INNER + continue@OUTER + } + continue@OUTER + } +} + +fun test3() { + L@ while (true) { // BLOCK + L@ while (true) break@L + break@L + } + L@ while (true) { // BLOCK + L@ while (true) continue@L + continue@L + } +} diff --git a/compiler/testData/ir/irText/expressions/breakContinueInLoopHeader.fir.kt.txt b/compiler/testData/ir/irText/expressions/breakContinueInLoopHeader.fir.kt.txt new file mode 100644 index 00000000000..88576c0eed8 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/breakContinueInLoopHeader.fir.kt.txt @@ -0,0 +1,78 @@ +fun test1(c: Boolean?) { + L@ while (true) { // BLOCK + L2@ while ({ // BLOCK + val : Boolean? = c + when { + EQEQ(arg0 = , arg1 = null) -> break@L + else -> /*as Boolean */ + } + }) { // BLOCK + } + } +} + +fun test2(c: Boolean?) { + L@ while (true) { // BLOCK + L2@ while ({ // BLOCK + val : Boolean? = c + when { + EQEQ(arg0 = , arg1 = null) -> continue@L + else -> /*as Boolean */ + } + }) { // BLOCK + } + } +} + +fun test3(ss: List?) { + L@ while (true) { // BLOCK + { // BLOCK + val : Iterator = { // BLOCK + val : List? = ss + when { + EQEQ(arg0 = , arg1 = null) -> continue@L + else -> /*as List */ + } + }.iterator() + L2@ while (.hasNext()) { // BLOCK + val s: String = .next() + } + } + } +} + +fun test4(ss: List?) { + L@ while (true) { // BLOCK + { // BLOCK + val : Iterator = { // BLOCK + val : List? = ss + when { + EQEQ(arg0 = , arg1 = null) -> break@L + else -> /*as List */ + } + }.iterator() + L2@ while (.hasNext()) { // BLOCK + val s: String = .next() + } + } + } +} + +fun test5() { + var i: Int = 0 + Outer@ while (true) { // BLOCK + i = i.inc() + i /*~> Unit */ + var j: Int = 0 + Inner@ do// COMPOSITE { + j = j.inc() + j + // } while (when { + greaterOrEqual(arg0 = j, arg1 = 3) -> false + else -> break@Outer + }) + when { + EQEQ(arg0 = i, arg1 = 3) -> break@Outer + } + } +} diff --git a/compiler/testData/ir/irText/expressions/breakContinueInWhen.fir.kt.txt b/compiler/testData/ir/irText/expressions/breakContinueInWhen.fir.kt.txt new file mode 100644 index 00000000000..9e334cc43e2 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/breakContinueInWhen.fir.kt.txt @@ -0,0 +1,70 @@ +fun testBreakFor() { + val xs: IntArray = IntArray(size = 10, init = local fun (i: Int): Int { + return i + } +) + var k: Int = 0 + { // BLOCK + val : IntIterator = xs.iterator() + while (.hasNext()) { // BLOCK + val x: Int = .next() + when { + greater(arg0 = k, arg1 = 2) -> break + } + } + } +} + +fun testBreakWhile() { + var k: Int = 0 + while (less(arg0 = k, arg1 = 10)) when { + greater(arg0 = k, arg1 = 2) -> break + } +} + +fun testBreakDoWhile() { + var k: Int = 0 + dowhen { + greater(arg0 = k, arg1 = 2) -> break + } while (less(arg0 = k, arg1 = 10)) +} + +fun testContinueFor() { + val xs: IntArray = IntArray(size = 10, init = local fun (i: Int): Int { + return i + } +) + var k: Int = 0 + { // BLOCK + val : IntIterator = xs.iterator() + while (.hasNext()) { // BLOCK + val x: Int = .next() + when { + greater(arg0 = k, arg1 = 2) -> continue + } + } + } +} + +fun testContinueWhile() { + var k: Int = 0 + while (less(arg0 = k, arg1 = 10)) when { + greater(arg0 = k, arg1 = 2) -> continue + } +} + +fun testContinueDoWhile() { + var k: Int = 0 + var s: String = "" + do// COMPOSITE { + k = k.inc() + k /*~> Unit */ + when { + greater(arg0 = k, arg1 = 2) -> continue + } + s = s.plus(other = k.toString() + ";") + // } while (less(arg0 = k, arg1 = 10)) + when { + EQEQ(arg0 = s, arg1 = "1;2;").not() -> throw AssertionError(p0 = s) + } +} diff --git a/compiler/testData/ir/irText/expressions/callableReferences/adaptedExtensionFunctions.fir.kt.txt b/compiler/testData/ir/irText/expressions/callableReferences/adaptedExtensionFunctions.fir.kt.txt new file mode 100644 index 00000000000..801dd51fa50 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/callableReferences/adaptedExtensionFunctions.fir.kt.txt @@ -0,0 +1,32 @@ +fun use(f: @ExtensionFunctionType @ExtensionFunctionType Function2) { +} + +class C { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +fun C.extensionVararg(i: Int, vararg s: String) { +} + +fun C.extensionDefault(i: Int, s: String = "") { +} + +fun C.extensionBoth(i: Int, s: String = "", vararg t: String) { +} + +fun testExtensionVararg() { + use(f = ::extensionVararg) +} + +fun testExtensionDefault() { + use(f = ::extensionDefault) +} + +fun testExtensionBoth() { + use(f = ::extensionBoth) +} diff --git a/compiler/testData/ir/irText/expressions/callableReferences/adaptedWithCoercionToUnit.fir.kt.txt b/compiler/testData/ir/irText/expressions/callableReferences/adaptedWithCoercionToUnit.fir.kt.txt new file mode 100644 index 00000000000..5786451f5dd --- /dev/null +++ b/compiler/testData/ir/irText/expressions/callableReferences/adaptedWithCoercionToUnit.fir.kt.txt @@ -0,0 +1,45 @@ +fun useUnit0(fn: Function0) { +} + +fun useUnit1(fn: Function1) { +} + +fun fn0(): Int { + return 1 +} + +fun fn1(x: Int): Int { + return 1 +} + +fun fnv(vararg xs: Int): Int { + return 1 +} + +fun test0() { + return useUnit0(fn = local fun fn0() { + fn0() + } +) +} + +fun test1() { + return useUnit1(fn = local fun fn1(p0: Int) { + fn1(x = p0) + } +) +} + +fun testV0() { + return useUnit0(fn = local fun fnv() { + fnv() + } +) +} + +fun testV1() { + return useUnit1(fn = local fun fnv(p0: Int) { + fnv(xs = [p0]) + } +) +} diff --git a/compiler/testData/ir/irText/expressions/callableReferences/boundInlineAdaptedReference.fir.kt.txt b/compiler/testData/ir/irText/expressions/callableReferences/boundInlineAdaptedReference.fir.kt.txt new file mode 100644 index 00000000000..78394c432fc --- /dev/null +++ b/compiler/testData/ir/irText/expressions/callableReferences/boundInlineAdaptedReference.fir.kt.txt @@ -0,0 +1,18 @@ +package test + +inline fun foo(x: Function0) { +} + +fun String.id(s: String = , vararg xs: Int): String { + return s +} + +fun test() { + foo(x = { // BLOCK + local fun String.id() { + receiver.id() + } + + "Fail"::id + }) +} diff --git a/compiler/testData/ir/irText/expressions/callableReferences/caoWithAdaptationForSam.fir.kt.txt b/compiler/testData/ir/irText/expressions/callableReferences/caoWithAdaptationForSam.fir.kt.txt new file mode 100644 index 00000000000..21a1418b094 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/callableReferences/caoWithAdaptationForSam.fir.kt.txt @@ -0,0 +1,97 @@ +fun interface IFoo { + abstract fun foo(i: Int) + +} + +fun interface IFoo2 : IFoo { + +} + +object A { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +object B { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +operator fun A.get(i: IFoo): Int { + return 1 +} + +operator fun A.set(i: IFoo, newValue: Int) { +} + +operator fun B.get(i: IFoo): Int { + return 1 +} + +operator fun B.set(i: IFoo2, newValue: Int) { +} + +fun withVararg(vararg xs: Int): Int { + return 42 +} + +fun test1() { + { // BLOCK + val <>: A = A + val <>: KFunction1 = ::withVararg + error("") /* ERROR CALL */<>; error("") /* ERROR CALL */<>; .plus(other = 1); + } +} + +fun test2() { + { // BLOCK + val <>: B = B + val <>: KFunction1 = ::withVararg + error("") /* ERROR CALL */<>; error("") /* ERROR CALL */<>; .plus(other = 1); + } +} + +fun test3(fn: Function1) { + { // BLOCK + val <>: A = A + val <>: Function1 = fn + <>.set(i = <> /*-> IFoo */, newValue = <>.get(i = <> /*-> IFoo */).plus(other = 1)) + } +} + +fun test4(fn: Function1) { + when { + fn is IFoo -> { // BLOCK + val <>: A = A + val <>: IFoo = fn /*as IFoo */ + <>.set(i = <>, newValue = <>.get(i = <>).plus(other = 1)) + } + } +} + +fun test5(a: Any) { + a as Function1 /*~> Unit */ + { // BLOCK + val <>: A = A + val <>: Function1 = a /*as Function1 */ + <>.set(i = <> /*-> IFoo */, newValue = <>.get(i = <> /*-> IFoo */).plus(other = 1)) + } +} + +fun test6(a: Any) { + a as Function1 /*~> Unit */ + a /*as Function1 */ as IFoo /*~> Unit */ + { // BLOCK + val <>: A = A + val <>: Function1 = a /*as Function1 */ + <>.set(i = <>, newValue = <>.get(i = <>).plus(other = 1)) + } +} diff --git a/compiler/testData/ir/irText/expressions/callableReferences/constructorWithAdaptedArguments.fir.kt.txt b/compiler/testData/ir/irText/expressions/callableReferences/constructorWithAdaptedArguments.fir.kt.txt new file mode 100644 index 00000000000..d4ac82252f5 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/callableReferences/constructorWithAdaptedArguments.fir.kt.txt @@ -0,0 +1,42 @@ +fun use(fn: Function1): Any { + return fn.invoke(p1 = 42) +} + +class C { + constructor(vararg xs: Int) /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +class Outer { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + inner class Inner { + constructor(vararg xs: Int) /* primary */ { + super/*Any*/() + /* () */ + + } + + } + +} + +fun testConstructor(): Any { + return use(fn = C::) +} + +fun testInnerClassConstructor(outer: Outer): Any { + return use(fn = outer::) +} + +fun testInnerClassConstructorCapturingOuter(): Any { + return use(fn = Outer()::) +} diff --git a/compiler/testData/ir/irText/expressions/callableReferences/kt37131.fir.kt.txt b/compiler/testData/ir/irText/expressions/callableReferences/kt37131.fir.kt.txt new file mode 100644 index 00000000000..f4cd26c31b7 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/callableReferences/kt37131.fir.kt.txt @@ -0,0 +1,28 @@ +fun foo(x: String = ""): String { + return x +} + +class C { + constructor(x: String = "") /* primary */ { + super/*Any*/() + /* () */ + + } + + val x: String + field = x + get + +} + +fun use(fn: Function0): Any { + return fn.invoke() +} + +fun testFn(): Any { + return use(fn = ::foo) +} + +fun testCtor(): Any { + return use(fn = C::) +} diff --git a/compiler/testData/ir/irText/expressions/callableReferences/suspendConversion.fir.kt.txt b/compiler/testData/ir/irText/expressions/callableReferences/suspendConversion.fir.kt.txt new file mode 100644 index 00000000000..43399532177 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/callableReferences/suspendConversion.fir.kt.txt @@ -0,0 +1,99 @@ +fun useSuspend(fn: SuspendFunction0) { +} + +fun useSuspendInt(fn: SuspendFunction1) { +} + +suspend fun foo0() { +} + +fun foo1() { +} + +fun fooInt(x: Int) { +} + +fun foo2(vararg xs: Int) { +} + +fun foo3(): Int { + return 42 +} + +fun foo4(i: Int = 42) { +} + +class C { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + fun bar() { + } + +} + +fun testLambda() { + useSuspend(fn = local suspend fun () { + foo1() + } +) +} + +fun testNoCoversion() { + useSuspend(fn = ::foo0) +} + +fun testSuspendPlain() { + useSuspend(fn = local suspend fun foo1() { + foo1() + } +) +} + +fun testSuspendWithArgs() { + useSuspendInt(fn = local suspend fun fooInt(p0: Int) { + fooInt(x = p0) + } +) +} + +fun testWithVararg() { + useSuspend(fn = local suspend fun foo2() { + foo2() + } +) +} + +fun testWithVarargMapped() { + useSuspendInt(fn = local suspend fun foo2(p0: Int) { + foo2(xs = [p0]) + } +) +} + +fun testWithCoercionToUnit() { + useSuspend(fn = local suspend fun foo3() { + foo3() + } +) +} + +fun testWithDefaults() { + useSuspend(fn = local suspend fun foo4() { + foo4() + } +) +} + +fun testWithBoundReceiver() { + useSuspend(fn = { // BLOCK + local suspend fun C.bar() { + receiver.bar() + } + + C()::bar + }) +} diff --git a/compiler/testData/ir/irText/expressions/callableReferences/typeArguments.fir.kt.txt b/compiler/testData/ir/irText/expressions/callableReferences/typeArguments.fir.kt.txt new file mode 100644 index 00000000000..b77a45000ec --- /dev/null +++ b/compiler/testData/ir/irText/expressions/callableReferences/typeArguments.fir.kt.txt @@ -0,0 +1,29 @@ +object Host { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + inline fun objectMember(x: T) { + } + +} + +inline fun topLevel1(x: T) { +} + +inline fun topLevel2(x: List) { +} + +val test1: Function1 + field = ::topLevel1/*()*/ + get + +val test2: Function1, Unit> + field = ::topLevel2/*()*/ + get + +val test3: Function1 + field = Host::objectMember/*()*/ + get diff --git a/compiler/testData/ir/irText/expressions/callableReferences/unboundMemberReferenceWithAdaptedArguments.fir.kt.txt b/compiler/testData/ir/irText/expressions/callableReferences/unboundMemberReferenceWithAdaptedArguments.fir.kt.txt new file mode 100644 index 00000000000..3f60c4c9a20 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/callableReferences/unboundMemberReferenceWithAdaptedArguments.fir.kt.txt @@ -0,0 +1,58 @@ +fun use1(fn: Function2) { +} + +fun use2(fn: Function1) { +} + +open class A { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + open fun foo(vararg xs: Int): Int { + return 1 + } + +} + +object Obj : A { + private constructor() /* primary */ { + super/*A*/() + /* () */ + + } + + override fun foo(vararg xs: Int): Int { + return 1 + } + +} + +fun testUnbound() { + use1(fn = local fun foo(p0: A, p1: Int) { + p0.foo() + } +) +} + +fun testBound(a: A) { + use2(fn = { // BLOCK + local fun A.foo(p0: Int) { + receiver.foo(xs = [p0]) + } + + a::foo + }) +} + +fun testObject() { + use2(fn = { // BLOCK + local fun Obj.foo(p0: Int) { + receiver.foo(xs = [p0]) + } + + Obj::foo + }) +} diff --git a/compiler/testData/ir/irText/expressions/callableReferences/withAdaptationForSam.fir.kt.txt b/compiler/testData/ir/irText/expressions/callableReferences/withAdaptationForSam.fir.kt.txt new file mode 100644 index 00000000000..66a0dce09b3 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/callableReferences/withAdaptationForSam.fir.kt.txt @@ -0,0 +1,18 @@ +fun interface IFoo { + abstract fun foo(i: Int) + +} + +fun useFoo(foo: IFoo) { +} + +fun withVararg(vararg xs: Int): Int { + return 42 +} + +fun test() { + useFoo(foo = local fun withVararg(p0: Int) { + withVararg(xs = [p0]) + } + /*-> IFoo */) +} diff --git a/compiler/testData/ir/irText/expressions/callableReferences/withAdaptedArguments.fir.kt.txt b/compiler/testData/ir/irText/expressions/callableReferences/withAdaptedArguments.fir.kt.txt new file mode 100644 index 00000000000..8063416bc28 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/callableReferences/withAdaptedArguments.fir.kt.txt @@ -0,0 +1,71 @@ +fun use(fn: Function1): String { + return fn.invoke(p1 = 1) +} + +fun use0(fn: Function0): String { + return fn.invoke() +} + +fun coerceToUnit(fn: Function1) { +} + +fun fnWithDefault(a: Int, b: Int = 42): String { + return "abc" +} + +fun fnWithDefaults(a: Int = 1, b: Int = 2): String { + return "" +} + +fun fnWithVarargs(vararg xs: Int): String { + return "abc" +} + +object Host { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + fun importedObjectMemberWithVarargs(vararg xs: Int): String { + return "abc" + } + +} + +fun testDefault(): String { + return use(fn = ::fnWithDefault) +} + +fun testVararg(): String { + return use(fn = local fun fnWithVarargs(p0: Int): String { + return fnWithVarargs(xs = [p0]) + } +) +} + +fun testCoercionToUnit() { + return coerceToUnit(fn = local fun fnWithDefault(p0: Int) { + fnWithDefault(a = p0) + } +) +} + +fun testImportedObjectMember(): String { + return use(fn = { // BLOCK + local fun Host.importedObjectMemberWithVarargs(p0: Int): String { + return receiver.importedObjectMemberWithVarargs(xs = [p0]) + } + + ::importedObjectMemberWithVarargs + }) +} + +fun testDefault0(): String { + return use0(fn = ::fnWithDefaults) +} + +fun testVararg0(): String { + return use0(fn = ::fnWithVarargs) +} diff --git a/compiler/testData/ir/irText/expressions/callableReferences/withArgumentAdaptationAndReceiver.fir.kt.txt b/compiler/testData/ir/irText/expressions/callableReferences/withArgumentAdaptationAndReceiver.fir.kt.txt new file mode 100644 index 00000000000..706b2504009 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/callableReferences/withArgumentAdaptationAndReceiver.fir.kt.txt @@ -0,0 +1,68 @@ +fun use(fn: Function1) { + fn.invoke(p1 = 1) +} + +class Host { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + fun withVararg(vararg xs: Int): String { + return "" + } + + fun testImplicitThis() { + use(fn = { // BLOCK + local fun Host.withVararg(p0: Int) { + receiver.withVararg(xs = [p0]) + } + + Host::withVararg + }) + } + + fun testBoundReceiverLocalVal() { + val h: Host = Host() + use(fn = { // BLOCK + local fun Host.withVararg(p0: Int) { + receiver.withVararg(xs = [p0]) + } + + h::withVararg + }) + } + + fun testBoundReceiverLocalVar() { + var h: Host = Host() + use(fn = { // BLOCK + local fun Host.withVararg(p0: Int) { + receiver.withVararg(xs = [p0]) + } + + h::withVararg + }) + } + + fun testBoundReceiverParameter(h: Host) { + use(fn = { // BLOCK + local fun Host.withVararg(p0: Int) { + receiver.withVararg(xs = [p0]) + } + + h::withVararg + }) + } + + fun testBoundReceiverExpression() { + use(fn = { // BLOCK + local fun Host.withVararg(p0: Int) { + receiver.withVararg(xs = [p0]) + } + + Host()::withVararg + }) + } + +} diff --git a/compiler/testData/ir/irText/expressions/callableReferences/withVarargViewedAsArray.fir.kt.txt b/compiler/testData/ir/irText/expressions/callableReferences/withVarargViewedAsArray.fir.kt.txt new file mode 100644 index 00000000000..b124b6438db --- /dev/null +++ b/compiler/testData/ir/irText/expressions/callableReferences/withVarargViewedAsArray.fir.kt.txt @@ -0,0 +1,52 @@ +fun sum(vararg args: Int): Int { + var result: Int = 0 + { // BLOCK + val : IntIterator = args.iterator() + while (.hasNext()) { // BLOCK + val arg: Int = .next() + result = result.plus(other = arg) + } + } + return result +} + +fun nsum(vararg args: Number): Int { + return sum(args = [*IntArray(size = args.(), init = local fun (it: Int): Int { + return args.get(index = it).toInt() + } +)]) +} + +fun zap(vararg b: String, k: Int = 42) { +} + +fun usePlainArgs(fn: Function2) { +} + +fun usePrimitiveArray(fn: Function1) { +} + +fun useArray(fn: Function1, Int>) { +} + +fun useStringArray(fn: Function1, Unit>) { +} + +fun testPlainArgs() { + usePlainArgs(fn = local fun sum(p0: Int, p1: Int): Int { + return sum(args = [p0, p1]) + } +) +} + +fun testPrimitiveArrayAsVararg() { + usePrimitiveArray(fn = ::sum) +} + +fun testArrayAsVararg() { + useArray(fn = ::nsum) +} + +fun testArrayAndDefaults() { + useStringArray(fn = ::zap) +} diff --git a/compiler/testData/ir/irText/expressions/catchParameterAccess.fir.kt.txt b/compiler/testData/ir/irText/expressions/catchParameterAccess.fir.kt.txt new file mode 100644 index 00000000000..ccb59492ec7 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/catchParameterAccess.fir.kt.txt @@ -0,0 +1,5 @@ +fun test(f: Function0) { + return try f.invoke() + catch (e: Exception)throw e + +} diff --git a/compiler/testData/ir/irText/expressions/classReference.fir.kt.txt b/compiler/testData/ir/irText/expressions/classReference.fir.kt.txt new file mode 100644 index 00000000000..e03a82adcb7 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/classReference.fir.kt.txt @@ -0,0 +1,15 @@ +class A { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +fun test() { + A::class /*~> Unit */ + A()::class /*~> Unit */ + A::class.() /*~> Unit */ + A()::class.() /*~> Unit */ +} diff --git a/compiler/testData/ir/irText/expressions/coercionToUnit.fir.kt.txt b/compiler/testData/ir/irText/expressions/coercionToUnit.fir.kt.txt new file mode 100644 index 00000000000..ab06fa52ba3 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/coercionToUnit.fir.kt.txt @@ -0,0 +1,27 @@ +val test1: Function0 + field = local fun (): Int { + return 42 + } + + get + +fun test2(mc: MutableCollection) { + mc.add(element = "") /*~> Unit */ +} + +fun test3() { + { // BLOCK + val tmp0_safe_receiver: PrintStream? = #out + when { + EQEQ(arg0 = tmp0_safe_receiver, arg1 = null) -> null + else -> tmp0_safe_receiver.println(p0 = "Hello,") + } + } /*~> Unit */ + { // BLOCK + val tmp1_safe_receiver: PrintStream? = #out + when { + EQEQ(arg0 = tmp1_safe_receiver, arg1 = null) -> null + else -> tmp1_safe_receiver.println(p0 = "world!") + } + } /*~> Unit */ +} diff --git a/compiler/testData/ir/irText/expressions/complexAugmentedAssignment.fir.kt.txt b/compiler/testData/ir/irText/expressions/complexAugmentedAssignment.fir.kt.txt new file mode 100644 index 00000000000..e0c7037a1d5 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/complexAugmentedAssignment.fir.kt.txt @@ -0,0 +1,100 @@ +object X1 { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + var x1: Int + field = 0 + get + set + + object X2 { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + var x2: Int + field = 0 + get + set + + object X3 { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + var x3: Int + field = 0 + get + set + + } + + } + +} + +fun test1(a: IntArray) { + var i: Int = 0 + val : IntArray = a + val : Int = { // BLOCK + val : Int = i + i = .inc() + + } + val : Int = .get(index = ) + .set(index = , value = .inc()) + /*~> Unit */ +} + +fun test2() { + val : X1 = X1 + val : Int = .() + .( = .inc()) + /*~> Unit */ + val : X2 = X2 + val : Int = .() + .( = .inc()) + /*~> Unit */ + val : X3 = X3 + val : Int = .() + .( = .inc()) + /*~> Unit */ +} + +class B { + constructor(s: Int = 0) /* primary */ { + super/*Any*/() + /* () */ + + } + + var s: Int + field = s + get + set + +} + +object Host { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + operator fun B.plusAssign(b: B) { + .( = .().plus(other = b.())) + } + +} + +fun Host.test3(v: B) { + (, v).plusAssign(b = B(s = 1000)) +} diff --git a/compiler/testData/ir/irText/expressions/constructorWithOwnTypeParametersCall.fir.kt.txt b/compiler/testData/ir/irText/expressions/constructorWithOwnTypeParametersCall.fir.kt.txt new file mode 100644 index 00000000000..9ab58236aa5 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/constructorWithOwnTypeParametersCall.fir.kt.txt @@ -0,0 +1,25 @@ +fun testKotlin(): K2 { + return K1().K2() +} + +fun testJava(): J2 { + return J1().J2() +} + +class K1 { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + inner class K2 { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + } + +} diff --git a/compiler/testData/ir/irText/expressions/conventionComparisons.fir.kt.txt b/compiler/testData/ir/irText/expressions/conventionComparisons.fir.kt.txt new file mode 100644 index 00000000000..8759cf24cc9 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/conventionComparisons.fir.kt.txt @@ -0,0 +1,24 @@ +interface IA { + +} + +interface IB { + abstract operator fun IA.compareTo(other: IA): Int + +} + +fun IB.test1(a1: IA, a2: IA): Boolean { + return greater(arg0 = (, a1).compareTo(other = a2), arg1 = 0) +} + +fun IB.test2(a1: IA, a2: IA): Boolean { + return greaterOrEqual(arg0 = (, a1).compareTo(other = a2), arg1 = 0) +} + +fun IB.test3(a1: IA, a2: IA): Boolean { + return less(arg0 = (, a1).compareTo(other = a2), arg1 = 0) +} + +fun IB.test4(a1: IA, a2: IA): Boolean { + return lessOrEqual(arg0 = (, a1).compareTo(other = a2), arg1 = 0) +} diff --git a/compiler/testData/ir/irText/expressions/destructuring1.fir.kt.txt b/compiler/testData/ir/irText/expressions/destructuring1.fir.kt.txt new file mode 100644 index 00000000000..a5f746ddfba --- /dev/null +++ b/compiler/testData/ir/irText/expressions/destructuring1.fir.kt.txt @@ -0,0 +1,31 @@ +object A { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +object B { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + operator fun A.component1(): Int { + return 1 + } + + operator fun A.component2(): Int { + return 2 + } + +} + +fun B.test() { + val : A = A + val x: Int = (, ).component1() + val y: Int = (, ).component2() +} diff --git a/compiler/testData/ir/irText/expressions/destructuringWithUnderscore.fir.kt.txt b/compiler/testData/ir/irText/expressions/destructuringWithUnderscore.fir.kt.txt new file mode 100644 index 00000000000..dff11a75023 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/destructuringWithUnderscore.fir.kt.txt @@ -0,0 +1,36 @@ +object A { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +object B { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + operator fun A.component1(): Int { + return 1 + } + + operator fun A.component2(): Int { + return 2 + } + + operator fun A.component3(): Int { + return 3 + } + +} + +fun B.test() { + val : A = A + val x: Int = (, ).component1() + val _: Int = (, ).component2() + val z: Int = (, ).component3() +} diff --git a/compiler/testData/ir/irText/expressions/elvis.fir.kt.txt b/compiler/testData/ir/irText/expressions/elvis.fir.kt.txt new file mode 100644 index 00000000000..0ec550b8a10 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/elvis.fir.kt.txt @@ -0,0 +1,63 @@ +val p: Any? + field = null + get + +fun foo(): Any? { + return null +} + +fun test1(a: Any?, b: Any): Any { + return { // BLOCK + val : Any? = a + when { + EQEQ(arg0 = , arg1 = null) -> b + else -> /*as Any */ + } + } +} + +fun test2(a: String?, b: Any): Any { + return { // BLOCK + val : String? = a + when { + EQEQ(arg0 = , arg1 = null) -> b + else -> /*as String */ + } + } +} + +fun test3(a: Any?, b: Any?): String { + when { + b !is String -> return "" + } + when { + a !is String? -> return "" + } + return { // BLOCK + val : String? = a /*as String? */ + when { + EQEQ(arg0 = , arg1 = null) -> b /*as String */ + else -> /*as String */ + } + } +} + +fun test4(x: Any): Any { + return { // BLOCK + val : Any? = () + when { + EQEQ(arg0 = , arg1 = null) -> x + else -> /*as Any */ + } + } +} + +fun test5(x: Any): Any { + return { // BLOCK + val : Any? = foo() + when { + EQEQ(arg0 = , arg1 = null) -> x + else -> /*as Any */ + } + } +} diff --git a/compiler/testData/ir/irText/expressions/enumEntryAsReceiver.fir.kt.txt b/compiler/testData/ir/irText/expressions/enumEntryAsReceiver.fir.kt.txt new file mode 100644 index 00000000000..898af00a36b --- /dev/null +++ b/compiler/testData/ir/irText/expressions/enumEntryAsReceiver.fir.kt.txt @@ -0,0 +1,40 @@ +abstract enum class X : Enum { + private constructor() /* primary */ { + super/*Enum*/() + /* () */ + + } + + B = B() + private enum entry class B : X { + private constructor() /* primary */ { + super/*X*/() + /* () */ + + } + + val value2: String + field = "OK" + get + + override val value: Function0 + field = local fun (): String { + return .() + } + + override get + + } + + abstract val value: Function0 + abstract get + + fun values(): Array /* Synthetic body for ENUM_VALUES */ + + fun valueOf(value: String): X /* Synthetic body for ENUM_VALUEOF */ + +} + +fun box(): String { + return X.B.().invoke() +} diff --git a/compiler/testData/ir/irText/expressions/enumEntryReferenceFromEnumEntryClass.fir.kt.txt b/compiler/testData/ir/irText/expressions/enumEntryReferenceFromEnumEntryClass.fir.kt.txt new file mode 100644 index 00000000000..48ca5fef585 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/enumEntryReferenceFromEnumEntryClass.fir.kt.txt @@ -0,0 +1,68 @@ +open enum class MyEnum : Enum { + private constructor() /* primary */ { + super/*Enum*/() + /* () */ + + } + + Z = Z() + private enum entry class Z : MyEnum { + private constructor() /* primary */ { + super/*MyEnum*/() + /* () */ + + } + + var counter: Int + field = 0 + get + set + + fun foo() { + } + + fun bar() { + .( = 1) + .foo() + } + + val aLambda: Function0 + field = local fun () { + .( = 1) + .foo() + } + + get + + val anObject: + field = { // BLOCK + local class { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + init { + .( = 1) + .foo() + } + + fun test() { + .( = 1) + .foo() + } + + } + + () + } + get + + } + + fun values(): Array /* Synthetic body for ENUM_VALUES */ + + fun valueOf(value: String): MyEnum /* Synthetic body for ENUM_VALUEOF */ + +} diff --git a/compiler/testData/ir/irText/expressions/equals.fir.kt.txt b/compiler/testData/ir/irText/expressions/equals.fir.kt.txt new file mode 100644 index 00000000000..bfc8d01fbe4 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/equals.fir.kt.txt @@ -0,0 +1,15 @@ +fun testEqeq(a: Int, b: Int): Boolean { + return EQEQ(arg0 = a, arg1 = b) +} + +fun testEquals(a: Int, b: Int): Boolean { + return a.equals(other = b) +} + +fun testJEqeqNull(): Boolean { + return EQEQ(arg0 = #INT_NULL, arg1 = null) +} + +fun testJEqualsNull(): Boolean { + return #INT_NULL.equals(other = null) +} diff --git a/compiler/testData/ir/irText/expressions/exhaustiveWhenElseBranch.fir.kt.txt b/compiler/testData/ir/irText/expressions/exhaustiveWhenElseBranch.fir.kt.txt new file mode 100644 index 00000000000..057c233f5a0 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/exhaustiveWhenElseBranch.fir.kt.txt @@ -0,0 +1,119 @@ +enum class A : Enum { + private constructor() /* primary */ { + super/*Enum*/() + /* () */ + + } + + V1 = A() + + fun values(): Array /* Synthetic body for ENUM_VALUES */ + + fun valueOf(value: String): A /* Synthetic body for ENUM_VALUEOF */ + +} + +fun testVariableAssignment_throws(a: A) { + val x: Int + { // BLOCK + val tmp0_subject: A = a + when { + EQEQ(arg0 = tmp0_subject, arg1 = A.V1) -> { // BLOCK + x = 11 + } + else -> noWhenBranchMatchedException() + } + } +} + +fun testStatement_empty(a: A) { + { // BLOCK + val tmp1_subject: A = a + when { + EQEQ(arg0 = tmp1_subject, arg1 = A.V1) -> 1 + else -> noWhenBranchMatchedException() + } + } /*~> Unit */ +} + +fun testParenthesized_throwsJvm(a: A) { + { // BLOCK + val tmp2_subject: A = a + when { + EQEQ(arg0 = tmp2_subject, arg1 = A.V1) -> 1 + else -> noWhenBranchMatchedException() + } + } /*~> Unit */ +} + +fun testAnnotated_throwsJvm(a: A) { + { // BLOCK + val tmp3_subject: A = a + when { + EQEQ(arg0 = tmp3_subject, arg1 = A.V1) -> 1 + else -> noWhenBranchMatchedException() + } + } /*~> Unit */ +} + +fun testExpression_throws(a: A): Int { + return { // BLOCK + val tmp4_subject: A = a + when { + EQEQ(arg0 = tmp4_subject, arg1 = A.V1) -> 1 + else -> noWhenBranchMatchedException() + } + } +} + +fun testIfTheElseStatement_empty(a: A, flag: Boolean) { + when { + flag -> 0 + else -> { // BLOCK + val tmp5_subject: A = a + when { + EQEQ(arg0 = tmp5_subject, arg1 = A.V1) -> 1 + else -> noWhenBranchMatchedException() + } + } + } /*~> Unit */ +} + +fun testIfTheElseParenthesized_throwsJvm(a: A, flag: Boolean) { + when { + flag -> 0 + else -> { // BLOCK + val tmp6_subject: A = a + when { + EQEQ(arg0 = tmp6_subject, arg1 = A.V1) -> 1 + else -> noWhenBranchMatchedException() + } + } + } /*~> Unit */ +} + +fun testIfTheElseAnnotated_throwsJvm(a: A, flag: Boolean) { + when { + flag -> 0 + else -> { // BLOCK + val tmp7_subject: A = a + when { + EQEQ(arg0 = tmp7_subject, arg1 = A.V1) -> 1 + else -> noWhenBranchMatchedException() + } + } + } /*~> Unit */ +} + +fun testLambdaResultExpression_throws(a: A) { + local fun (): Int { + return { // BLOCK + val tmp8_subject: A = a + when { + EQEQ(arg0 = tmp8_subject, arg1 = A.V1) -> 1 + else -> noWhenBranchMatchedException() + } + } + } +.invoke() /*~> Unit */ +} diff --git a/compiler/testData/ir/irText/expressions/extFunInvokeAsFun.fir.kt.txt b/compiler/testData/ir/irText/expressions/extFunInvokeAsFun.fir.kt.txt new file mode 100644 index 00000000000..de1341623b5 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/extFunInvokeAsFun.fir.kt.txt @@ -0,0 +1,7 @@ +fun with1(receiver: Any?, block: @ExtensionFunctionType @ExtensionFunctionType Function1) { + return block.invoke(p1 = receiver) +} + +fun with2(receiver: Any?, block: @ExtensionFunctionType @ExtensionFunctionType Function1) { + return block.invoke(p1 = receiver) +} diff --git a/compiler/testData/ir/irText/expressions/extFunSafeInvoke.fir.kt.txt b/compiler/testData/ir/irText/expressions/extFunSafeInvoke.fir.kt.txt new file mode 100644 index 00000000000..dff7557aa76 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/extFunSafeInvoke.fir.kt.txt @@ -0,0 +1,9 @@ +fun test(receiver: Any?, fn: @ExtensionFunctionType @ExtensionFunctionType Function3): Unit? { + return { // BLOCK + val tmp0_safe_receiver: Any? = receiver + when { + EQEQ(arg0 = tmp0_safe_receiver, arg1 = null) -> null + else -> fn.invoke(p1 = tmp0_safe_receiver, p2 = 42, p3 = "Hello") + } + } +} diff --git a/compiler/testData/ir/irText/expressions/field.fir.kt.txt b/compiler/testData/ir/irText/expressions/field.fir.kt.txt new file mode 100644 index 00000000000..810d860b9b1 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/field.fir.kt.txt @@ -0,0 +1,13 @@ +var testSimple: Int + field = 0 + get + set(value: Int) { + #testSimple = value + } + +var testAugmented: Int + field = 0 + get + set(value: Int) { + #testAugmented = #testAugmented.plus(other = value) + } diff --git a/compiler/testData/ir/irText/expressions/floatingPointComparisons/floatingPointEquals.fir.kt.txt b/compiler/testData/ir/irText/expressions/floatingPointComparisons/floatingPointEquals.fir.kt.txt new file mode 100644 index 00000000000..a1ed83271ac --- /dev/null +++ b/compiler/testData/ir/irText/expressions/floatingPointComparisons/floatingPointEquals.fir.kt.txt @@ -0,0 +1,115 @@ +fun test1d(x: Double, y: Double): Boolean { + return x.equals(other = y) +} + +fun test2d(x: Double, y: Double?): Boolean { + return x.equals(other = y) +} + +fun test3d(x: Double, y: Any): Boolean { + return x.equals(other = y) +} + +fun test4d(x: Double, y: Number): Boolean { + return x.equals(other = y) +} + +fun test5d(x: Double, y: Any): Boolean { + return when { + y is Double -> x.equals(other = y /*as Double */) + else -> false + } +} + +fun test6d(x: Any, y: Any): Boolean { + return when { + when { + x is Double -> y is Double + else -> false + } -> x /*as Double */.equals(other = y /*as Double */) + else -> false + } +} + +fun test1f(x: Float, y: Float): Boolean { + return x.equals(other = y) +} + +fun test2f(x: Float, y: Float?): Boolean { + return x.equals(other = y) +} + +fun test3f(x: Float, y: Any): Boolean { + return x.equals(other = y) +} + +fun test4f(x: Float, y: Number): Boolean { + return x.equals(other = y) +} + +fun test5f(x: Float, y: Any): Boolean { + return when { + y is Float -> x.equals(other = y /*as Float */) + else -> false + } +} + +fun test6f(x: Any, y: Any): Boolean { + return when { + when { + x is Float -> y is Float + else -> false + } -> x /*as Float */.equals(other = y /*as Float */) + else -> false + } +} + +fun testFD(x: Any, y: Any): Boolean { + return when { + when { + x is Float -> y is Double + else -> false + } -> x /*as Float */.equals(other = y /*as Double */) + else -> false + } +} + +fun testDF(x: Any, y: Any): Boolean { + return when { + when { + x is Double -> y is Float + else -> false + } -> x /*as Double */.equals(other = y /*as Float */) + else -> false + } +} + +fun Float.test1fr(x: Float): Boolean { + return .equals(other = x) +} + +fun Float.test2fr(x: Float?): Boolean { + return .equals(other = x) +} + +fun Float.test3fr(x: Any): Boolean { + return .equals(other = x) +} + +fun Float.test4fr(x: Number): Boolean { + return .equals(other = x) +} + +fun Float.test5fr(x: Any): Boolean { + return when { + x is Float -> .equals(other = x /*as Float */) + else -> false + } +} + +fun Float.test6fr(x: Any): Boolean { + return when { + x is Double -> .equals(other = x /*as Double */) + else -> false + } +} diff --git a/compiler/testData/ir/irText/expressions/floatingPointComparisons/nullableAnyAsIntToDouble.fir.kt.txt b/compiler/testData/ir/irText/expressions/floatingPointComparisons/nullableAnyAsIntToDouble.fir.kt.txt new file mode 100644 index 00000000000..88e971888fe --- /dev/null +++ b/compiler/testData/ir/irText/expressions/floatingPointComparisons/nullableAnyAsIntToDouble.fir.kt.txt @@ -0,0 +1,6 @@ +fun test(x: Any?, y: Double): Boolean { + return when { + x is Int -> less(arg0 = x /*as Int */.toDouble(), arg1 = y) + else -> false + } +} diff --git a/compiler/testData/ir/irText/expressions/floatingPointComparisons/nullableFloatingPointEqeq.fir.kt.txt b/compiler/testData/ir/irText/expressions/floatingPointComparisons/nullableFloatingPointEqeq.fir.kt.txt new file mode 100644 index 00000000000..e9599a84b7d --- /dev/null +++ b/compiler/testData/ir/irText/expressions/floatingPointComparisons/nullableFloatingPointEqeq.fir.kt.txt @@ -0,0 +1,45 @@ +fun testDD(x: Double?, y: Double?): Boolean { + return ieee754equals(arg0 = x, arg1 = y) +} + +fun testDF(x: Double?, y: Any?): Boolean { + return when { + y is Float? -> ieee754equals(arg0 = x, arg1 = { // BLOCK + val tmp0_safe_receiver: Float? = y /*as Float? */ + when { + EQEQ(arg0 = tmp0_safe_receiver, arg1 = null) -> null + else -> tmp0_safe_receiver.toDouble() + } + }) + else -> false + } +} + +fun testDI(x: Double?, y: Any?): Boolean { + return when { + y is Int? -> ieee754equals(arg0 = x, arg1 = { // BLOCK + val tmp1_safe_receiver: Int? = y /*as Int? */ + when { + EQEQ(arg0 = tmp1_safe_receiver, arg1 = null) -> null + else -> tmp1_safe_receiver.toDouble() + } + }) + else -> false + } +} + +fun testDI2(x: Any?, y: Any?): Boolean { + return when { + when { + x is Int? -> y is Double + else -> false + } -> ieee754equals(arg0 = { // BLOCK + val tmp2_safe_receiver: Int? = x /*as Int? */ + when { + EQEQ(arg0 = tmp2_safe_receiver, arg1 = null) -> null + else -> tmp2_safe_receiver.toDouble() + } + }, arg1 = y /*as Double */) + else -> false + } +} diff --git a/compiler/testData/ir/irText/expressions/floatingPointComparisons/typeParameterWithPrimitiveNumericSupertype.fir.kt.txt b/compiler/testData/ir/irText/expressions/floatingPointComparisons/typeParameterWithPrimitiveNumericSupertype.fir.kt.txt new file mode 100644 index 00000000000..879bb4ba492 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/floatingPointComparisons/typeParameterWithPrimitiveNumericSupertype.fir.kt.txt @@ -0,0 +1,64 @@ +fun test0(x: Any, y: T): Boolean { + return when { + x is Int -> EQEQ(arg0 = x /*as Int */, arg1 = y) + else -> false + } +} + +fun test1(x: Any, y: T): Boolean { + return when { + x is Float -> ieee754equals(arg0 = x /*as Float */, arg1 = y) + else -> false + } +} + +fun test2(x: Any, y: T): Boolean { + return when { + x is Float -> ieee754equals(arg0 = x /*as Float */.toDouble(), arg1 = y) + else -> false + } +} + +fun test3(x: Any, y: T): Boolean { + return when { + x is Int -> ieee754equals(arg0 = x /*as Int */.toFloat(), arg1 = y) + else -> false + } +} + +fun test4(x: Any, y: T): Boolean { + return when { + x is Int -> ieee754equals(arg0 = x /*as Int */.toFloat(), arg1 = y) + else -> false + } +} + +fun test5(x: Any, y: R): Boolean { + return when { + x is Int -> ieee754equals(arg0 = x /*as Int */.toFloat(), arg1 = y) + else -> false + } +} + +fun test6(x: Any, y: T): Boolean { + return when { + x is Int -> EQEQ(arg0 = x /*as Int */, arg1 = y) + else -> false + } +} + +class F { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + fun testCapturedType(x: T, y: Any): Boolean { + return when { + y is Double -> ieee754equals(arg0 = x.toDouble(), arg1 = y /*as Double */) + else -> false + } + } + +} diff --git a/compiler/testData/ir/irText/expressions/floatingPointComparisons/whenByFloatingPoint.fir.kt.txt b/compiler/testData/ir/irText/expressions/floatingPointComparisons/whenByFloatingPoint.fir.kt.txt new file mode 100644 index 00000000000..da3ff7b2233 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/floatingPointComparisons/whenByFloatingPoint.fir.kt.txt @@ -0,0 +1,79 @@ +fun testSimple(x: Double): Int { + return { // BLOCK + val tmp0_subject: Double = x + when { + ieee754equals(arg0 = tmp0_subject, arg1 = 0.0D) -> 0 + else -> 1 + } + } +} + +fun testSmartCastInWhenSubject(x: Any): Int { + when { + x !is Double -> return -1 + } + return { // BLOCK + val tmp1_subject: Double = x /*as Double */ + when { + ieee754equals(arg0 = tmp1_subject, arg1 = 0.0D) -> 0 + else -> 1 + } + } +} + +fun testSmartCastInWhenCondition(x: Double, y: Any): Int { + when { + y !is Double -> return -1 + } + return { // BLOCK + val tmp2_subject: Double = x + when { + ieee754equals(arg0 = tmp2_subject, arg1 = y /*as Double */) -> 0 + else -> 1 + } + } +} + +fun testSmartCastInWhenConditionInBranch(x: Any): Int { + return { // BLOCK + val tmp3_subject: Any = x + when { + tmp3_subject !is Double -> -1 + EQEQ(arg0 = tmp3_subject, arg1 = 0.0D) -> 0 + else -> 1 + } + } +} + +fun testSmartCastToDifferentTypes(x: Any, y: Any): Int { + when { + x !is Double -> return -1 + } + when { + y !is Float -> return -1 + } + return { // BLOCK + val tmp4_subject: Double = x /*as Double */ + when { + ieee754equals(arg0 = tmp4_subject, arg1 = y /*as Float */.toDouble()) -> 0 + else -> 1 + } + } +} + +fun foo(x: Double): Double { + return x +} + +fun testWithPrematureExitInConditionSubexpression(x: Any): Int { + return { // BLOCK + val tmp5_subject: Any = x + when { + EQEQ(arg0 = tmp5_subject, arg1 = foo(x = when { + x !is Double -> return 42 + else -> x /*as Double */ + })) -> 0 + else -> 1 + } + } +} diff --git a/compiler/testData/ir/irText/expressions/for.fir.kt.txt b/compiler/testData/ir/irText/expressions/for.fir.kt.txt new file mode 100644 index 00000000000..d24d3e0c666 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/for.fir.kt.txt @@ -0,0 +1,40 @@ +fun testEmpty(ss: List) { + { // BLOCK + val : Iterator = ss.iterator() + while (.hasNext()) { // BLOCK + val s: String = .next() + } + } +} + +fun testIterable(ss: List) { + { // BLOCK + val : Iterator = ss.iterator() + while (.hasNext()) { // BLOCK + val s: String = .next() + println(message = s) + } + } +} + +fun testDestructuring(pp: List>) { + { // BLOCK + val : Iterator> = pp.iterator() + while (.hasNext()) { // BLOCK + val : Pair = .next() + val i: Int = .component1() + val s: String = .component2() + println(message = i) + println(message = s) + } + } +} + +fun testRange() { + { // BLOCK + val : IntIterator = 1.rangeTo(other = 10).iterator() + while (.hasNext()) { // BLOCK + val i: Int = .next() + } + } +} diff --git a/compiler/testData/ir/irText/expressions/forWithBreakContinue.fir.kt.txt b/compiler/testData/ir/irText/expressions/forWithBreakContinue.fir.kt.txt new file mode 100644 index 00000000000..2a96bfab610 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/forWithBreakContinue.fir.kt.txt @@ -0,0 +1,57 @@ +fun testForBreak1(ss: List) { + { // BLOCK + val : Iterator = ss.iterator() + while (.hasNext()) { // BLOCK + val s: String = .next() + break + } + } +} + +fun testForBreak2(ss: List) { + { // BLOCK + val : Iterator = ss.iterator() + OUTER@ while (.hasNext()) { // BLOCK + val s1: String = .next() + { // BLOCK + val : Iterator = ss.iterator() + INNER@ while (.hasNext()) { // BLOCK + val s2: String = .next() + break@OUTER + break@INNER + break@INNER + } + } + break@OUTER + } + } +} + +fun testForContinue1(ss: List) { + { // BLOCK + val : Iterator = ss.iterator() + while (.hasNext()) { // BLOCK + val s: String = .next() + continue + } + } +} + +fun testForContinue2(ss: List) { + { // BLOCK + val : Iterator = ss.iterator() + OUTER@ while (.hasNext()) { // BLOCK + val s1: String = .next() + { // BLOCK + val : Iterator = ss.iterator() + INNER@ while (.hasNext()) { // BLOCK + val s2: String = .next() + continue@OUTER + continue@INNER + continue@INNER + } + } + continue@OUTER + } + } +} diff --git a/compiler/testData/ir/irText/expressions/forWithImplicitReceivers.fir.kt.txt b/compiler/testData/ir/irText/expressions/forWithImplicitReceivers.fir.kt.txt new file mode 100644 index 00000000000..713711ed6f5 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/forWithImplicitReceivers.fir.kt.txt @@ -0,0 +1,51 @@ +object FiveTimes { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +class IntCell { + constructor(value: Int) /* primary */ { + super/*Any*/() + /* () */ + + } + + var value: Int + field = value + get + set + +} + +interface IReceiver { + operator fun FiveTimes.iterator(): IntCell { + return IntCell(value = 5) + } + + operator fun IntCell.hasNext(): Boolean { + return greater(arg0 = .(), arg1 = 0) + } + + operator fun IntCell.next(): Int { + return { // BLOCK + val : Int = .() + .( = .dec()) + + } + } + +} + +fun IReceiver.test() { + { // BLOCK + val : IntCell = (, FiveTimes).iterator() + while ((, ).hasNext()) { // BLOCK + val i: Int = (, ).next() + println(message = i) + } + } +} diff --git a/compiler/testData/ir/irText/expressions/funInterface/partialSam.fir.kt.txt b/compiler/testData/ir/irText/expressions/funInterface/partialSam.fir.kt.txt new file mode 100644 index 00000000000..cd1a19710b7 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/funInterface/partialSam.fir.kt.txt @@ -0,0 +1,66 @@ +fun interface Fn { + abstract fun run(s: String, i: Int, t: T): R + +} + +class J { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + fun runConversion(f1: Fn, f2: Fn): Int { + return f1.run(s = "Bar", i = 1, t = f2.run(s = "Foo", i = 42, t = 239)) + } + +} + +val fsi: Fn + field = { // BLOCK + local class : Fn { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + override fun run(s: String, i: Int, t: String): Int { + return 1 + } + + } + + () + } + get + +val fis: Fn + field = { // BLOCK + local class : Fn { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + override fun run(s: String, i: Int, t: Int): String { + return "" + } + + } + + () + } + get + +fun test(j: J) { + j.runConversion(f1 = (), f2 = local fun (s: String, i: Int, ti: Int): String { + return "" + } + /*-> Fn */) /*~> Unit */ + j.runConversion(f1 = local fun (s: String, i: Int, ts: String): Int { + return 1 + } + /*-> Fn */, f2 = ()) /*~> Unit */ +} diff --git a/compiler/testData/ir/irText/expressions/funInterface/samConversionInVarargs.fir.kt.txt b/compiler/testData/ir/irText/expressions/funInterface/samConversionInVarargs.fir.kt.txt new file mode 100644 index 00000000000..d37014897d3 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/funInterface/samConversionInVarargs.fir.kt.txt @@ -0,0 +1,38 @@ +fun interface IFoo { + abstract fun foo(i: Int) + +} + +fun useVararg(vararg foos: IFoo) { +} + +fun testLambda() { + useVararg(foos = [local fun (it: Int) { + return Unit + } + /*-> IFoo */]) +} + +fun testSeveralLambdas() { + useVararg(foos = [local fun (it: Int) { + return Unit + } + /*-> IFoo */, local fun (it: Int) { + return Unit + } + /*-> IFoo */, local fun (it: Int) { + return Unit + } + /*-> IFoo */]) +} + +fun withVarargOfInt(vararg xs: Int): String { + return "" +} + +fun testAdaptedCR() { + useVararg(foos = [local fun withVarargOfInt(p0: Int) { + withVarargOfInt(xs = [p0]) + } + /*-> IFoo */]) +} diff --git a/compiler/testData/ir/irText/expressions/funInterface/samConversionInVarargsMixed.fir.kt.txt b/compiler/testData/ir/irText/expressions/funInterface/samConversionInVarargsMixed.fir.kt.txt new file mode 100644 index 00000000000..4e96e4a9a78 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/funInterface/samConversionInVarargsMixed.fir.kt.txt @@ -0,0 +1,16 @@ +fun interface MyRunnable { + abstract fun run() + +} + +fun test(a: Any, r: MyRunnable) { + when { + a is MyRunnable -> foo(rs = [local fun () { + return Unit + } + /*-> MyRunnable */, r, a /*as MyRunnable */]) + } +} + +fun foo(vararg rs: MyRunnable) { +} diff --git a/compiler/testData/ir/irText/expressions/funInterface/samConversionOnCallableReference.fir.kt.txt b/compiler/testData/ir/irText/expressions/funInterface/samConversionOnCallableReference.fir.kt.txt new file mode 100644 index 00000000000..38484efcba1 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/funInterface/samConversionOnCallableReference.fir.kt.txt @@ -0,0 +1,36 @@ +fun interface KRunnable { + abstract fun run() + +} + +fun foo0() { +} + +fun foo1(vararg xs: Int): Int { + return 1 +} + +fun use(r: KRunnable) { +} + +fun testSamConstructor(): KRunnable { + return ::foo0 /*-> KRunnable */ +} + +fun testSamCosntructorOnAdapted(): KRunnable { + return local fun foo1() { + foo1() + } + /*-> KRunnable */ +} + +fun testSamConversion() { + use(r = ::foo0 /*-> KRunnable */) +} + +fun testSamConversionOnAdapted() { + use(r = local fun foo1() { + foo1() + } + /*-> KRunnable */) +} diff --git a/compiler/testData/ir/irText/expressions/funInterface/samConversionsWithSmartCasts.fir.kt.txt b/compiler/testData/ir/irText/expressions/funInterface/samConversionsWithSmartCasts.fir.kt.txt new file mode 100644 index 00000000000..b769f5e4a61 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/funInterface/samConversionsWithSmartCasts.fir.kt.txt @@ -0,0 +1,69 @@ +fun interface KRunnable { + abstract fun run() + +} + +fun id(x: T): T { + return x +} + +fun run1(r: KRunnable) { +} + +fun run2(r1: KRunnable, r2: KRunnable) { +} + +fun test0(a: T) where T : KRunnable, T : Function0 { + run1(r = a) +} + +fun test1(a: Function0) { + when { + a is KRunnable -> run1(r = a /*as KRunnable */) + } +} + +fun test2(a: KRunnable) { + a as Function0 /*~> Unit */ + run1(r = a /*as Function0 */) +} + +fun test3(a: Function0) { + when { + a is KRunnable -> run2(r1 = a /*as KRunnable */, r2 = a /*as KRunnable */) + } +} + +fun test4(a: Function0, b: Function0) { + when { + a is KRunnable -> run2(r1 = a /*as KRunnable */, r2 = b /*-> KRunnable */) + } +} + +fun test5(a: Any) { + when { + a is KRunnable -> run1(r = a /*as KRunnable */) + } +} + +fun test5x(a: Any) { + when { + a is KRunnable -> { // BLOCK + a /*as KRunnable */ as Function0 /*~> Unit */ + run1(r = a /*as KRunnable */) + } + } +} + +fun test6(a: Any) { + a as Function0 /*~> Unit */ + run1(r = a /*as Function0 */ /*-> KRunnable */) +} + +fun test8(a: Function0) { + run1(r = id>(x = a) /*-> KRunnable */) +} + +fun test9() { + run1(r = ::test9 /*-> KRunnable */) +} diff --git a/compiler/testData/ir/irText/expressions/genericConstructorCallWithTypeArguments.fir.kt.txt b/compiler/testData/ir/irText/expressions/genericConstructorCallWithTypeArguments.fir.kt.txt new file mode 100644 index 00000000000..a313764ee48 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/genericConstructorCallWithTypeArguments.fir.kt.txt @@ -0,0 +1,23 @@ +fun testSimple(): Box { + return Box(value = 6L) +} + +inline fun testArray(n: Int, crossinline block: Function0): Array { + return Array(size = n, init = local fun (it: Int): T { + return block.invoke() + } +) +} + +class Box { + constructor(value: T) /* primary */ { + super/*Any*/() + /* () */ + + } + + val value: T + field = value + get + +} diff --git a/compiler/testData/ir/irText/expressions/genericPropertyRef.fir.kt.txt b/compiler/testData/ir/irText/expressions/genericPropertyRef.fir.kt.txt new file mode 100644 index 00000000000..92837ccb850 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/genericPropertyRef.fir.kt.txt @@ -0,0 +1,70 @@ +class Value { + constructor(value: T = null as T, text: String? = null) /* primary */ { + super/*Any*/() + /* () */ + + } + + var value: T + field = value + get + set + + var text: String? + field = text + get + set + +} + +val Value.additionalText: Int /* by */ + field = DVal(kmember = Value::text) + get(): Int { + return #additionalText$delegate.getValue(t = , p = ::additionalText/*()*/) + } + +val Value.additionalValue: Int /* by */ + field = DVal(kmember = Value::value) + get(): Int { + return #additionalValue$delegate.getValue(t = , p = ::additionalValue/*()*/) + } + +class DVal { + constructor(kmember: Any) /* primary */ { + super/*Any*/() + /* () */ + + } + + val kmember: Any + field = kmember + get + + operator fun getValue(t: Any?, p: Any): Int { + return 42 + } + +} + +var recivier: Any? + field = "fail" + get + set + +var value2: Any? + field = "fail2" + get + set + +var T.bar: T + get(): T { + return + } + set(value: T) { + ( = ) + ( = value) + } + +val barRef: KMutableProperty1 + field = ::bar/*()*/ + get diff --git a/compiler/testData/ir/irText/expressions/ifElseIf.fir.kt.txt b/compiler/testData/ir/irText/expressions/ifElseIf.fir.kt.txt new file mode 100644 index 00000000000..dc7d00ebb86 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/ifElseIf.fir.kt.txt @@ -0,0 +1,39 @@ +fun test(i: Int): Int { + return when { + greater(arg0 = i, arg1 = 0) -> 1 + else -> when { + less(arg0 = i, arg1 = 0) -> -1 + else -> 0 + } + } +} + +fun testEmptyBranches1(flag: Boolean) { + when { + flag -> { // BLOCK + } + else -> true + } /*~> Unit */ + when { + flag -> true + } +} + +fun testEmptyBranches2(flag: Boolean) { + when { + flag -> { // BLOCK + } + else -> true + } /*~> Unit */ + when { + flag -> true + } +} + +fun testEmptyBranches3(flag: Boolean) { + when { + flag -> { // BLOCK + } + else -> true + } /*~> Unit */ +} diff --git a/compiler/testData/ir/irText/expressions/implicitCastInReturnFromConstructor.fir.kt.txt b/compiler/testData/ir/irText/expressions/implicitCastInReturnFromConstructor.fir.kt.txt new file mode 100644 index 00000000000..23546a6f1f1 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/implicitCastInReturnFromConstructor.fir.kt.txt @@ -0,0 +1,15 @@ +class C { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + constructor(x: Any?) { + this/*C*/() + when { + x is Unit -> return x /*as Unit */ + } + } + +} diff --git a/compiler/testData/ir/irText/expressions/implicitCastOnPlatformType.fir.kt.txt b/compiler/testData/ir/irText/expressions/implicitCastOnPlatformType.fir.kt.txt new file mode 100644 index 00000000000..174fb1c518b --- /dev/null +++ b/compiler/testData/ir/irText/expressions/implicitCastOnPlatformType.fir.kt.txt @@ -0,0 +1,3 @@ +fun test(): String { + return getProperty(p0 = "test") /*!! String */ +} diff --git a/compiler/testData/ir/irText/expressions/implicitCastToNonNull.fir.kt.txt b/compiler/testData/ir/irText/expressions/implicitCastToNonNull.fir.kt.txt new file mode 100644 index 00000000000..f1ea7098be2 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/implicitCastToNonNull.fir.kt.txt @@ -0,0 +1,33 @@ +fun test1(x: String?): Int { + return when { + EQEQ(arg0 = x, arg1 = null) -> 0 + else -> x /*as String */.() + } +} + +fun test2(x: T): Int { + return when { + EQEQ(arg0 = x, arg1 = null) -> 0 + else -> x.() + } +} + +inline fun test3(x: Any): Int { + return when { + x !is T -> 0 + else -> x /*as T */.() + } +} + +inline fun test4(x: Any?): Int { + return when { + x !is T -> 0 + else -> x /*as T */.() + } +} + +fun test5(x: T, fn: Function1) { + when { + EQEQ(arg0 = x, arg1 = null).not() -> fn.invoke(p1 = x) + } +} diff --git a/compiler/testData/ir/irText/expressions/implicitCastToTypeParameter.fir.kt.txt b/compiler/testData/ir/irText/expressions/implicitCastToTypeParameter.fir.kt.txt new file mode 100644 index 00000000000..8afcaf303af --- /dev/null +++ b/compiler/testData/ir/irText/expressions/implicitCastToTypeParameter.fir.kt.txt @@ -0,0 +1,35 @@ +inline fun Any.test1(): T? { + return when { + is T -> + else -> null + } +} + +interface Foo { + +} + +val Foo.asT: T? + inline get(): T? { + return when { + is T -> /*as T */ + else -> null + } + } + +class Bar { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + fun test(arg: Any) { + arg as T /*~> Unit */ + .useT(t = arg /*as T */) + } + + fun useT(t: T) { + } + +} diff --git a/compiler/testData/ir/irText/expressions/implicitNotNullInDestructuringAssignment.fir.kt.txt b/compiler/testData/ir/irText/expressions/implicitNotNullInDestructuringAssignment.fir.kt.txt new file mode 100644 index 00000000000..e4947d8c8b7 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/implicitNotNullInDestructuringAssignment.fir.kt.txt @@ -0,0 +1,13 @@ +operator fun J?.component1(): Int { + return 1 +} + +private operator fun J.component2(): Int { + return 2 +} + +fun test() { + val : J? = j() + val a: Int = .component1() + val b: Int = .component2() +} diff --git a/compiler/testData/ir/irText/expressions/in.fir.kt.txt b/compiler/testData/ir/irText/expressions/in.fir.kt.txt new file mode 100644 index 00000000000..e582eb28918 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/in.fir.kt.txt @@ -0,0 +1,15 @@ +fun test1(a: Any, x: Collection): Boolean { + return x.contains(element = a) +} + +fun test2(a: Any, x: Collection): Boolean { + return x.contains(element = a).not() +} + +fun test3(a: T, x: Collection): Boolean { + return x.contains(element = a) +} + +fun test4(a: T, x: Collection): Boolean { + return x.contains(element = a).not() +} diff --git a/compiler/testData/ir/irText/expressions/incrementDecrement.fir.kt.txt b/compiler/testData/ir/irText/expressions/incrementDecrement.fir.kt.txt new file mode 100644 index 00000000000..ae5e74d0547 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/incrementDecrement.fir.kt.txt @@ -0,0 +1,91 @@ +var p: Int + field = 0 + get + set + +val arr: IntArray + field = intArrayOf(elements = [1, 2, 3]) + get + +fun testVarPrefix() { + var x: Int = 0 + val x1: Int = { // BLOCK + x = x.inc() + x + } + val x2: Int = { // BLOCK + x = x.dec() + x + } +} + +fun testVarPostfix() { + var x: Int = 0 + val x1: Int = { // BLOCK + val : Int = x + x = .inc() + + } + val x2: Int = { // BLOCK + val : Int = x + x = .dec() + + } +} + +fun testPropPrefix() { + val p1: Int = { // BLOCK + ( = ().inc()) + () + } + val p2: Int = { // BLOCK + ( = ().dec()) + () + } +} + +fun testPropPostfix() { + val p1: Int = { // BLOCK + val : Int = () + ( = .inc()) + + } + val p2: Int = { // BLOCK + ( = ().dec()) + () + } +} + +fun testArrayPrefix() { + val a1: Int = { // BLOCK + val : IntArray = () + val : Int = 0 + val : Int = .get(index = ).inc() + .set(index = , value = ) + + } + val a2: Int = { // BLOCK + val : IntArray = () + val : Int = 0 + val : Int = .get(index = ).dec() + .set(index = , value = ) + + } +} + +fun testArrayPostfix() { + val a1: Int = { // BLOCK + val : IntArray = () + val : Int = 0 + val : Int = .get(index = ) + .set(index = , value = .inc()) + + } + val a2: Int = { // BLOCK + val : IntArray = () + val : Int = 0 + val : Int = .get(index = ) + .set(index = , value = .dec()) + + } +} diff --git a/compiler/testData/ir/irText/expressions/javaSyntheticGenericPropertyAccess.fir.kt.txt b/compiler/testData/ir/irText/expressions/javaSyntheticGenericPropertyAccess.fir.kt.txt new file mode 100644 index 00000000000..bc01ad1333c --- /dev/null +++ b/compiler/testData/ir/irText/expressions/javaSyntheticGenericPropertyAccess.fir.kt.txt @@ -0,0 +1,9 @@ +fun test(j: J) { + j.getFoo() /*~> Unit */ + j.setFoo(x = 1) + val : J = j + val : Int = .getFoo() + .setFoo(x = .inc()) + /*~> Unit */ + j.setFoo(x = j.getFoo().plus(other = 1)) +} diff --git a/compiler/testData/ir/irText/expressions/javaSyntheticPropertyAccess.fir.kt.txt b/compiler/testData/ir/irText/expressions/javaSyntheticPropertyAccess.fir.kt.txt new file mode 100644 index 00000000000..fce2040c4c7 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/javaSyntheticPropertyAccess.fir.kt.txt @@ -0,0 +1,9 @@ +fun test(j: J) { + j.getFoo() /*~> Unit */ + j.setFoo(x = 1) + val : J = j + val : Int = .getFoo() + .setFoo(x = .inc()) + /*~> Unit */ + j.setFoo(x = j.getFoo().plus(other = 1)) +} diff --git a/compiler/testData/ir/irText/expressions/jvmFieldWithIntersectionTypes.fir.kt.txt b/compiler/testData/ir/irText/expressions/jvmFieldWithIntersectionTypes.fir.kt.txt new file mode 100644 index 00000000000..19a6f58cbab --- /dev/null +++ b/compiler/testData/ir/irText/expressions/jvmFieldWithIntersectionTypes.fir.kt.txt @@ -0,0 +1,67 @@ +interface IFoo { + +} + +class Derived1 : JFieldOwner, IFoo { + constructor() /* primary */ { + super/*JFieldOwner*/() + /* () */ + + } + +} + +class Derived2 : JFieldOwner, IFoo { + constructor() /* primary */ { + super/*JFieldOwner*/() + /* () */ + + } + +} + +open class Mid : JFieldOwner { + constructor() /* primary */ { + super/*JFieldOwner*/() + /* () */ + + } + +} + +class DerivedThroughMid1 : Mid, IFoo { + constructor() /* primary */ { + super/*Mid*/() + /* () */ + + } + +} + +class DerivedThroughMid2 : Mid, IFoo { + constructor() /* primary */ { + super/*Mid*/() + /* () */ + + } + +} + +fun test(b: Boolean) { + val d1: Derived1 = Derived1() + val d2: Derived2 = Derived2() + val k: JFieldOwner = when { + b -> d1 + else -> d2 + } + k.#f = 42 + k.#f /*~> Unit */ + val md1: DerivedThroughMid1 = DerivedThroughMid1() + val md2: DerivedThroughMid2 = DerivedThroughMid2() + val mk: Mid = when { + b -> md1 + else -> md2 + } + mk.#f = 44 + mk.#f /*~> Unit */ +} diff --git a/compiler/testData/ir/irText/expressions/jvmInstanceFieldReference.fir.kt.txt b/compiler/testData/ir/irText/expressions/jvmInstanceFieldReference.fir.kt.txt new file mode 100644 index 00000000000..242c7bc48aa --- /dev/null +++ b/compiler/testData/ir/irText/expressions/jvmInstanceFieldReference.fir.kt.txt @@ -0,0 +1,20 @@ +class Derived : Base { + constructor() /* primary */ { + super/*Base*/() + /* () */ + + } + + init { + .#value = 0 + } + + fun getValue(): Int { + return .#value + } + + fun setValue(value: Int) { + .#value = value + } + +} diff --git a/compiler/testData/ir/irText/expressions/jvmStaticFieldReference.fir.kt.txt b/compiler/testData/ir/irText/expressions/jvmStaticFieldReference.fir.kt.txt new file mode 100644 index 00000000000..30bafebac69 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/jvmStaticFieldReference.fir.kt.txt @@ -0,0 +1,34 @@ +fun testFun() { + #out.println(p0 = "testFun") +} + +var testProp: Any + get(): Any { + #out.println(p0 = "testProp/get") + return 42 + } + set(value: Any) { + #out.println(p0 = "testProp/set") + } + +class TestClass { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + val test: Int + field = when { + else -> { // BLOCK + #out.println(p0 = "TestClass/test") + 42 + } + } + get + + init { + #out.println(p0 = "TestClass/init") + } + +} diff --git a/compiler/testData/ir/irText/expressions/kt16904.fir.kt.txt b/compiler/testData/ir/irText/expressions/kt16904.fir.kt.txt new file mode 100644 index 00000000000..8505dcfe34f --- /dev/null +++ b/compiler/testData/ir/irText/expressions/kt16904.fir.kt.txt @@ -0,0 +1,53 @@ +abstract class A { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + val x: B + field = B() + get + + var y: Int + field = 0 + get + set + +} + +class B { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + operator fun plusAssign(x: Int) { + } + +} + +class Test1 : A { + constructor() { + super/*A*/() + /* () */ + + .().plusAssign(x = 42) + .( = .().plus(other = 42)) + } + +} + +class Test2 : J { + constructor() /* primary */ { + super/*J*/() + /* () */ + + } + + init { + .#field = 42 + } + +} diff --git a/compiler/testData/ir/irText/expressions/kt16905.fir.kt.txt b/compiler/testData/ir/irText/expressions/kt16905.fir.kt.txt new file mode 100644 index 00000000000..a183fef06e5 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/kt16905.fir.kt.txt @@ -0,0 +1,40 @@ +typealias OI = Inner +class Outer { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + open inner class Inner { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + } + + inner class InnerDerived0 : Inner { + constructor() /* primary */ { + .super/*Inner*/() + /* () */ + + } + + } + + inner class InnerDerived1 : Inner { + constructor() /* primary */ { + .super/*Inner*/() + /* () */ + + } + + } + +} + +fun test(): Inner { + return Outer().Inner() +} diff --git a/compiler/testData/ir/irText/expressions/kt23030.fir.kt.txt b/compiler/testData/ir/irText/expressions/kt23030.fir.kt.txt new file mode 100644 index 00000000000..72c686100ce --- /dev/null +++ b/compiler/testData/ir/irText/expressions/kt23030.fir.kt.txt @@ -0,0 +1,54 @@ +operator fun Int.compareTo(c: Char): Int { + return 0 +} + +fun testOverloadedCompareToCall(x: Int, y: Char): Boolean { + return less(arg0 = x.compareTo(c = y), arg1 = 0) +} + +fun testOverloadedCompareToCallWithSmartCast(x: Any, y: Any): Boolean { + return when { + when { + x is Int -> y is Char + else -> false + } -> less(arg0 = x /*as Int */.compareTo(c = y /*as Char */), arg1 = 0) + else -> false + } +} + +fun testEqualsWithSmartCast(x: Any, y: Any): Boolean { + return when { + when { + x is Int -> y is Char + else -> false + } -> EQEQ(arg0 = x /*as Int */, arg1 = y /*as Char */) + else -> false + } +} + +class C { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + operator fun Int.compareTo(c: Char): Int { + return 0 + } + + fun testMemberExtensionCompareToCall(x: Int, y: Char): Boolean { + return less(arg0 = (, x).compareTo(c = y), arg1 = 0) + } + + fun testMemberExtensionCompareToCallWithSmartCast(x: Any, y: Any): Boolean { + return when { + when { + x is Int -> y is Char + else -> false + } -> less(arg0 = (, x /*as Int */).compareTo(c = y /*as Char */), arg1 = 0) + else -> false + } + } + +} diff --git a/compiler/testData/ir/irText/expressions/kt24804.fir.kt.txt b/compiler/testData/ir/irText/expressions/kt24804.fir.kt.txt new file mode 100644 index 00000000000..509317c8937 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/kt24804.fir.kt.txt @@ -0,0 +1,24 @@ +inline fun foo(): Boolean { + return false +} + +fun run(x: Boolean, y: Boolean): String { + var z: Int = 10 + l2@ do// COMPOSITE { + z = z.plus(other = 1) + when { + greater(arg0 = z, arg1 = 100) -> return "NOT_OK" + } + when { + x -> error("") /* ERROR EXPRESSION */ + } + when { + y -> continue@l2 + } + // } while (foo()) + return "OK" +} + +fun box(): String { + return run(x = true, y = true) +} diff --git a/compiler/testData/ir/irText/expressions/kt27933.fir.kt.txt b/compiler/testData/ir/irText/expressions/kt27933.fir.kt.txt new file mode 100644 index 00000000000..d1e3e1b00d5 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/kt27933.fir.kt.txt @@ -0,0 +1,16 @@ +fun box(): String { + var r: String = "" + when { + EQEQ(arg0 = r, arg1 = "").not() -> { // BLOCK + } + else -> { // BLOCK + r = r.plus(other = "O") + } + } + when { + EQEQ(arg0 = r, arg1 = "O") -> { // BLOCK + r = r.plus(other = "K") + } + } + return r +} diff --git a/compiler/testData/ir/irText/expressions/kt28006.fir.kt.txt b/compiler/testData/ir/irText/expressions/kt28006.fir.kt.txt new file mode 100644 index 00000000000..930972b7920 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/kt28006.fir.kt.txt @@ -0,0 +1,36 @@ +val test1: String + field = "\uD83E\uDD17" + get + +val test2: String + field = "\uD83E\uDD17\uD83E\uDD17" + get + +const val testConst1: String + field = "\uD83E\uDD17" + get + +const val testConst2: String + field = "\uD83E\uDD17\uD83E\uDD17" + get + +const val testConst3: String + field = "\uD83E\uDD17\uD83E\uDD17\uD83E\uDD17" + get + +const val testConst4: String + field = "\uD83E\uDD17\uD83E\uDD17\uD83E\uDD17\uD83E\uDD17" + get + +fun test1(x: Int): String { + return "\uD83E" + "\uDD17" + x.toString() +} + +fun test2(x: Int): String { + return x.toString() + "\uD83E" + "\uDD17" +} + +fun test3(x: Int): String { + return x.toString() + "\uD83E" + "\uDD17" + x.toString() +} + diff --git a/compiler/testData/ir/irText/expressions/kt28456.fir.kt.txt b/compiler/testData/ir/irText/expressions/kt28456.fir.kt.txt new file mode 100644 index 00000000000..bea687736e0 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/kt28456.fir.kt.txt @@ -0,0 +1,39 @@ +class A { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +operator fun A.get(vararg xs: Int): Int { + return 0 +} + +operator fun A.set(i: Int, j: Int, v: Int) { +} + +fun testSimpleAssignment(a: A) { + a.set(i = 1, j = 2, v = 0) +} + +fun testPostfixIncrement(a: A): Int { + return { // BLOCK + val : A = a + val : Int = 1 + val : Int = 2 + val : Int = .get(xs = [, ]) + .set(i = , j = , v = .inc()) + + } +} + +fun testCompoundAssignment(a: A) { + { // BLOCK + val <>: A = a + val <>: Int = 1 + val <>: Int = 2 + <>.set(i = <>, j = <>, v = <>.get(xs = [<>, <>]).plus(other = 10)) + } +} diff --git a/compiler/testData/ir/irText/expressions/kt28456a.fir.kt.txt b/compiler/testData/ir/irText/expressions/kt28456a.fir.kt.txt new file mode 100644 index 00000000000..e336daf21c7 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/kt28456a.fir.kt.txt @@ -0,0 +1,15 @@ +class A { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +operator fun A.set(vararg i: Int, v: Int) { +} + +fun testSimpleAssignment(a: A) { + a.set(i = [1, 2, 3], v = 0) +} diff --git a/compiler/testData/ir/irText/expressions/kt28456b.fir.kt.txt b/compiler/testData/ir/irText/expressions/kt28456b.fir.kt.txt new file mode 100644 index 00000000000..4261eb2d798 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/kt28456b.fir.kt.txt @@ -0,0 +1,37 @@ +class A { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +operator fun A.get(i: Int, a: Int = 1, b: Int = 2, c: Int = 3, d: Int = 4): Int { + return 0 +} + +operator fun A.set(i: Int, j: Int = 42, v: Int) { +} + +fun testSimpleAssignment(a: A) { + a.set(i = 1, v = 0) +} + +fun testPostfixIncrement(a: A): Int { + return { // BLOCK + val : A = a + val : Int = 1 + val : Int = .get(i = ) + .set(i = , v = .inc()) + + } +} + +fun testCompoundAssignment(a: A) { + { // BLOCK + val <>: A = a + val <>: Int = 1 + <>.set(i = <>, v = <>.get(i = <>).plus(other = 10)) + } +} diff --git a/compiler/testData/ir/irText/expressions/kt30020.fir.kt.txt b/compiler/testData/ir/irText/expressions/kt30020.fir.kt.txt new file mode 100644 index 00000000000..fd3b77edb9d --- /dev/null +++ b/compiler/testData/ir/irText/expressions/kt30020.fir.kt.txt @@ -0,0 +1,58 @@ +interface X { + abstract val xs: MutableList + abstract get + + abstract fun f(): MutableList + +} + +fun test(x: X, nx: X?) { + x.().plusAssign(element = 1) + x.f().plusAssign(element = 2) + x.() as MutableList.plusAssign(element = 3) + x.f() as MutableList.plusAssign(element = 4) + CHECK_NOT_NULL>(arg0 = { // BLOCK + val tmp0_safe_receiver: X? = nx + when { + EQEQ(arg0 = tmp0_safe_receiver, arg1 = null) -> null + else -> tmp0_safe_receiver.() + } + }).plusAssign(element = 5) + CHECK_NOT_NULL>(arg0 = { // BLOCK + val tmp1_safe_receiver: X? = nx + when { + EQEQ(arg0 = tmp1_safe_receiver, arg1 = null) -> null + else -> tmp1_safe_receiver.f() + } + }).plusAssign(element = 6) +} + +fun MutableList.testExtensionReceiver() { + .plusAssign(element = 100) +} + +abstract class AML : MutableList { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + fun testExplicitThis() { + .plusAssign(element = 200) + } + + inner class Inner { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + fun testOuterThis() { + .plusAssign(element = 300) + } + + } + +} diff --git a/compiler/testData/ir/irText/expressions/kt30796.fir.kt.txt b/compiler/testData/ir/irText/expressions/kt30796.fir.kt.txt new file mode 100644 index 00000000000..f45cf10a60b --- /dev/null +++ b/compiler/testData/ir/irText/expressions/kt30796.fir.kt.txt @@ -0,0 +1,85 @@ +fun magic(): T { + return throw Exception() +} + +fun test(value: T, value2: T) { + val x1: Any = { // BLOCK + val : T = value + when { + EQEQ(arg0 = , arg1 = null) -> 42 + else -> + } + } + val x2: Any = { // BLOCK + val : T = value + when { + EQEQ(arg0 = , arg1 = null) -> { // BLOCK + val : T = value2 + when { + EQEQ(arg0 = , arg1 = null) -> 42 + else -> + } + } + else -> + } + } + val x3: Any = { // BLOCK + val : T = { // BLOCK + val : T = value + when { + EQEQ(arg0 = , arg1 = null) -> value2 + else -> + } + } + when { + EQEQ(arg0 = , arg1 = null) -> 42 + else -> + } + } + val x4: Any = { // BLOCK + val : T = { // BLOCK + val : T = value + when { + EQEQ(arg0 = , arg1 = null) -> value2 + else -> + } + } + when { + EQEQ(arg0 = , arg1 = null) -> 42 + else -> + } + } + val x5: Any = { // BLOCK + val : Int? = magic() + when { + EQEQ(arg0 = , arg1 = null) -> 42 + else -> /*as Int */ + } + } + val x6: Any = { // BLOCK + val : T = { // BLOCK + val : T = value + when { + EQEQ(arg0 = , arg1 = null) -> magic() + else -> + } + } + when { + EQEQ(arg0 = , arg1 = null) -> 42 + else -> + } + } + val x7: Any = { // BLOCK + val : T? = { // BLOCK + val : T? = magic() + when { + EQEQ(arg0 = , arg1 = null) -> value + else -> /*as T */ + } + } + when { + EQEQ(arg0 = , arg1 = null) -> 42 + else -> /*as T */ + } + } +} diff --git a/compiler/testData/ir/irText/expressions/kt35730.fir.kt.txt b/compiler/testData/ir/irText/expressions/kt35730.fir.kt.txt new file mode 100644 index 00000000000..44446d56be0 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/kt35730.fir.kt.txt @@ -0,0 +1,19 @@ +interface Base { + fun foo() { + } + +} + +object Derived : Base { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +fun test() { + Derived.foo() + Derived.foo() +} diff --git a/compiler/testData/ir/irText/expressions/kt36956.fir.kt.txt b/compiler/testData/ir/irText/expressions/kt36956.fir.kt.txt new file mode 100644 index 00000000000..d5b48c07d6c --- /dev/null +++ b/compiler/testData/ir/irText/expressions/kt36956.fir.kt.txt @@ -0,0 +1,33 @@ +class A { + constructor(value: T) /* primary */ { + super/*Any*/() + /* () */ + + } + + private val value: T + field = value + private get + + operator fun get(i: Int): T { + return .() + } + + operator fun set(i: Int, v: T) { + } + +} + +val aFloat: A + field = A(value = 0.0F) + get + +val aInt: Float + field = { // BLOCK + val : A = () + val : Int = 1 + val : Float = .get(i = ) + .set(i = , v = .dec()) + + } + get diff --git a/compiler/testData/ir/irText/expressions/kt36963.fir.kt.txt b/compiler/testData/ir/irText/expressions/kt36963.fir.kt.txt new file mode 100644 index 00000000000..1121fbdab3a --- /dev/null +++ b/compiler/testData/ir/irText/expressions/kt36963.fir.kt.txt @@ -0,0 +1,6 @@ +fun foo() { +} + +fun test(): KFunction0 { + return CHECK_NOT_NULL>(arg0 = ::foo) +} diff --git a/compiler/testData/ir/irText/expressions/kt37570.fir.kt.txt b/compiler/testData/ir/irText/expressions/kt37570.fir.kt.txt new file mode 100644 index 00000000000..76ba6c9c5c6 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/kt37570.fir.kt.txt @@ -0,0 +1,22 @@ +fun a(): String { + return "string" +} + +class A { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + val b: String + get + + init { + a().apply(block = local fun String.() { + .#b = + } +) /*~> Unit */ + } + +} diff --git a/compiler/testData/ir/irText/expressions/lambdaInCAO.fir.kt.txt b/compiler/testData/ir/irText/expressions/lambdaInCAO.fir.kt.txt new file mode 100644 index 00000000000..f6c877506fb --- /dev/null +++ b/compiler/testData/ir/irText/expressions/lambdaInCAO.fir.kt.txt @@ -0,0 +1,31 @@ +operator fun Any.plusAssign(lambda: Function0) { +} + +operator fun Any.get(index: Function0): Int { + return 42 +} + +operator fun Any.set(index: Function0, value: Int) { +} + +fun test1(a: Any) { + a.plusAssign(lambda = local fun () { + return Unit + } +) +} + +fun test2(a: Any) { + error("") /* ERROR CALL */ +} + +fun test3(a: Any) { + val : Any = a + val : Function0 = local fun () { + return Unit + } + + val : Int = .get(index = ) + .set(index = , value = .inc()) + /*~> Unit */ +} diff --git a/compiler/testData/ir/irText/expressions/literals.fir.kt.txt b/compiler/testData/ir/irText/expressions/literals.fir.kt.txt new file mode 100644 index 00000000000..253306edf33 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/literals.fir.kt.txt @@ -0,0 +1,67 @@ +val test1: Int + field = 1 + get + +val test2: Int + field = -1 + get + +val test3: Boolean + field = true + get + +val test4: Boolean + field = false + get + +val test5: String + field = "abc" + get + +val test6: Nothing? + field = null + get + +val test7: Long + field = 1L + get + +val test8: Long + field = 1L.unaryMinus() + get + +val test9: Double + field = 1.0D + get + +val test10: Double + field = 1.0D.unaryMinus() + get + +val test11: Float + field = 1.0F + get + +val test12: Float + field = 1.0F.unaryMinus() + get + +val test13: Char + field = 'a' + get + +val testB: Byte + field = 1B + get + +val testS: Short + field = 1S + get + +val testI: Int + field = 1 + get + +val testL: Long + field = 1L + get diff --git a/compiler/testData/ir/irText/expressions/multipleThisReferences.fir.kt.txt b/compiler/testData/ir/irText/expressions/multipleThisReferences.fir.kt.txt new file mode 100644 index 00000000000..64218022524 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/multipleThisReferences.fir.kt.txt @@ -0,0 +1,53 @@ +class Outer { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + open inner class Inner { + constructor(x: Int) /* primary */ { + super/*Any*/() + /* () */ + + } + + val x: Int + field = x + get + + } + +} + +class Host { + constructor(y: Int) /* primary */ { + super/*Any*/() + /* () */ + + } + + val y: Int + field = y + get + + fun Outer.test(): Inner { + return { // BLOCK + local class : Inner { + private constructor() /* primary */ { + .super/*Inner*/(x = 42) + /* () */ + + } + + val xx: Int + field = .().plus(other = .()) + get + + } + + () + } + } + +} diff --git a/compiler/testData/ir/irText/expressions/nullCheckOnGenericLambdaReturn.fir.kt.txt b/compiler/testData/ir/irText/expressions/nullCheckOnGenericLambdaReturn.fir.kt.txt new file mode 100644 index 00000000000..2aeea6b4888 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/nullCheckOnGenericLambdaReturn.fir.kt.txt @@ -0,0 +1,47 @@ +fun checkAny(fn: Function0): Any { + return fn.invoke() +} + +fun checkAnyN(fn: Function0): Any? { + return fn.invoke() +} + +fun checkT(fn: Function0): T { + return fn.invoke() +} + +fun checkTAny(fn: Function0): T { + return fn.invoke() +} + +fun id(x: T): T { + return x +} + +fun test1(): String? { + return checkT(fn = local fun (): String? { + return foo() + } +) +} + +fun test2(): String { + return checkT<@EnhancedNullability String>(fn = local fun (): @EnhancedNullability String { + return nnFoo() + } +) /*!! String */ +} + +fun test3(): String? { + return checkTAny(fn = local fun (): String? { + return foo() + } +) +} + +fun test4(): String { + return checkTAny<@EnhancedNullability String>(fn = local fun (): @EnhancedNullability String { + return nnFoo() + } +) /*!! String */ +} diff --git a/compiler/testData/ir/irText/expressions/nullCheckOnLambdaReturn.fir.kt.txt b/compiler/testData/ir/irText/expressions/nullCheckOnLambdaReturn.fir.kt.txt new file mode 100644 index 00000000000..a4286acb737 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/nullCheckOnLambdaReturn.fir.kt.txt @@ -0,0 +1,53 @@ +fun checkAny(fn: Function0): Any { + return fn.invoke() +} + +fun checkAnyN(fn: Function0): Any? { + return fn.invoke() +} + +fun id(x: T): T { + return x +} + +fun test1(): Any { + return checkAny(fn = local fun (): Any { + return foo() /*!! String */ + } +) +} + +val test2: Function0 + field = local fun (): String? { + return foo() + } + + get + +val test3: Function0 + field = local fun (): String? { + return foo() + } + as Function0 + get + +val test4: Function0 + field = id>(x = local fun (): String? { + return foo() + } +) + get + +fun test5(): Any? { + return checkAnyN(fn = local fun (): Any? { + return foo() + } +) +} + +fun test6(): Any? { + return checkAnyN(fn = local fun (): Any? { + return nnFoo() + } +) +} diff --git a/compiler/testData/ir/irText/expressions/objectAsCallable.fir.kt.txt b/compiler/testData/ir/irText/expressions/objectAsCallable.fir.kt.txt new file mode 100644 index 00000000000..11639efa551 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/objectAsCallable.fir.kt.txt @@ -0,0 +1,39 @@ +object A { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +enum class En : Enum { + private constructor() /* primary */ { + super/*Enum*/() + /* () */ + + } + + X = En() + + fun values(): Array /* Synthetic body for ENUM_VALUES */ + + fun valueOf(value: String): En /* Synthetic body for ENUM_VALUEOF */ + +} + +operator fun A.invoke(i: Int): Int { + return i +} + +operator fun En.invoke(i: Int): Int { + return i +} + +val test1: Int + field = A.invoke(i = 42) + get + +val test2: Int + field = En.X.invoke(i = 42) + get diff --git a/compiler/testData/ir/irText/expressions/objectByNameInsideObject.fir.kt.txt b/compiler/testData/ir/irText/expressions/objectByNameInsideObject.fir.kt.txt new file mode 100644 index 00000000000..48a45ae537a --- /dev/null +++ b/compiler/testData/ir/irText/expressions/objectByNameInsideObject.fir.kt.txt @@ -0,0 +1,32 @@ +open class Base { + constructor(f1: Function0) /* primary */ { + super/*Any*/() + /* () */ + + } + + val f1: Function0 + field = f1 + get + +} + +object Thing : Base { + private constructor() /* primary */ { + super/*Base*/(f1 = local fun (): Any { + return Thing + } +) + /* () */ + + } + + fun test1(): Thing { + return Thing + } + + fun test2(): Thing { + return + } + +} diff --git a/compiler/testData/ir/irText/expressions/objectReference.fir.kt.txt b/compiler/testData/ir/irText/expressions/objectReference.fir.kt.txt new file mode 100644 index 00000000000..a079149616d --- /dev/null +++ b/compiler/testData/ir/irText/expressions/objectReference.fir.kt.txt @@ -0,0 +1,92 @@ +object Z { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + var counter: Int + field = 0 + get + set + + fun foo() { + } + + fun bar() { + .( = 1) + .foo() + Z.( = 1) + Z.foo() + } + + class Nested { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + init { + Z.( = 1) + Z.foo() + Z.( = 1) + Z.foo() + } + + fun test() { + Z.( = 1) + Z.foo() + Z.( = 1) + Z.foo() + } + + } + + val aLambda: Function0 + field = local fun () { + .( = 1) + .foo() + Z.( = 1) + Z.foo() + } + + get + + val anObject: + field = { // BLOCK + local class { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + init { + Z.( = 1) + Z.foo() + Z.( = 1) + Z.foo() + } + + fun test() { + Z.( = 1) + Z.foo() + Z.( = 1) + Z.foo() + } + + } + + () + } + get + +} + +fun Z.test() { + .( = 1) + .foo() + Z.( = 1) + Z.foo() +} diff --git a/compiler/testData/ir/irText/expressions/objectReferenceInClosureInSuperConstructorCall.fir.kt.txt b/compiler/testData/ir/irText/expressions/objectReferenceInClosureInSuperConstructorCall.fir.kt.txt new file mode 100644 index 00000000000..b2e99c61e65 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/objectReferenceInClosureInSuperConstructorCall.fir.kt.txt @@ -0,0 +1,24 @@ +abstract class Base { + constructor(lambda: Function0) /* primary */ { + super/*Any*/() + /* () */ + + } + + val lambda: Function0 + field = lambda + get + +} + +object Test : Base { + private constructor() /* primary */ { + super/*Base*/(lambda = local fun (): Any { + return Test + } +) + /* () */ + + } + +} diff --git a/compiler/testData/ir/irText/expressions/objectReferenceInFieldInitializer.fir.kt.txt b/compiler/testData/ir/irText/expressions/objectReferenceInFieldInitializer.fir.kt.txt new file mode 100644 index 00000000000..c6c1947e457 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/objectReferenceInFieldInitializer.fir.kt.txt @@ -0,0 +1,20 @@ +object A { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + private val a: String + field = "$" + private get + + private val b: String + field = "1234" + .().toString() + private get + + private val c: Int + field = 10000 + private get + +} diff --git a/compiler/testData/ir/irText/expressions/primitivesImplicitConversions.fir.kt.txt b/compiler/testData/ir/irText/expressions/primitivesImplicitConversions.fir.kt.txt new file mode 100644 index 00000000000..0462a5c1fc5 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/primitivesImplicitConversions.fir.kt.txt @@ -0,0 +1,49 @@ +val test1: Long + field = 42L + get + +val test2: Short + field = 42S + get + +val test3: Byte + field = 42B + get + +val test4: Long + field = 42.unaryMinus() + get + +val test5: Short + field = 42.unaryMinus() + get + +val test6: Byte + field = 42.unaryMinus() + get + +fun test() { + val test1: Int? = 42 + val test2: Long = 42L + val test3: Long? = 42L + val test4: Long? = -1L + val test5: Long? = -1 + val test6: Short? = -1 + val test7: Byte? = -1 +} + +fun testImplicitArguments(x: Long = -1) { +} + +class TestImplicitArguments { + constructor(x: Long = -1) /* primary */ { + super/*Any*/() + /* () */ + + } + + val x: Long + field = x + get + +} diff --git a/compiler/testData/ir/irText/expressions/propertyReferences.fir.kt.txt b/compiler/testData/ir/irText/expressions/propertyReferences.fir.kt.txt new file mode 100644 index 00000000000..7e089c78274 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/propertyReferences.fir.kt.txt @@ -0,0 +1,131 @@ +object Delegate { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + operator fun getValue(thisRef: Any?, kProp: Any): Int { + return 1 + } + + operator fun setValue(thisRef: Any?, kProp: Any, value: Int) { + } + +} + +open class C { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + var varWithPrivateSet: Int + field = 1 + get + private set + + var varWithProtectedSet: Int + field = 1 + get + protected set + +} + +val valWithBackingField: Int + field = 1 + get + +val test_valWithBackingField: KProperty0 + field = ::valWithBackingField + get + +var varWithBackingField: Int + field = 1 + get + set + +val test_varWithBackingField: KMutableProperty0 + field = ::varWithBackingField + get + +var varWithBackingFieldAndAccessors: Int + field = 1 + get(): Int { + return #varWithBackingFieldAndAccessors + } + set(value: Int) { + #varWithBackingFieldAndAccessors = value + } + +val test_varWithBackingFieldAndAccessors: KMutableProperty0 + field = ::varWithBackingFieldAndAccessors + get + +val valWithAccessors: Int + get(): Int { + return 1 + } + +val test_valWithAccessors: KProperty0 + field = ::valWithAccessors + get + +var varWithAccessors: Int + get(): Int { + return 1 + } + set(value: Int) { + } + +val test_varWithAccessors: KMutableProperty0 + field = ::varWithAccessors + get + +val delegatedVal: Int /* by */ + field = Delegate + get(): Int { + return #delegatedVal$delegate.getValue(thisRef = null, kProp = ::delegatedVal) + } + +val test_delegatedVal: KProperty0 + field = ::delegatedVal + get + +var delegatedVar: Int /* by */ + field = Delegate + get(): Int { + return #delegatedVar$delegate.getValue(thisRef = null, kProp = ::delegatedVar) + } + set(: Int) { + #delegatedVar$delegate.setValue(thisRef = null, kProp = ::delegatedVar, value = ) + } + +val test_delegatedVar: KMutableProperty0 + field = ::delegatedVar + get + +val constVal: Int + field = 1 + get + +val test_constVal: KProperty0 + field = ::constVal + get + +val test_J_CONST: KProperty0 + field = J::CONST/*()*/ + get + +val test_J_nonConst: KMutableProperty0 + field = J::nonConst/*()*/ + get + +val test_varWithPrivateSet: KProperty1 + field = C::varWithPrivateSet + get + +val test_varWithProtectedSet: KProperty1 + field = C::varWithProtectedSet + get diff --git a/compiler/testData/ir/irText/expressions/reflectionLiterals.fir.kt.txt b/compiler/testData/ir/irText/expressions/reflectionLiterals.fir.kt.txt new file mode 100644 index 00000000000..13152677fbc --- /dev/null +++ b/compiler/testData/ir/irText/expressions/reflectionLiterals.fir.kt.txt @@ -0,0 +1,42 @@ +class A { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + fun foo() { + } + +} + +fun bar() { +} + +val qux: Int + field = 1 + get + +val test1: KClass + field = A::class + get + +val test2: KClass + field = ()::class + get + +val test3: KFunction1 + field = A::foo + get + +val test4: KFunction0 + field = A:: + get + +val test5: KFunction0 + field = A()::foo + get + +val test6: KFunction0 + field = ::bar + get diff --git a/compiler/testData/ir/irText/expressions/safeAssignment.fir.kt.txt b/compiler/testData/ir/irText/expressions/safeAssignment.fir.kt.txt new file mode 100644 index 00000000000..a44b20dfee8 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/safeAssignment.fir.kt.txt @@ -0,0 +1,23 @@ +class C { + constructor(x: Int) /* primary */ { + super/*Any*/() + /* () */ + + } + + var x: Int + field = x + get + set + +} + +fun test(nc: C?) { + { // BLOCK + val tmp0_safe_receiver: C? = nc + when { + EQEQ(arg0 = tmp0_safe_receiver, arg1 = null) -> null + else -> tmp0_safe_receiver.( = 42) + } + } /*~> Unit */ +} diff --git a/compiler/testData/ir/irText/expressions/safeCallWithIncrementDecrement.fir.kt.txt b/compiler/testData/ir/irText/expressions/safeCallWithIncrementDecrement.fir.kt.txt new file mode 100644 index 00000000000..ea0d8518045 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/safeCallWithIncrementDecrement.fir.kt.txt @@ -0,0 +1,66 @@ +package test + +class C { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +var C?.p: Int + get(): Int { + return 42 + } + set(value: Int) { + } + +operator fun Int?.inc(): Int? { + return { // BLOCK + val tmp0_safe_receiver: Int? = + when { + EQEQ(arg0 = tmp0_safe_receiver, arg1 = null) -> null + else -> tmp0_safe_receiver.inc() + } + } +} + +operator fun Int?.get(index: Int): Int { + return 42 +} + +operator fun Int?.set(index: Int, value: Int) { +} + +fun testProperty(nc: C?) { + val : Int? = { // BLOCK + val tmp1_safe_receiver: C? = nc + when { + EQEQ(arg0 = tmp1_safe_receiver, arg1 = null) -> null + else -> tmp1_safe_receiver.() + } + } + { // BLOCK + val tmp2_safe_receiver: C? = nc + when { + EQEQ(arg0 = tmp2_safe_receiver, arg1 = null) -> null + else -> tmp2_safe_receiver.(value = .inc()) + } + } /*~> Unit */ + /*~> Unit */ +} + +fun testArrayAccess(nc: C?) { + val : Int? = { // BLOCK + val tmp3_safe_receiver: C? = nc + when { + EQEQ(arg0 = tmp3_safe_receiver, arg1 = null) -> null + else -> tmp3_safe_receiver.() + } + } + val : Int = 0 + val : Int = .get(index = ) + .set(index = , value = .inc()) + /*~> Unit */ +} diff --git a/compiler/testData/ir/irText/expressions/safeCalls.fir.kt.txt b/compiler/testData/ir/irText/expressions/safeCalls.fir.kt.txt new file mode 100644 index 00000000000..9805859fa15 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/safeCalls.fir.kt.txt @@ -0,0 +1,84 @@ +class Ref { + constructor(value: Int) /* primary */ { + super/*Any*/() + /* () */ + + } + + var value: Int + field = value + get + set + +} + +interface IHost { + fun String.extLength(): Int { + return .() + } + +} + +fun test1(x: String?): Int? { + return { // BLOCK + val tmp0_safe_receiver: String? = x + when { + EQEQ(arg0 = tmp0_safe_receiver, arg1 = null) -> null + else -> tmp0_safe_receiver.() + } + } +} + +fun test2(x: String?): Int? { + return { // BLOCK + val tmp1_safe_receiver: String? = x + when { + EQEQ(arg0 = tmp1_safe_receiver, arg1 = null) -> null + else -> tmp1_safe_receiver.hashCode() + } + } +} + +fun test3(x: String?, y: Any?): Boolean? { + return { // BLOCK + val tmp2_safe_receiver: String? = x + when { + EQEQ(arg0 = tmp2_safe_receiver, arg1 = null) -> null + else -> tmp2_safe_receiver.equals(other = y) + } + } +} + +fun test4(x: Ref?) { + { // BLOCK + val tmp3_safe_receiver: Ref? = x + when { + EQEQ(arg0 = tmp3_safe_receiver, arg1 = null) -> null + else -> tmp3_safe_receiver.( = 0) + } + } /*~> Unit */ +} + +fun IHost.test5(s: String?): Int? { + return { // BLOCK + val tmp4_safe_receiver: String? = s + when { + EQEQ(arg0 = tmp4_safe_receiver, arg1 = null) -> null + else -> (, tmp4_safe_receiver).extLength() + } + } +} + +fun Int.foo(): Int { + return 239 +} + +fun box() { + { // BLOCK + val tmp5_safe_receiver: Int = 42 + when { + EQEQ(arg0 = tmp5_safe_receiver, arg1 = null) -> null + else -> tmp5_safe_receiver.foo() + } + } /*~> Unit */ +} diff --git a/compiler/testData/ir/irText/expressions/sam/arrayAsVarargAfterSamArgument.fir.kt.txt b/compiler/testData/ir/irText/expressions/sam/arrayAsVarargAfterSamArgument.fir.kt.txt new file mode 100644 index 00000000000..77f1971f85c --- /dev/null +++ b/compiler/testData/ir/irText/expressions/sam/arrayAsVarargAfterSamArgument.fir.kt.txt @@ -0,0 +1,68 @@ +fun test(fn: Function0, r: Runnable, arr: Array) { + error("") /* ERROR CALL */local fun () { + return Unit + } +; arr; + foo1(r = local fun () { + return Unit + } + /*-> Runnable? */, strs = [*arr]) /*~> Unit */ + error("") /* ERROR CALL */fn; arr; + foo1(r = fn /*-> Runnable? */, strs = [*arr]) /*~> Unit */ + foo1(r = r, strs = [""]) /*~> Unit */ + error("") /* ERROR CALL */fn; arr; + foo1(r = fn /*-> Runnable? */, strs = [*arr]) /*~> Unit */ + foo1(r = r, strs = [*arr]) /*~> Unit */ + val i1: ErrorType /* ERROR */ = error("") /* ERROR CALL */local fun () { + return Unit + } +; arr; + val i2: Test = Test(r = local fun () { + return Unit + } + /*-> Runnable? */, strs = [*arr]) + val i3: ErrorType /* ERROR */ = error("") /* ERROR CALL */local fun () { + return Unit + } +; local fun () { + return Unit + } +; arr; + val i4: Test = Test(r1 = r, r2 = local fun () { + return Unit + } + /*-> Runnable? */, strs = [""]) + val i5: Test = Test(r1 = local fun () { + return Unit + } + /*-> Runnable? */, r2 = local fun () { + return Unit + } + /*-> Runnable? */, strs = [*arr]) + val i6: Test = Test(r1 = r, r2 = local fun () { + return Unit + } + /*-> Runnable? */, strs = [*arr]) + error("") /* ERROR CALL */local fun () { + return Unit + } +; local fun () { + return Unit + } +; arr; + error("") /* ERROR CALL */r; local fun () { + return Unit + } +; ""; + error("") /* ERROR CALL */local fun () { + return Unit + } +; local fun () { + return Unit + } +; arr; + error("") /* ERROR CALL */r; local fun () { + return Unit + } +; arr; +} diff --git a/compiler/testData/ir/irText/expressions/sam/genericSamProjectedOut.fir.kt.txt b/compiler/testData/ir/irText/expressions/sam/genericSamProjectedOut.fir.kt.txt new file mode 100644 index 00000000000..dbc03ed47f0 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/sam/genericSamProjectedOut.fir.kt.txt @@ -0,0 +1,14 @@ +fun test(a: SomeJavaClass) { + a.someFunction(hello = local fun (it: String?) { + return Unit + } + /*-> Hello? */) + a.plus(hello = local fun (it: String?) { + return Unit + } + /*-> Hello? */) + a.get(hello = local fun (it: String?) { + return Unit + } + /*-> Hello? */) +} diff --git a/compiler/testData/ir/irText/expressions/sam/genericSamSmartcast.fir.kt.txt b/compiler/testData/ir/irText/expressions/sam/genericSamSmartcast.fir.kt.txt new file mode 100644 index 00000000000..869b1c4a1ec --- /dev/null +++ b/compiler/testData/ir/irText/expressions/sam/genericSamSmartcast.fir.kt.txt @@ -0,0 +1,9 @@ +fun f(x: Any): String { + when { + x is A<*> -> return x /*as A<*> */.call(block = local fun (y: Any?): String? { + return "OK" + } + /*-> I? */) /*!! String */ + } + return "Fail" +} diff --git a/compiler/testData/ir/irText/expressions/sam/samByProjectedType.fir.kt.txt b/compiler/testData/ir/irText/expressions/sam/samByProjectedType.fir.kt.txt new file mode 100644 index 00000000000..1aeceb64953 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/sam/samByProjectedType.fir.kt.txt @@ -0,0 +1,6 @@ +fun test1() { + bar(j = local fun (x: Any): Any? { + return x + } + /*-> J<*>? */) +} diff --git a/compiler/testData/ir/irText/expressions/sam/samConstructors.fir.kt.txt b/compiler/testData/ir/irText/expressions/sam/samConstructors.fir.kt.txt new file mode 100644 index 00000000000..0248a8a9153 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/sam/samConstructors.fir.kt.txt @@ -0,0 +1,24 @@ +fun test1(): Runnable { + return local fun () { + return Unit + } + /*-> Runnable */ +} + +fun test2(a: Function0): Runnable { + return a /*-> Runnable */ +} + +fun foo() { +} + +fun test3(): Runnable { + return ::foo /*-> Runnable */ +} + +fun test4(): Comparator { + return local fun (a: Int?, b: Int?): Int { + return a.minus(other = b /*!! Int */) + } + /*-> Comparator */ +} diff --git a/compiler/testData/ir/irText/expressions/sam/samConversionInGenericConstructorCall.fir.kt.txt b/compiler/testData/ir/irText/expressions/sam/samConversionInGenericConstructorCall.fir.kt.txt new file mode 100644 index 00000000000..53195465e1f --- /dev/null +++ b/compiler/testData/ir/irText/expressions/sam/samConversionInGenericConstructorCall.fir.kt.txt @@ -0,0 +1,8 @@ +fun test1(f: Function1): C { + return C(jxx = f /*-> J? */) +} + +fun test2(x: Any) { + x as Function1 /*~> Unit */ + C(jxx = x /*as Function1 */ /*-> J? */) /*~> Unit */ +} diff --git a/compiler/testData/ir/irText/expressions/sam/samConversionInGenericConstructorCall_NI.fir.kt.txt b/compiler/testData/ir/irText/expressions/sam/samConversionInGenericConstructorCall_NI.fir.kt.txt new file mode 100644 index 00000000000..fcde5506071 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/sam/samConversionInGenericConstructorCall_NI.fir.kt.txt @@ -0,0 +1,42 @@ +fun test3(f1: Function1, f2: Function1): D { + return C(jxx = f1 /*-> J? */).D(jxy = f2 /*-> J? */) +} + +class Outer { + constructor(j11: J) /* primary */ { + super/*Any*/() + /* () */ + + } + + val j11: J + field = j11 + get + + inner class Inner { + constructor(j12: J) /* primary */ { + super/*Any*/() + /* () */ + + } + + val j12: J + field = j12 + get + + } + +} + +fun test4(f: Function1, g: Function1): Inner { + return Outer(j11 = f /*-> J */).Inner(j12 = g /*-> J */) +} + +fun testGenericJavaCtor1(f: Function1): G { + return G(x = f /*-> J? */) +} + +fun testGenericJavaCtor2(x: Any) { + x as Function1 /*~> Unit */ + G(x = x /*as Function1 */ /*-> J? */) /*~> Unit */ +} diff --git a/compiler/testData/ir/irText/expressions/sam/samConversionToGeneric.fir.kt.txt b/compiler/testData/ir/irText/expressions/sam/samConversionToGeneric.fir.kt.txt new file mode 100644 index 00000000000..d0245f2b431 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/sam/samConversionToGeneric.fir.kt.txt @@ -0,0 +1,51 @@ +fun test1(): J { + return local fun (x: String?): String? { + return x + } + /*-> J */ +} + +fun test2(): J { + return local fun (x: String): String { + return x + } + /*-> J */ +} + +fun test3() { + return bar(j = local fun (x: String): String { + return x + } + /*-> J? */) +} + +fun test4(a: Any) { + a as J /*~> Unit */ + bar(j = a /*as J */) +} + +fun test5(a: Any) { + a as Function1 /*~> Unit */ + bar(j = a /*as Function1 */ /*-> J? */) +} + +fun test6(a: Function1) { + bar(j = a /*-> J? */) +} + +fun test7(a: Any) { + a as Function1 /*~> Unit */ + bar(j = a /*as Function1 */ /*-> J? */) +} + +fun test8(efn: @ExtensionFunctionType @ExtensionFunctionType Function1): J { + return efn /*-> J */ +} + +fun test9(efn: @ExtensionFunctionType @ExtensionFunctionType Function1) { + bar(j = efn /*-> J? */) +} + +fun test10(fn: Function1) { + bar2x(j2x = fn /*-> J2X? */) +} diff --git a/compiler/testData/ir/irText/expressions/sam/samConversions.fir.kt.txt b/compiler/testData/ir/irText/expressions/sam/samConversions.fir.kt.txt new file mode 100644 index 00000000000..0c781d0237f --- /dev/null +++ b/compiler/testData/ir/irText/expressions/sam/samConversions.fir.kt.txt @@ -0,0 +1,29 @@ +fun J.test0(a: Runnable) { + runStatic(r = a) + .runIt(r = a) +} + +fun test1() { + runStatic(r = local fun () { + test1() + } + /*-> Runnable? */) +} + +fun J.test2() { + .runIt(r = local fun () { + test1() + } + /*-> Runnable? */) +} + +fun J.test3(a: Function0) { + .run2(r1 = a /*-> Runnable? */, r2 = a /*-> Runnable? */) +} + +fun J.test4(a: Function0, b: Function0, flag: Boolean) { + .runIt(r = when { + flag -> a + else -> b + } /*-> Runnable? */) +} diff --git a/compiler/testData/ir/irText/expressions/sam/samConversionsWithSmartCasts.fir.kt.txt b/compiler/testData/ir/irText/expressions/sam/samConversionsWithSmartCasts.fir.kt.txt new file mode 100644 index 00000000000..cf210020075 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/sam/samConversionsWithSmartCasts.fir.kt.txt @@ -0,0 +1,56 @@ +fun test1(a: Function0) { + when { + a is Runnable -> runStatic(r = a /*as Runnable */) + } +} + +fun test2(a: Function0) { + when { + a is Runnable -> J().run1(r = a /*as Runnable */) + } +} + +fun test3(a: Function0) { + when { + a is Runnable -> J().run2(r1 = a /*as Runnable */, r2 = a /*as Runnable */) + } +} + +fun test4(a: Function0, b: Function0) { + when { + a is Runnable -> J().run2(r1 = a /*as Runnable */, r2 = b /*-> Runnable? */) + } +} + +fun test5(a: Any) { + when { + a is Runnable -> J().run1(r = a /*as Runnable */) + } +} + +fun test5x(a: Any) { + when { + a is Runnable -> { // BLOCK + a /*as Runnable */ as Function0 /*~> Unit */ + J().run1(r = a /*as Runnable */) + } + } +} + +fun test6(a: Any) { + a as Function0 /*~> Unit */ + J().run1(r = a /*as Function0 */ /*-> Runnable? */) +} + +fun test7(a: Function1) { + a as Function0 /*~> Unit */ + error("") /* ERROR CALL */a /*as Function0 */; +} + +fun test8(a: Function0) { + error("") /* ERROR CALL */id?>(x = a); +} + +fun test9() { + J().run1(r = ::test9 /*-> Runnable? */) +} diff --git a/compiler/testData/ir/irText/expressions/sam/samOperators.fir.kt.txt b/compiler/testData/ir/irText/expressions/sam/samOperators.fir.kt.txt new file mode 100644 index 00000000000..3ec22f65775 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/sam/samOperators.fir.kt.txt @@ -0,0 +1,17 @@ +fun f() { +} + +fun J.test1() { + .get(k = ::f /*-> Runnable? */) + .get(k = ::f /*-> Runnable? */, m = ::f /*-> Runnable? */) +} + +fun J.test2() { + .set(k = ::f /*-> Runnable? */, v = ::f /*-> Runnable? */) + .set(k = ::f /*-> Runnable? */, m = ::f /*-> Runnable? */, v = ::f /*-> Runnable? */) +} + +fun J.test3() { + .plusAssign(i = ::f /*-> Runnable? */) + .minusAssign(i = ::f /*-> Runnable? */) +} diff --git a/compiler/testData/ir/irText/expressions/setFieldWithImplicitCast.fir.kt.txt b/compiler/testData/ir/irText/expressions/setFieldWithImplicitCast.fir.kt.txt new file mode 100644 index 00000000000..6d79a354a8d --- /dev/null +++ b/compiler/testData/ir/irText/expressions/setFieldWithImplicitCast.fir.kt.txt @@ -0,0 +1,16 @@ +class Derived : Base { + constructor() /* primary */ { + super/*Base*/() + /* () */ + + } + + fun setValue(v: Any) { + when { + v is String -> { // BLOCK + .#value = v /*as String */ + } + } + } + +} diff --git a/compiler/testData/ir/irText/expressions/signedToUnsignedConversions_annotation.fir.kt.txt b/compiler/testData/ir/irText/expressions/signedToUnsignedConversions_annotation.fir.kt.txt new file mode 100644 index 00000000000..9acc6bebb01 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/signedToUnsignedConversions_annotation.fir.kt.txt @@ -0,0 +1,6 @@ +package kotlin.internal + +annotation class ImplicitIntegerCoercion : Annotation { + constructor() /* primary */ + +} diff --git a/compiler/testData/ir/irText/expressions/signedToUnsignedConversions_test.fir.kt.txt b/compiler/testData/ir/irText/expressions/signedToUnsignedConversions_test.fir.kt.txt new file mode 100644 index 00000000000..04c0939354d --- /dev/null +++ b/compiler/testData/ir/irText/expressions/signedToUnsignedConversions_test.fir.kt.txt @@ -0,0 +1,57 @@ +@ImplicitIntegerCoercion +const val IMPLICIT_INT: Int + field = 255 + get + +@ImplicitIntegerCoercion +const val EXPLICIT_INT: Int + field = 255 + get + +@ImplicitIntegerCoercion +const val LONG_CONST: Long + field = 255L + get + +@ImplicitIntegerCoercion +val NON_CONST: Int + field = 255 + get + +@ImplicitIntegerCoercion +const val BIGGER_THAN_UBYTE: Int + field = 256 + get + +@ImplicitIntegerCoercion +const val UINT_CONST: UInt + field = 42 + get + +fun takeUByte(@ImplicitIntegerCoercion u: UByte) { +} + +fun takeUShort(@ImplicitIntegerCoercion u: UShort) { +} + +fun takeUInt(@ImplicitIntegerCoercion u: UInt) { +} + +fun takeULong(@ImplicitIntegerCoercion u: ULong) { +} + +fun takeUBytes(@ImplicitIntegerCoercion vararg u: UByte) { +} + +fun takeLong(@ImplicitIntegerCoercion l: Long) { +} + +fun test() { + error("") /* ERROR CALL */255; + error("") /* ERROR CALL */255; + error("") /* ERROR CALL */255; + error("") /* ERROR CALL */256; + error("") /* ERROR CALL */255; + error("") /* ERROR CALL */255; + error("") /* ERROR CALL */255; 255; 42; +} diff --git a/compiler/testData/ir/irText/expressions/simpleUnaryOperators.fir.kt.txt b/compiler/testData/ir/irText/expressions/simpleUnaryOperators.fir.kt.txt new file mode 100644 index 00000000000..dd9a2cdcd72 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/simpleUnaryOperators.fir.kt.txt @@ -0,0 +1,23 @@ +fun test1(x: Int): Int { + return x.unaryMinus() +} + +fun test2(): Int { + return -42 +} + +fun test3(x: Int): Int { + return x.unaryPlus() +} + +fun test4(): Int { + return 42 +} + +fun test5(x: Boolean): Boolean { + return x.not() +} + +fun test6(): Boolean { + return false +} diff --git a/compiler/testData/ir/irText/expressions/smartCastsWithDestructuring.fir.kt.txt b/compiler/testData/ir/irText/expressions/smartCastsWithDestructuring.fir.kt.txt new file mode 100644 index 00000000000..077e7fa05d0 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/smartCastsWithDestructuring.fir.kt.txt @@ -0,0 +1,24 @@ +interface I1 { + +} + +interface I2 { + +} + +operator fun I1.component1(): Int { + return 1 +} + +operator fun I2.component2(): String { + return "" +} + +fun test(x: I1) { + when { + x !is I2 -> return Unit + } + val : I2 = x /*as I2 */ + val c1: Int = .component1() + val c2: String = .component2() +} diff --git a/compiler/testData/ir/irText/expressions/specializedTypeAliasConstructorCall.fir.kt.txt b/compiler/testData/ir/irText/expressions/specializedTypeAliasConstructorCall.fir.kt.txt new file mode 100644 index 00000000000..1fea8c4a1aa --- /dev/null +++ b/compiler/testData/ir/irText/expressions/specializedTypeAliasConstructorCall.fir.kt.txt @@ -0,0 +1,17 @@ +typealias IntAlias = Cell +class Cell { + constructor(value: T) /* primary */ { + super/*Any*/() + /* () */ + + } + + val value: T + field = value + get + +} + +fun test(): Cell { + return Cell(value = 42) +} diff --git a/compiler/testData/ir/irText/expressions/stringComparisons.fir.kt.txt b/compiler/testData/ir/irText/expressions/stringComparisons.fir.kt.txt new file mode 100644 index 00000000000..b0e6c856350 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/stringComparisons.fir.kt.txt @@ -0,0 +1,15 @@ +fun test1(a: String, b: String): Boolean { + return greater(arg0 = a.compareTo(other = b), arg1 = 0) +} + +fun test2(a: String, b: String): Boolean { + return less(arg0 = a.compareTo(other = b), arg1 = 0) +} + +fun test3(a: String, b: String): Boolean { + return greaterOrEqual(arg0 = a.compareTo(other = b), arg1 = 0) +} + +fun test4(a: String, b: String): Boolean { + return lessOrEqual(arg0 = a.compareTo(other = b), arg1 = 0) +} diff --git a/compiler/testData/ir/irText/expressions/stringTemplates.fir.kt.txt b/compiler/testData/ir/irText/expressions/stringTemplates.fir.kt.txt new file mode 100644 index 00000000000..25daa4ce302 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/stringTemplates.fir.kt.txt @@ -0,0 +1,43 @@ +fun foo(): String { + return "" +} + +val x: Int + field = 42 + get + +val test1: String + field = "" + get + +val test2: String + field = "abc" + get + +val test3: String + field = "" + get + +val test4: String + field = "abc" + get + +val test5: String + field = "\nabc\n" + get + +val test6: String + field = ().toString() + " " + foo().toString() + get + +val test7: String + field = ().toString() + get + +val test8: String + field = foo().toString() + get + +val test9: String + field = ().toString() + get diff --git a/compiler/testData/ir/irText/expressions/suspendConversionOnArbitraryExpression.fir.kt.txt b/compiler/testData/ir/irText/expressions/suspendConversionOnArbitraryExpression.fir.kt.txt new file mode 100644 index 00000000000..58f8cee23af --- /dev/null +++ b/compiler/testData/ir/irText/expressions/suspendConversionOnArbitraryExpression.fir.kt.txt @@ -0,0 +1,189 @@ +fun useSuspend(sfn: SuspendFunction0) { +} + +fun useSuspendExt(sfn: @ExtensionFunctionType @ExtensionFunctionType SuspendFunction1) { +} + +fun useSuspendArg(sfn: SuspendFunction1) { +} + +fun useSuspendArgT(sfn: SuspendFunction1) { +} + +fun useSuspendExtT(sfn: @ExtensionFunctionType @ExtensionFunctionType SuspendFunction1) { +} + +fun produceFun(): Function0 { + return local fun () { + return Unit + } + +} + +fun testSimple(fn: Function0) { + useSuspend(sfn = { // BLOCK + local suspend fun Function0.suspendConversion() { + callee.invoke() + } + + fn::suspendConversion + }) +} + +fun testSimpleNonVal() { + useSuspend(sfn = { // BLOCK + local suspend fun Function0.suspendConversion() { + callee.invoke() + } + + produceFun()::suspendConversion + }) +} + +fun testExtAsExt(fn: @ExtensionFunctionType @ExtensionFunctionType Function1) { + useSuspendExt(sfn = { // BLOCK + local suspend fun @ExtensionFunctionType @ExtensionFunctionType Function1.suspendConversion(p0: Int) { + callee.invoke(p1 = p0) + } + + fn::suspendConversion + }) +} + +fun testExtAsSimple(fn: @ExtensionFunctionType @ExtensionFunctionType Function1) { + useSuspendArg(sfn = { // BLOCK + local suspend fun @ExtensionFunctionType @ExtensionFunctionType Function1.suspendConversion(p0: Int) { + callee.invoke(p1 = p0) + } + + fn::suspendConversion + }) +} + +fun testSimpleAsExt(fn: Function1) { + useSuspendExt(sfn = { // BLOCK + local suspend fun Function1.suspendConversion(p0: Int) { + callee.invoke(p1 = p0) + } + + fn::suspendConversion + }) +} + +fun testSimpleAsSimpleT(fn: Function1) { + useSuspendArgT(sfn = { // BLOCK + local suspend fun Function1.suspendConversion(p0: T) { + callee.invoke(p1 = p0) + } + + fn::suspendConversion + }) +} + +fun testSimpleAsExtT(fn: Function1) { + useSuspendExtT(sfn = { // BLOCK + local suspend fun Function1.suspendConversion(p0: T) { + callee.invoke(p1 = p0) + } + + fn::suspendConversion + }) +} + +fun testExtAsSimpleT(fn: @ExtensionFunctionType @ExtensionFunctionType Function1) { + useSuspendArgT(sfn = { // BLOCK + local suspend fun @ExtensionFunctionType @ExtensionFunctionType Function1.suspendConversion(p0: T) { + callee.invoke(p1 = p0) + } + + fn::suspendConversion + }) +} + +fun testExtAsExtT(fn: @ExtensionFunctionType @ExtensionFunctionType Function1) { + useSuspendExtT(sfn = { // BLOCK + local suspend fun @ExtensionFunctionType @ExtensionFunctionType Function1.suspendConversion(p0: T) { + callee.invoke(p1 = p0) + } + + fn::suspendConversion + }) +} + +fun testSimpleSAsSimpleT(fn: Function1) { + useSuspendArgT(sfn = { // BLOCK + local suspend fun Function1.suspendConversion(p0: T) { + callee.invoke(p1 = p0) + } + + fn::suspendConversion + }) +} + +fun testSimpleSAsExtT(fn: Function1) { + useSuspendExtT(sfn = { // BLOCK + local suspend fun Function1.suspendConversion(p0: T) { + callee.invoke(p1 = p0) + } + + fn::suspendConversion + }) +} + +fun testExtSAsSimpleT(fn: @ExtensionFunctionType @ExtensionFunctionType Function1) { + useSuspendArgT(sfn = { // BLOCK + local suspend fun @ExtensionFunctionType @ExtensionFunctionType Function1.suspendConversion(p0: T) { + callee.invoke(p1 = p0) + } + + fn::suspendConversion + }) +} + +fun testExtSAsExtT(fn: @ExtensionFunctionType @ExtensionFunctionType Function1) { + useSuspendExtT(sfn = { // BLOCK + local suspend fun @ExtensionFunctionType @ExtensionFunctionType Function1.suspendConversion(p0: T) { + callee.invoke(p1 = p0) + } + + fn::suspendConversion + }) +} + +fun testSmartCastWithSuspendConversion(a: Any) { + a as Function0 /*~> Unit */ + useSuspend(sfn = { // BLOCK + local suspend fun Function0.suspendConversion() { + callee.invoke() + } + + a /*as Function0 */::suspendConversion + }) +} + +fun testSmartCastOnVarWithSuspendConversion(a: Any) { + var b: Any = a + b as Function0 /*~> Unit */ + useSuspend(sfn = { // BLOCK + local suspend fun Function0.suspendConversion() { + callee.invoke() + } + + b /*as Function0 */::suspendConversion + }) +} + +fun testSmartCastVsSuspendConversion(a: Function0) { + a as SuspendFunction0 /*~> Unit */ + useSuspend(sfn = a /*as SuspendFunction0 */) +} + +fun testSmartCastOnVarVsSuspendConversion(a: Function0) { + var b: Function0 = a + b as SuspendFunction0 /*~> Unit */ + useSuspend(sfn = b) +} + +fun testIntersectionVsSuspendConversion(x: T) where T : Function0, T : SuspendFunction0 { + useSuspend(sfn = x) +} diff --git a/compiler/testData/ir/irText/expressions/temporaryInEnumEntryInitializer.fir.kt.txt b/compiler/testData/ir/irText/expressions/temporaryInEnumEntryInitializer.fir.kt.txt new file mode 100644 index 00000000000..8019c9ab30b --- /dev/null +++ b/compiler/testData/ir/irText/expressions/temporaryInEnumEntryInitializer.fir.kt.txt @@ -0,0 +1,28 @@ +val n: Any? + field = null + get + +open enum class En : Enum { + private constructor(x: String?) /* primary */ { + super/*Enum*/() + /* () */ + + } + + val x: String? + field = x + get + + ENTRY = En(x = { // BLOCK + val tmp0_safe_receiver: Any? = () + when { + EQEQ(arg0 = tmp0_safe_receiver, arg1 = null) -> null + else -> tmp0_safe_receiver.toString() + } + }) + + fun values(): Array /* Synthetic body for ENUM_VALUES */ + + fun valueOf(value: String): En /* Synthetic body for ENUM_VALUEOF */ + +} diff --git a/compiler/testData/ir/irText/expressions/thisOfGenericOuterClass.fir.kt.txt b/compiler/testData/ir/irText/expressions/thisOfGenericOuterClass.fir.kt.txt new file mode 100644 index 00000000000..1f36002c48d --- /dev/null +++ b/compiler/testData/ir/irText/expressions/thisOfGenericOuterClass.fir.kt.txt @@ -0,0 +1,44 @@ +class Outer { + constructor(x: T) /* primary */ { + super/*Any*/() + /* () */ + + } + + val x: T + field = x + get + + open inner class Inner { + constructor(y: Int) /* primary */ { + super/*Any*/() + /* () */ + + } + + val y: Int + field = y + get + + } + +} + +fun Outer.test(): Inner { + return { // BLOCK + local class : Inner { + private constructor() /* primary */ { + .super/*Inner*/(y = 42) + /* () */ + + } + + val xx: Int + field = .().plus(other = .()) + get + + } + + () + } +} diff --git a/compiler/testData/ir/irText/expressions/thisRefToObjectInNestedClassConstructorCall.fir.kt.txt b/compiler/testData/ir/irText/expressions/thisRefToObjectInNestedClassConstructorCall.fir.kt.txt new file mode 100644 index 00000000000..17c69ed7c75 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/thisRefToObjectInNestedClassConstructorCall.fir.kt.txt @@ -0,0 +1,39 @@ +open class Base { + constructor(x: Any) /* primary */ { + super/*Any*/() + /* () */ + + } + + val x: Any + field = x + get + +} + +object Host { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + class Derived1 : Base { + constructor() /* primary */ { + super/*Base*/(x = Host) + /* () */ + + } + + } + + class Derived2 : Base { + constructor() /* primary */ { + super/*Base*/(x = Host) + /* () */ + + } + + } + +} diff --git a/compiler/testData/ir/irText/expressions/thisReferenceBeforeClassDeclared.fir.kt.txt b/compiler/testData/ir/irText/expressions/thisReferenceBeforeClassDeclared.fir.kt.txt new file mode 100644 index 00000000000..9231a19a63d --- /dev/null +++ b/compiler/testData/ir/irText/expressions/thisReferenceBeforeClassDeclared.fir.kt.txt @@ -0,0 +1,48 @@ +fun WithCompanion.test() { + val test1: = { // BLOCK + local class : WithCompanion { + private constructor() /* primary */ { + super/*WithCompanion*/(a = Companion) + /* () */ + + } + + } + + () + } + val test2: = { // BLOCK + local class : WithCompanion { + private constructor() /* primary */ { + super/*WithCompanion*/(a = Companion.foo()) + /* () */ + + } + + } + + () + } +} + +open class WithCompanion { + constructor(a: Companion) /* primary */ { + super/*Any*/() + /* () */ + + } + + companion object Companion { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + fun foo(): Companion { + return + } + + } + +} diff --git a/compiler/testData/ir/irText/expressions/throw.fir.kt.txt b/compiler/testData/ir/irText/expressions/throw.fir.kt.txt new file mode 100644 index 00000000000..76bd6339f87 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/throw.fir.kt.txt @@ -0,0 +1,9 @@ +fun test1() { + throw Throwable() +} + +fun testImplicitCast(a: Any) { + when { + a is Throwable -> throw a /*as Throwable */ + } +} diff --git a/compiler/testData/ir/irText/expressions/tryCatch.fir.kt.txt b/compiler/testData/ir/irText/expressions/tryCatch.fir.kt.txt new file mode 100644 index 00000000000..c8bd8877a5a --- /dev/null +++ b/compiler/testData/ir/irText/expressions/tryCatch.fir.kt.txt @@ -0,0 +1,20 @@ +fun test1() { + try println() + catch (e: Throwable)println() + finally println() +} + +fun test2(): Int { + return try { // BLOCK + println() + 42 + } + catch (e: Throwable){ // BLOCK + println() + 24 + } + finally { // BLOCK + println() + 555 + } +} diff --git a/compiler/testData/ir/irText/expressions/tryCatchWithImplicitCast.fir.kt.txt b/compiler/testData/ir/irText/expressions/tryCatchWithImplicitCast.fir.kt.txt new file mode 100644 index 00000000000..c5b32397587 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/tryCatchWithImplicitCast.fir.kt.txt @@ -0,0 +1,8 @@ +fun testImplicitCast(a: Any) { + when { + a !is String -> return Unit + } + val t: String = try a /*as String */ + catch (e: Throwable)"" + +} diff --git a/compiler/testData/ir/irText/expressions/typeAliasConstructorReference.fir.kt.txt b/compiler/testData/ir/irText/expressions/typeAliasConstructorReference.fir.kt.txt new file mode 100644 index 00000000000..9dec7e45903 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/typeAliasConstructorReference.fir.kt.txt @@ -0,0 +1,36 @@ +typealias CA = C +typealias NA = Nested +class C { + constructor(x: Int) /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +object Host { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + class Nested { + constructor(x: Int) /* primary */ { + super/*Any*/() + /* () */ + + } + + } + +} + +val test1: Function1 + field = C:: + get + +val test2: Function1 + field = Nested:: + get diff --git a/compiler/testData/ir/irText/expressions/useImportedMember.fir.kt.txt b/compiler/testData/ir/irText/expressions/useImportedMember.fir.kt.txt new file mode 100644 index 00000000000..987ce65d2a2 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/useImportedMember.fir.kt.txt @@ -0,0 +1,102 @@ +interface I { + fun T.fromInterface(): T { + return + } + + fun genericFromSuper(g: G): G { + return g + } + +} + +open class BaseClass { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + val T.fromClass: T + get(): T { + return + } + +} + +object C : BaseClass, I { + private constructor() /* primary */ { + super/*BaseClass*/() + /* () */ + + } + + fun f(s: Int): Int { + return 1 + } + + fun f(s: String): Int { + return 2 + } + + fun Boolean.f(): Int { + return 3 + } + + var p: Int + field = 4 + get + set + + val Int.ext: Int + get(): Int { + return 6 + } + + fun g1(t: T): T { + return t + } + + val T.g2: T + get(): T { + return + } + +} + +fun box(): String { + when { + EQEQ(arg0 = C.f(s = 1), arg1 = 1).not() -> return "1" + } + when { + EQEQ(arg0 = C.f(s = "s"), arg1 = 2).not() -> return "2" + } + when { + EQEQ(arg0 = (C, true).f(), arg1 = 3).not() -> return "3" + } + when { + EQEQ(arg0 = C.(), arg1 = 4).not() -> return "4" + } + C.( = 5) + when { + EQEQ(arg0 = C.(), arg1 = 5).not() -> return "5" + } + when { + EQEQ(arg0 = (C, 5).(), arg1 = 6).not() -> return "6" + } + when { + EQEQ(arg0 = C.g1(t = "7"), arg1 = "7").not() -> return "7" + } + when { + EQEQ(arg0 = (C, "8").(), arg1 = "8").not() -> return "8" + } + when { + EQEQ(arg0 = (C, 9).fromInterface(), arg1 = 9).not() -> return "9" + } + when { + EQEQ(arg0 = (C, "10").(), arg1 = "10").not() -> return "10" + } + when { + EQEQ(arg0 = C.genericFromSuper(g = "11"), arg1 = "11").not() -> return "11" + } + return "OK" +} diff --git a/compiler/testData/ir/irText/expressions/values.fir.kt.txt b/compiler/testData/ir/irText/expressions/values.fir.kt.txt new file mode 100644 index 00000000000..0466612fce3 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/values.fir.kt.txt @@ -0,0 +1,61 @@ +enum class Enum : Enum { + private constructor() /* primary */ { + super/*Enum*/() + /* () */ + + } + + A = Enum() + + fun values(): Array /* Synthetic body for ENUM_VALUES */ + + fun valueOf(value: String): Enum /* Synthetic body for ENUM_VALUEOF */ + +} + +object A { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +val a: Int + field = 0 + get + +class Z { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + companion object Companion { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + } + +} + +fun test1(): Enum { + return Enum.A +} + +fun test2(): A { + return A +} + +fun test3(): Int { + return () +} + +fun test4(): Companion { + return Companion +} diff --git a/compiler/testData/ir/irText/expressions/variableAsFunctionCall.fir.kt.txt b/compiler/testData/ir/irText/expressions/variableAsFunctionCall.fir.kt.txt new file mode 100644 index 00000000000..ec434a2a7e0 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/variableAsFunctionCall.fir.kt.txt @@ -0,0 +1,34 @@ +fun String.k(): Function0 { + return local fun (): String { + return + } + +} + +fun test1(f: Function0) { + return f.invoke() +} + +fun test2(f: @ExtensionFunctionType @ExtensionFunctionType Function1) { + return f.invoke(p1 = "hello") +} + +fun test3(): String { + return "hello".k().invoke() +} + +fun test4(ns: String?): String? { + return { // BLOCK + val tmp1_safe_receiver: Function0? = { // BLOCK + val tmp0_safe_receiver: String? = ns + when { + EQEQ(arg0 = tmp0_safe_receiver, arg1 = null) -> null + else -> tmp0_safe_receiver.k() + } + } + when { + EQEQ(arg0 = tmp1_safe_receiver, arg1 = null) -> null + else -> tmp1_safe_receiver.invoke() + } + } +} diff --git a/compiler/testData/ir/irText/expressions/variableAsFunctionCallWithGenerics.fir.kt.txt b/compiler/testData/ir/irText/expressions/variableAsFunctionCallWithGenerics.fir.kt.txt new file mode 100644 index 00000000000..7e5a7758482 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/variableAsFunctionCallWithGenerics.fir.kt.txt @@ -0,0 +1,23 @@ +val T.gk: Function0 + get(): Function0 { + return local fun (): T { + return + } + + } + +fun testGeneric1(x: String): T { + return x.().invoke() +} + +val T.kt26531Val: Function0 + get(): Function0 { + return local fun (): T { + return + } + + } + +fun kt26531(): T { + return 7.().invoke() +} diff --git a/compiler/testData/ir/irText/expressions/when.fir.kt.txt b/compiler/testData/ir/irText/expressions/when.fir.kt.txt new file mode 100644 index 00000000000..b29edd7691a --- /dev/null +++ b/compiler/testData/ir/irText/expressions/when.fir.kt.txt @@ -0,0 +1,63 @@ +object A { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +fun testWithSubject(x: Any?): String { + return { // BLOCK + val tmp0_subject: Any? = x + when { + EQEQ(arg0 = tmp0_subject, arg1 = null) -> "null" + EQEQ(arg0 = tmp0_subject, arg1 = A) -> "A" + tmp0_subject is String -> "String" + tmp0_subject !is Number -> "!Number" + setOf().contains(element = tmp0_subject) -> "nothingness?" + else -> "something" + } + } +} + +fun test(x: Any?): String { + return when { + EQEQ(arg0 = x, arg1 = null) -> "null" + EQEQ(arg0 = x /*as Any */, arg1 = A) -> "A" + x /*as Any */ is String -> "String" + x /*as Any */ !is Number -> "!Number" + setOf().contains(element = x /*as Number */) -> "nothingness?" + else -> "something" + } +} + +fun testComma(x: Int): String { + return { // BLOCK + val tmp1_subject: Int = x + when { + when { + when { + when { + EQEQ(arg0 = tmp1_subject, arg1 = 1) -> true + else -> EQEQ(arg0 = tmp1_subject, arg1 = 2) + } -> true + else -> EQEQ(arg0 = tmp1_subject, arg1 = 3) + } -> true + else -> EQEQ(arg0 = tmp1_subject, arg1 = 4) + } -> "1234" + when { + when { + EQEQ(arg0 = tmp1_subject, arg1 = 5) -> true + else -> EQEQ(arg0 = tmp1_subject, arg1 = 6) + } -> true + else -> EQEQ(arg0 = tmp1_subject, arg1 = 7) + } -> "567" + when { + EQEQ(arg0 = tmp1_subject, arg1 = 8) -> true + else -> EQEQ(arg0 = tmp1_subject, arg1 = 9) + } -> "89" + else -> "?" + } + } +} diff --git a/compiler/testData/ir/irText/expressions/whenReturn.fir.kt.txt b/compiler/testData/ir/irText/expressions/whenReturn.fir.kt.txt new file mode 100644 index 00000000000..bd39afe8f55 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/whenReturn.fir.kt.txt @@ -0,0 +1,13 @@ +fun toString(grade: String): String { + { // BLOCK + val tmp0_subject: String = grade + when { + EQEQ(arg0 = tmp0_subject, arg1 = "A") -> return "Excellent" + EQEQ(arg0 = tmp0_subject, arg1 = "B") -> return "Good" + EQEQ(arg0 = tmp0_subject, arg1 = "C") -> return "Mediocre" + EQEQ(arg0 = tmp0_subject, arg1 = "D") -> return "Fair" + else -> return "Failure" + } + } + return "???" +} diff --git a/compiler/testData/ir/irText/expressions/whenUnusedExpression.fir.kt.txt b/compiler/testData/ir/irText/expressions/whenUnusedExpression.fir.kt.txt new file mode 100644 index 00000000000..30614dd0e9f --- /dev/null +++ b/compiler/testData/ir/irText/expressions/whenUnusedExpression.fir.kt.txt @@ -0,0 +1,12 @@ +fun test(b: Boolean, i: Int) { + when { + b -> { // BLOCK + val tmp0_subject: Int = i + when { + EQEQ(arg0 = tmp0_subject, arg1 = 0) -> 1 + else -> null + } + } + else -> null + } /*~> Unit */ +} diff --git a/compiler/testData/ir/irText/expressions/whenWithSubjectVariable.fir.kt.txt b/compiler/testData/ir/irText/expressions/whenWithSubjectVariable.fir.kt.txt new file mode 100644 index 00000000000..8a108d7366d --- /dev/null +++ b/compiler/testData/ir/irText/expressions/whenWithSubjectVariable.fir.kt.txt @@ -0,0 +1,17 @@ +fun foo(): Any { + return 1 +} + +fun test(): Int { + return { // BLOCK + val y: Any = foo() + when { + EQEQ(arg0 = y, arg1 = 42) -> 1 + y is String -> y /*as String */.() + y !is Int -> 2 + error("") /* ERROR CALL */y; -> 3 + error("") /* ERROR CALL */y; .not() -> 4 + else -> -1 + } + } +} diff --git a/compiler/testData/ir/irText/expressions/whileDoWhile.fir.kt.txt b/compiler/testData/ir/irText/expressions/whileDoWhile.fir.kt.txt new file mode 100644 index 00000000000..89dd728143d --- /dev/null +++ b/compiler/testData/ir/irText/expressions/whileDoWhile.fir.kt.txt @@ -0,0 +1,39 @@ +fun test() { + var x: Int = 0 + while (less(arg0 = x, arg1 = 0)) { // BLOCK + } + while (less(arg0 = x, arg1 = 5)) { // BLOCK + val : Int = x + x = .inc() + + } + while (less(arg0 = x, arg1 = 10)) { // BLOCK + val : Int = x + x = .inc() + + } + do// COMPOSITE { + // } while (less(arg0 = x, arg1 = 0)) + do{ // BLOCK + val : Int = x + x = .inc() + + } while (less(arg0 = x, arg1 = 15)) + do// COMPOSITE { + val : Int = x + x = .inc() + + // } while (less(arg0 = x, arg1 = 20)) +} + +fun testSmartcastInCondition() { + val a: Any? = null + when { + a is Boolean -> { // BLOCK + while (a /*as Boolean */) { // BLOCK + } + do// COMPOSITE { + // } while (a /*as Boolean */) + } + } +} diff --git a/compiler/testData/ir/irText/firProblems/AbstractMutableMap.fir.kt.txt b/compiler/testData/ir/irText/firProblems/AbstractMutableMap.fir.kt.txt new file mode 100644 index 00000000000..f4df9b24968 --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/AbstractMutableMap.fir.kt.txt @@ -0,0 +1,17 @@ +class MyMap : AbstractMutableMap { + constructor() /* primary */ { + super/*AbstractMutableMap*/() + /* () */ + + } + + override fun put(key: K, value: V): V? { + return null + } + + override val entries: MutableSet> + override get(): MutableSet> { + return mutableSetOf>() + } + +} diff --git a/compiler/testData/ir/irText/firProblems/AllCandidates.fir.kt.txt b/compiler/testData/ir/irText/firProblems/AllCandidates.fir.kt.txt new file mode 100644 index 00000000000..7b048f664b7 --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/AllCandidates.fir.kt.txt @@ -0,0 +1,31 @@ +class ResolvedCall { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +class MyCandidate { + constructor(resolvedCall: ResolvedCall<*>) /* primary */ { + super/*Any*/() + /* () */ + + } + + val resolvedCall: ResolvedCall<*> + field = resolvedCall + get + +} + +private fun allCandidatesResult(allCandidates: Collection): OverloadResolutionResultsImpl? { + return nameNotFound().apply?>(block = local fun OverloadResolutionResultsImpl?.() { + .setAllCandidates(allCandidates = allCandidates.map>(transform = local fun (it: MyCandidate): ResolvedCall { + return it.() as ResolvedCall + } +)) + } +) +} diff --git a/compiler/testData/ir/irText/firProblems/AnnotationInAnnotation.fir.kt.txt b/compiler/testData/ir/irText/firProblems/AnnotationInAnnotation.fir.kt.txt new file mode 100644 index 00000000000..e5d0f36e470 --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/AnnotationInAnnotation.fir.kt.txt @@ -0,0 +1,29 @@ +annotation class Storage : Annotation { + constructor(value: String) /* primary */ + val value: String + field = value + get + +} + +annotation class State : Annotation { + constructor(name: String, storages: Array) /* primary */ + val name: String + field = name + get + + val storages: Array + field = storages + get + +} + +@State(name = "1", storages = [Storage(value = "HELLO")]) +class Test { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} diff --git a/compiler/testData/ir/irText/firProblems/BaseFirBuilder.fir.kt.txt b/compiler/testData/ir/irText/firProblems/BaseFirBuilder.fir.kt.txt new file mode 100644 index 00000000000..e40fd82c215 --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/BaseFirBuilder.fir.kt.txt @@ -0,0 +1,12 @@ +abstract class BaseFirBuilder { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + inline fun withCapturedTypeParameters(block: Function0): T { + return block.invoke() + } + +} diff --git a/compiler/testData/ir/irText/firProblems/ClashResolutionDescriptor.fir.kt.txt b/compiler/testData/ir/irText/firProblems/ClashResolutionDescriptor.fir.kt.txt new file mode 100644 index 00000000000..fa763a44d20 --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/ClashResolutionDescriptor.fir.kt.txt @@ -0,0 +1,62 @@ +interface ComponentContainer { + +} + +interface PlatformSpecificExtension> { + +} + +interface ComponentDescriptor { + +} + +abstract class PlatformExtensionsClashResolver> { + constructor(applicableTo: Class) /* primary */ { + super/*Any*/() + /* () */ + + } + + val applicableTo: Class + field = applicableTo + get + +} + +class ClashResolutionDescriptor> { + constructor(container: ComponentContainer, resolver: PlatformExtensionsClashResolver, clashedComponents: List) /* primary */ { + super/*Any*/() + /* () */ + + } + + private val resolver: PlatformExtensionsClashResolver + field = resolver + private get + + private val clashedComponents: List + field = clashedComponents + private get + +} + +private val registrationMap: HashMap + field = hashMapOf() + private get + +fun resolveClashesIfAny(container: ComponentContainer, clashResolvers: List>) { + { // BLOCK + val : Iterator> = clashResolvers.iterator() + while (.hasNext()) { // BLOCK + val resolver: PlatformExtensionsClashResolver<*> = .next() + val clashedComponents: Collection = { // BLOCK + val : Collection? = ().get(p0 = resolver.()) as? Collection + when { + EQEQ(arg0 = , arg1 = null) -> continue + else -> /*as Collection */ + } + } + val substituteDescriptor: ClashResolutionDescriptor>>>>> = ClashResolutionDescriptor>>>>>(container = container, resolver = resolver, clashedComponents = clashedComponents.toList()) + } + } +} diff --git a/compiler/testData/ir/irText/firProblems/DeepCopyIrTree.fir.kt.txt b/compiler/testData/ir/irText/firProblems/DeepCopyIrTree.fir.kt.txt new file mode 100644 index 00000000000..fcf25423542 --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/DeepCopyIrTree.fir.kt.txt @@ -0,0 +1,77 @@ +interface IrType { + +} + +interface TypeRemapper { + abstract fun enterScope(irTypeParametersContainer: IrTypeParametersContainer) + abstract fun remapType(type: IrType): IrType + abstract fun leaveScope() + +} + +interface IrTypeParametersContainer : IrDeclaration, IrDeclarationParent { + abstract var typeParameters: List + abstract get + abstract set + +} + +interface IrDeclaration { + +} + +interface IrTypeParameter : IrDeclaration { + abstract val superTypes: MutableList + abstract get + +} + +interface IrDeclarationParent { + +} + +class DeepCopyIrTreeWithSymbols { + constructor(typeRemapper: TypeRemapper) /* primary */ { + super/*Any*/() + /* () */ + + } + + private val typeRemapper: TypeRemapper + field = typeRemapper + private get + + private fun copyTypeParameter(declaration: IrTypeParameter): IrTypeParameter { + return declaration + } + + fun IrTypeParametersContainer.copyTypeParametersFrom(other: IrTypeParametersContainer) { + .( = other.().map(transform = local fun (it: IrTypeParameter): IrTypeParameter { + return .copyTypeParameter(declaration = it) + } +)) + .().withinScope(irTypeParametersContainer = , fn = local fun () { + { // BLOCK + val : Iterator> = .().zip(other = other.()).iterator() + while (.hasNext()) { // BLOCK + val : Pair = .next() + val thisTypeParameter: IrTypeParameter = .component1() + val otherTypeParameter: IrTypeParameter = .component2() + otherTypeParameter.().mapTo>(destination = thisTypeParameter.(), transform = local fun (it: IrType): IrType { + return .().remapType(type = it) + } +) + } + } + } +) + } + +} + +inline fun TypeRemapper.withinScope(irTypeParametersContainer: IrTypeParametersContainer, fn: Function0): T { + .enterScope(irTypeParametersContainer = irTypeParametersContainer) + val result: T = fn.invoke() + .leaveScope() + return result +} diff --git a/compiler/testData/ir/irText/firProblems/DelegationAndInheritanceFromJava.fir.kt.txt b/compiler/testData/ir/irText/firProblems/DelegationAndInheritanceFromJava.fir.kt.txt new file mode 100644 index 00000000000..fca16e0cd8d --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/DelegationAndInheritanceFromJava.fir.kt.txt @@ -0,0 +1,60 @@ +class Impl : A, B { + constructor(b: B) /* primary */ { + super/*Any*/() + /* () */ + + .#<$$delegate_0> = b + } + + override fun add(element: String?): Boolean { + return .#<$$delegate_0>.add(element = element) + } + + override fun addAll(elements: Collection): Boolean { + return .#<$$delegate_0>.addAll(elements = elements) + } + + override fun clear() { + .#<$$delegate_0>.clear() + } + + override operator fun iterator(): MutableIterator { + return .#<$$delegate_0>.iterator() + } + + override fun remove(element: String?): Boolean { + return .#<$$delegate_0>.remove(element = element) + } + + override fun removeAll(elements: Collection): Boolean { + return .#<$$delegate_0>.removeAll(elements = elements) + } + + override fun retainAll(elements: Collection): Boolean { + return .#<$$delegate_0>.retainAll(elements = elements) + } + + override operator fun contains(element: String?): Boolean { + return .#<$$delegate_0>.contains(element = element) + } + + override fun containsAll(elements: Collection): Boolean { + return .#<$$delegate_0>.containsAll(elements = elements) + } + + override fun isEmpty(): Boolean { + return .#<$$delegate_0>.isEmpty() + } + + override val size: Int + override get(): Int { + return .#<$$delegate_0>.() + } + + local /*final field*/ val <$$delegate_0>: B + +} + +fun box(): String { + return "OK" +} diff --git a/compiler/testData/ir/irText/firProblems/FirBuilder.fir.kt.txt b/compiler/testData/ir/irText/firProblems/FirBuilder.fir.kt.txt new file mode 100644 index 00000000000..62fa200f594 --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/FirBuilder.fir.kt.txt @@ -0,0 +1,17 @@ +open class BaseConverter : BaseFirBuilder { + constructor() /* primary */ { + super/*BaseFirBuilder*/() + /* () */ + + } + +} + +class DeclarationsConverter : BaseConverter { + constructor() /* primary */ { + super/*BaseConverter*/() + /* () */ + + } + +} diff --git a/compiler/testData/ir/irText/firProblems/InnerClassInAnonymous.fir.kt.txt b/compiler/testData/ir/irText/firProblems/InnerClassInAnonymous.fir.kt.txt new file mode 100644 index 00000000000..ed7485eda9e --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/InnerClassInAnonymous.fir.kt.txt @@ -0,0 +1,49 @@ +fun box(): String { + val obj: = { // BLOCK + local class { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + val end: String + field = "K" + get + + fun foo(): String { + return .Some(s = "O").bar() + } + + local inner class Some : Base { + constructor(s: String) /* primary */ { + .super/*Base*/(s = s) + /* () */ + + } + + fun bar(): String { + return .().plus(other = .()) + } + + } + + local open inner class Base { + constructor(s: String) /* primary */ { + super/*Any*/() + /* () */ + + } + + val s: String + field = s + get + + } + + } + + () + } + return obj.foo() +} diff --git a/compiler/testData/ir/irText/firProblems/MultiList.fir.kt.txt b/compiler/testData/ir/irText/firProblems/MultiList.fir.kt.txt new file mode 100644 index 00000000000..7a96913bc62 --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/MultiList.fir.kt.txt @@ -0,0 +1,67 @@ +data class Some { + constructor(value: T) /* primary */ { + super/*Any*/() + /* () */ + + } + + val value: T + field = value + get + + fun component1(): T { + return .#value + } + + fun copy(value: T = .#value): Some { + return Some(value = value) + } + + override fun equals(other: Any?): Boolean { + when { + EQEQEQ(arg0 = , arg1 = other) -> return true + } + when { + other !is Some -> return false + } + val tmp0_other_with_cast: Some = other as Some + when { + EQEQ(arg0 = .#value, arg1 = tmp0_other_with_cast.#value).not() -> return false + } + return true + } + + override fun hashCode(): Int { + return when { + EQEQ(arg0 = .#value, arg1 = null) -> 0 + else -> .#value.hashCode() + } + } + + override fun toString(): String { + return "Some(" + "value=" + .#value + ")" + } + +} + +interface MyList : List> { + +} + +open class SomeList : MyList, ArrayList> { + constructor() /* primary */ { + super/*ArrayList*/>() + /* () */ + + } + +} + +class FinalList : SomeList { + constructor() /* primary */ { + super/*SomeList*/() + /* () */ + + } + +} diff --git a/compiler/testData/ir/irText/firProblems/SameJavaFieldReferences.fir.kt.txt b/compiler/testData/ir/irText/firProblems/SameJavaFieldReferences.fir.kt.txt new file mode 100644 index 00000000000..c4bde9f59c7 --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/SameJavaFieldReferences.fir.kt.txt @@ -0,0 +1,4 @@ +fun foo() { + val ref1: KProperty0 = SomeJavaClass::someJavaField/*()*/ + val ref2: KProperty0 = SomeJavaClass::someJavaField/*()*/ +} diff --git a/compiler/testData/ir/irText/firProblems/SignatureClash.fir.kt.txt b/compiler/testData/ir/irText/firProblems/SignatureClash.fir.kt.txt new file mode 100644 index 00000000000..30ecc73057c --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/SignatureClash.fir.kt.txt @@ -0,0 +1,79 @@ +typealias Some = Function1 +object Factory { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + fun foo(a: String): String { + return "Alpha" + } + + fun foo(a: String, f: Function1): String { + return "Omega" + } + +} + +interface Base { + +} + +interface Delegate : Base { + abstract fun bar() + +} + +interface Derived : Delegate { + +} + +data class DataClass : Derived, Delegate { + constructor(delegate: Delegate) /* primary */ { + super/*Any*/() + /* () */ + + .#<$$delegate_0> = delegate + } + + val delegate: Delegate + field = delegate + get + + fun component1(): Delegate { + return .#delegate + } + + fun copy(delegate: Delegate = .#delegate): DataClass { + return DataClass(delegate = delegate) + } + + override fun bar() { + .#<$$delegate_0>.bar() + } + + local /*final field*/ val <$$delegate_0>: Delegate + override fun equals(other: Any?): Boolean { + when { + EQEQEQ(arg0 = , arg1 = other) -> return true + } + when { + other !is DataClass -> return false + } + val tmp0_other_with_cast: DataClass = other as DataClass + when { + EQEQ(arg0 = .#delegate, arg1 = tmp0_other_with_cast.#delegate).not() -> return false + } + return true + } + + override fun hashCode(): Int { + return .#delegate.hashCode() + } + + override fun toString(): String { + return "DataClass(" + "delegate=" + .#delegate + ")" + } + +} diff --git a/compiler/testData/ir/irText/firProblems/candidateSymbol.fir.kt.txt b/compiler/testData/ir/irText/firProblems/candidateSymbol.fir.kt.txt new file mode 100644 index 00000000000..1214db912fa --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/candidateSymbol.fir.kt.txt @@ -0,0 +1,52 @@ +class Candidate { + constructor(symbol: AbstractFirBasedSymbol<*>) /* primary */ { + super/*Any*/() + /* () */ + + } + + val symbol: AbstractFirBasedSymbol<*> + field = symbol + get + +} + +abstract class AbstractFirBasedSymbol where E : FirSymbolOwner, E : FirDeclaration { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + lateinit var fir: E + get + set + +} + +interface FirDeclaration { + +} + +interface FirSymbolOwner where E : FirSymbolOwner, E : FirDeclaration { + abstract val symbol: AbstractFirBasedSymbol + abstract get + +} + +interface FirCallableMemberDeclaration> : FirSymbolOwner, FirDeclaration { + abstract override val symbol: AbstractFirBasedSymbol + abstract override get + +} + +fun foo(candidate: Candidate) { + val me: FirSymbolOwner>>>> = candidate.().() + when { + when { + me is FirCallableMemberDeclaration<*> -> EQEQ(arg0 = me /*as FirCallableMemberDeclaration<*> */.(), arg1 = null).not() + else -> false + } -> { // BLOCK + } + } +} diff --git a/compiler/testData/ir/irText/firProblems/coercionToUnitForNestedWhen.fir.kt.txt b/compiler/testData/ir/irText/firProblems/coercionToUnitForNestedWhen.fir.kt.txt new file mode 100644 index 00000000000..4cf9c1fb9dc --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/coercionToUnitForNestedWhen.fir.kt.txt @@ -0,0 +1,39 @@ +private const val BACKSLASH: Char + field = '\\' + private get + +private fun Reader.nextChar(): Char? { + return { // BLOCK + val tmp0_safe_receiver: Int? = .read().takeUnless(predicate = local fun (it: Int): Boolean { + return EQEQ(arg0 = it, arg1 = -1) + } +) + when { + EQEQ(arg0 = tmp0_safe_receiver, arg1 = null) -> null + else -> tmp0_safe_receiver.toChar() + } + } +} + +fun Reader.consumeRestOfQuotedSequence(sb: StringBuilder, quote: Char) { + var ch: Char? = .nextChar() + while (when { + EQEQ(arg0 = ch, arg1 = null).not() -> EQEQ(arg0 = ch /*as Char */, arg1 = quote).not() + else -> false + }) { // BLOCK + when { + EQEQ(arg0 = ch /*as Char */, arg1 = ()) -> { // BLOCK + val tmp1_safe_receiver: Char? = .nextChar() + when { + EQEQ(arg0 = tmp1_safe_receiver, arg1 = null) -> null + else -> tmp1_safe_receiver.let(block = local fun (it: Char): StringBuilder? { + return sb.append(p0 = it) + } +) + } + } + else -> sb.append(p0 = ch /*as Char */) + } /*~> Unit */ + ch = .nextChar() + } +} diff --git a/compiler/testData/ir/irText/firProblems/putIfAbsent.fir.kt.txt b/compiler/testData/ir/irText/firProblems/putIfAbsent.fir.kt.txt new file mode 100644 index 00000000000..5e4cdba83e1 --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/putIfAbsent.fir.kt.txt @@ -0,0 +1,13 @@ +class Owner { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + fun foo(x: T, y: T) { + val map: MutableMap = mutableMapOf() + map.putIfAbsent(p0 = x, p1 = y) /*~> Unit */ + } + +} diff --git a/compiler/testData/ir/irText/firProblems/recursiveCapturedTypeInPropertyReference.fir.kt.txt b/compiler/testData/ir/irText/firProblems/recursiveCapturedTypeInPropertyReference.fir.kt.txt new file mode 100644 index 00000000000..54c5833bc51 --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/recursiveCapturedTypeInPropertyReference.fir.kt.txt @@ -0,0 +1,22 @@ +interface Something { + +} + +interface Recursive where R : Recursive, R : Something { + abstract val symbol: AbstractSymbol + abstract get + +} + +abstract class AbstractSymbol where E : Recursive, E : Something { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + fun foo(list: List) { + val result: List>> = list.filterIsInstance>().map, AbstractSymbol>>(transform = Recursive::symbol) + } + +} diff --git a/compiler/testData/ir/irText/firProblems/throwableStackTrace.fir.kt.txt b/compiler/testData/ir/irText/firProblems/throwableStackTrace.fir.kt.txt new file mode 100644 index 00000000000..33e6667ac65 --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/throwableStackTrace.fir.kt.txt @@ -0,0 +1,3 @@ +fun foo(t: Throwable) { + t.setStackTrace(p0 = t.getStackTrace()) +} diff --git a/compiler/testData/ir/irText/firProblems/v8arrayToList.fir.kt.txt b/compiler/testData/ir/irText/firProblems/v8arrayToList.fir.kt.txt new file mode 100644 index 00000000000..4ce9775b538 --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/v8arrayToList.fir.kt.txt @@ -0,0 +1,14 @@ +class V8Array { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +fun box(): String { + val array: V8Array = V8Array() + val list: List = toList(array = array) as List + return list.get(index = 0) +} diff --git a/compiler/testData/ir/irText/lambdas/anonymousFunction.fir.kt.txt b/compiler/testData/ir/irText/lambdas/anonymousFunction.fir.kt.txt new file mode 100644 index 00000000000..ef19f0f61aa --- /dev/null +++ b/compiler/testData/ir/irText/lambdas/anonymousFunction.fir.kt.txt @@ -0,0 +1,6 @@ +val anonymous: Function0 + field = local fun () { + println() + } + + get diff --git a/compiler/testData/ir/irText/lambdas/destructuringInLambda.fir.kt.txt b/compiler/testData/ir/irText/lambdas/destructuringInLambda.fir.kt.txt new file mode 100644 index 00000000000..801757a9b58 --- /dev/null +++ b/compiler/testData/ir/irText/lambdas/destructuringInLambda.fir.kt.txt @@ -0,0 +1,65 @@ +data class A { + constructor(x: Int, y: Int) /* primary */ { + super/*Any*/() + /* () */ + + } + + val x: Int + field = x + get + + val y: Int + field = y + get + + fun component1(): Int { + return .#x + } + + fun component2(): Int { + return .#y + } + + fun copy(x: Int = .#x, y: Int = .#y): A { + return A(x = x, y = y) + } + + override fun equals(other: Any?): Boolean { + when { + EQEQEQ(arg0 = , arg1 = other) -> return true + } + when { + other !is A -> return false + } + val tmp0_other_with_cast: A = other as A + when { + EQEQ(arg0 = .#x, arg1 = tmp0_other_with_cast.#x).not() -> return false + } + when { + EQEQ(arg0 = .#y, arg1 = tmp0_other_with_cast.#y).not() -> return false + } + return true + } + + override fun hashCode(): Int { + var result: Int = .#x.hashCode() + result = result.times(other = 31).plus(other = .#y.hashCode()) + return result + } + + override fun toString(): String { + return "A(" + "x=" + .#x + ", " + "y=" + .#y + ")" + } + +} + +var fn: Function1 + field = local fun (: A): Int { + val _: Int = .component1() + val y: Int = .component2() + return 42.plus(other = y) + } + + get + set diff --git a/compiler/testData/ir/irText/lambdas/extensionLambda.fir.kt.txt b/compiler/testData/ir/irText/lambdas/extensionLambda.fir.kt.txt new file mode 100644 index 00000000000..46b75238fa5 --- /dev/null +++ b/compiler/testData/ir/irText/lambdas/extensionLambda.fir.kt.txt @@ -0,0 +1,6 @@ +fun test1(): Int { + return "42".run(block = local fun String.(): Int { + return .() + } +) +} diff --git a/compiler/testData/ir/irText/lambdas/localFunction.fir.kt.txt b/compiler/testData/ir/irText/lambdas/localFunction.fir.kt.txt new file mode 100644 index 00000000000..051571a5ade --- /dev/null +++ b/compiler/testData/ir/irText/lambdas/localFunction.fir.kt.txt @@ -0,0 +1,10 @@ +fun outer() { + var x: Int = 0 + local fun local() { + val : Int = x + x = .inc() + /*~> Unit */ + } + + local() +} diff --git a/compiler/testData/ir/irText/lambdas/multipleImplicitReceivers.fir.kt.txt b/compiler/testData/ir/irText/lambdas/multipleImplicitReceivers.fir.kt.txt new file mode 100644 index 00000000000..ebb433fa9a2 --- /dev/null +++ b/compiler/testData/ir/irText/lambdas/multipleImplicitReceivers.fir.kt.txt @@ -0,0 +1,45 @@ +object A { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +object B { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +interface IFoo { + val A.foo: B + get(): B { + return B + } + +} + +interface IInvoke { + operator fun B.invoke(): Int { + return 42 + } + +} + +fun test(fooImpl: IFoo, invokeImpl: IInvoke) { + with(receiver = A, block = local fun A.(): Int { + return with(receiver = fooImpl, block = local fun IFoo.(): Int { + return with(receiver = invokeImpl, block = local fun IInvoke.(): Int { + return (, (, ).()).invoke() + } +) + } +) + } +) /*~> Unit */ +} diff --git a/compiler/testData/ir/irText/lambdas/nonLocalReturn.fir.kt.txt b/compiler/testData/ir/irText/lambdas/nonLocalReturn.fir.kt.txt new file mode 100644 index 00000000000..8792fe14792 --- /dev/null +++ b/compiler/testData/ir/irText/lambdas/nonLocalReturn.fir.kt.txt @@ -0,0 +1,50 @@ +fun test0() { + run(block = local fun (): Nothing { + return Unit + } +) +} + +fun test1() { + run(block = local fun () { + return Unit + } +) +} + +fun test2() { + run(block = local fun () { + return Unit + } +) +} + +fun test3() { + run(block = local fun () { + return run(block = local fun (): Nothing { + return Unit + } +) + } +) +} + +fun testLrmFoo1(ints: List) { + ints.forEach(action = local fun (it: Int) { + when { + EQEQ(arg0 = it, arg1 = 0) -> return Unit + } + print(message = it) + } +) +} + +fun testLrmFoo2(ints: List) { + ints.forEach(action = local fun (it: Int) { + when { + EQEQ(arg0 = it, arg1 = 0) -> return Unit + } + print(message = it) + } +) +} diff --git a/compiler/testData/ir/irText/regressions/coercionInLoop.fir.kt.txt b/compiler/testData/ir/irText/regressions/coercionInLoop.fir.kt.txt new file mode 100644 index 00000000000..01ec6ae4577 --- /dev/null +++ b/compiler/testData/ir/irText/regressions/coercionInLoop.fir.kt.txt @@ -0,0 +1,14 @@ +fun box(): String { + val a: DoubleArray = DoubleArray(size = 5) + val x: DoubleIterator = a.iterator() + var i: Int = 0 + while (x.hasNext()) { // BLOCK + when { + ieee754equals(arg0 = a.get(index = i), arg1 = x.next()).not() -> return "Fail " + i.toString() + } + val : Int = i + i = .inc() + + } + return "OK" +} diff --git a/compiler/testData/ir/irText/regressions/integerCoercionToT.fir.kt.txt b/compiler/testData/ir/irText/regressions/integerCoercionToT.fir.kt.txt new file mode 100644 index 00000000000..f07bb0463ca --- /dev/null +++ b/compiler/testData/ir/irText/regressions/integerCoercionToT.fir.kt.txt @@ -0,0 +1,41 @@ +typealias CInt32Var = CInt32VarX +interface CPointed { + +} + +inline fun CPointed.reinterpret(): T { + return TODO() +} + +class CInt32VarX : CPointed { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +var CInt32VarX.value: T_INT + get(): T_INT { + return TODO() + } + set(value: T_INT) { + } + +class IdType : CPointed { + constructor(value: Int) /* primary */ { + super/*Any*/() + /* () */ + + } + + val value: Int + field = value + get + +} + +fun foo(value: IdType, cv: CInt32VarX) { + cv.(value = value.()) +} diff --git a/compiler/testData/ir/irText/regressions/kt24114.fir.kt.txt b/compiler/testData/ir/irText/regressions/kt24114.fir.kt.txt new file mode 100644 index 00000000000..ea17afbee5a --- /dev/null +++ b/compiler/testData/ir/irText/regressions/kt24114.fir.kt.txt @@ -0,0 +1,37 @@ +fun one(): Int { + return 1 +} + +fun two(): Int { + return 2 +} + +fun test1(): Int { + while (true) { // BLOCK + val tmp0_subject: Int = one() + when { + EQEQ(arg0 = tmp0_subject, arg1 = 1) -> { // BLOCK + val tmp1_subject: Int = two() + when { + EQEQ(arg0 = tmp1_subject, arg1 = 2) -> return 2 + } + } + else -> return 3 + } + } +} + +fun test2(): Int { + while (true) { // BLOCK + val tmp2_subject: Int = one() + when { + EQEQ(arg0 = tmp2_subject, arg1 = 1) -> { // BLOCK + val tmp3_subject: Int = two() + when { + EQEQ(arg0 = tmp3_subject, arg1 = 2) -> return 2 + } + } + else -> return 3 + } + } +} diff --git a/compiler/testData/ir/irText/regressions/newInference/fixationOrder1.fir.kt.txt b/compiler/testData/ir/irText/regressions/newInference/fixationOrder1.fir.kt.txt new file mode 100644 index 00000000000..6ae5f6007b2 --- /dev/null +++ b/compiler/testData/ir/irText/regressions/newInference/fixationOrder1.fir.kt.txt @@ -0,0 +1,20 @@ +fun foo(): Function1 { + return TODO() +} + +interface Inv2 { + +} + +fun check(x: T, y: R, f: Function1): Inv2 { + return TODO() +} + +fun test(): Inv2 { + return check(x = "", y = 1, f = foo()) +} + +fun box(): String { + val x: Inv2 = test() + return "OK" +} diff --git a/compiler/testData/ir/irText/regressions/typeAliasCtorForGenericClass.fir.kt.txt b/compiler/testData/ir/irText/regressions/typeAliasCtorForGenericClass.fir.kt.txt new file mode 100644 index 00000000000..4a917e950bc --- /dev/null +++ b/compiler/testData/ir/irText/regressions/typeAliasCtorForGenericClass.fir.kt.txt @@ -0,0 +1,19 @@ +typealias B = A +typealias B2 = A> +class A { + constructor(q: Q) /* primary */ { + super/*Any*/() + /* () */ + + } + + val q: Q + field = q + get + +} + +fun bar() { + val b: A = A(q = 2) + val b2: A> = A(q = b) +} diff --git a/compiler/testData/ir/irText/regressions/typeParametersInImplicitCast.fir.kt.txt b/compiler/testData/ir/irText/regressions/typeParametersInImplicitCast.fir.kt.txt new file mode 100644 index 00000000000..df40c6ff4e0 --- /dev/null +++ b/compiler/testData/ir/irText/regressions/typeParametersInImplicitCast.fir.kt.txt @@ -0,0 +1,6 @@ +fun problematic(lss: List>): List { + return lss.flatMap, T>(transform = local fun (it: List): Iterable { + return id(v = it) /*!! List */ + } +) +} diff --git a/compiler/testData/ir/irText/singletons/enumEntry.fir.kt.txt b/compiler/testData/ir/irText/singletons/enumEntry.fir.kt.txt new file mode 100644 index 00000000000..29498bc733d --- /dev/null +++ b/compiler/testData/ir/irText/singletons/enumEntry.fir.kt.txt @@ -0,0 +1,38 @@ +open enum class Z : Enum { + private constructor() /* primary */ { + super/*Enum*/() + /* () */ + + } + + ENTRY = ENTRY() + private enum entry class ENTRY : Z { + private constructor() /* primary */ { + super/*Z*/() + /* () */ + + } + + fun test() { + } + + inner class A { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + fun test2() { + .test() + } + + } + + } + + fun values(): Array /* Synthetic body for ENUM_VALUES */ + + fun valueOf(value: String): Z /* Synthetic body for ENUM_VALUEOF */ + +} diff --git a/compiler/testData/ir/irText/stubs/builtinMap.fir.kt.txt b/compiler/testData/ir/irText/stubs/builtinMap.fir.kt.txt new file mode 100644 index 00000000000..98510fbd27f --- /dev/null +++ b/compiler/testData/ir/irText/stubs/builtinMap.fir.kt.txt @@ -0,0 +1,9 @@ +fun Map.plus(pair: Pair): Map { + return when { + .isEmpty() -> mapOf(pair = pair) + else -> LinkedHashMap(p0 = ).apply>(block = local fun LinkedHashMap.() { + return .put(p0 = pair.(), p1 = pair.()) /*~> Unit */ + } +) + } +} diff --git a/compiler/testData/ir/irText/stubs/genericClassInDifferentModule_m1.fir.kt.txt b/compiler/testData/ir/irText/stubs/genericClassInDifferentModule_m1.fir.kt.txt new file mode 100644 index 00000000000..75c23ef42be --- /dev/null +++ b/compiler/testData/ir/irText/stubs/genericClassInDifferentModule_m1.fir.kt.txt @@ -0,0 +1,21 @@ +abstract class Base { + constructor(x: T) /* primary */ { + super/*Any*/() + /* () */ + + } + + val x: T + field = x + get + + abstract fun foo(y: Y): T + abstract var bar: T + abstract get + abstract set + + abstract var Z.exn: T + abstract get + abstract set + +} diff --git a/compiler/testData/ir/irText/stubs/genericClassInDifferentModule_m2.fir.kt.txt b/compiler/testData/ir/irText/stubs/genericClassInDifferentModule_m2.fir.kt.txt new file mode 100644 index 00000000000..09a09d03532 --- /dev/null +++ b/compiler/testData/ir/irText/stubs/genericClassInDifferentModule_m2.fir.kt.txt @@ -0,0 +1,24 @@ +class Derived1 : Base { + constructor(x: T) /* primary */ { + super/*Base*/(x = x) + /* () */ + + } + + override fun foo(y: Y): T { + return .() + } + + override var bar: T + field = x + override get + override set + + override var Z.exn: T + override get(): T { + return .() + } + override set(value: T) { + } + +} diff --git a/compiler/testData/ir/irText/stubs/javaConstructorWithTypeParameters.fir.kt.txt b/compiler/testData/ir/irText/stubs/javaConstructorWithTypeParameters.fir.kt.txt new file mode 100644 index 00000000000..cc8b41cd181 --- /dev/null +++ b/compiler/testData/ir/irText/stubs/javaConstructorWithTypeParameters.fir.kt.txt @@ -0,0 +1,15 @@ +fun test1(): J1 { + return J1() +} + +fun test2(): J1 { + return J1(x1 = 1) +} + +fun test3(j1: J1): J2 { + return j1.J2() +} + +fun test4(j1: J1): J2 { + return j1.J2(x2 = 1) +} diff --git a/compiler/testData/ir/irText/stubs/javaEnum.fir.kt.txt b/compiler/testData/ir/irText/stubs/javaEnum.fir.kt.txt new file mode 100644 index 00000000000..1bd552f2499 --- /dev/null +++ b/compiler/testData/ir/irText/stubs/javaEnum.fir.kt.txt @@ -0,0 +1,3 @@ +val test: @FlexibleNullability JEnum + field = JEnum.ONE + get diff --git a/compiler/testData/ir/irText/stubs/javaInnerClass.fir.kt.txt b/compiler/testData/ir/irText/stubs/javaInnerClass.fir.kt.txt new file mode 100644 index 00000000000..e2eb3738043 --- /dev/null +++ b/compiler/testData/ir/irText/stubs/javaInnerClass.fir.kt.txt @@ -0,0 +1,12 @@ +class Test1 : J { + constructor() /* primary */ { + super/*J*/() + /* () */ + + } + + val test: JInner + field = .JInner() + get + +} diff --git a/compiler/testData/ir/irText/stubs/javaSyntheticProperty.fir.kt.txt b/compiler/testData/ir/irText/stubs/javaSyntheticProperty.fir.kt.txt new file mode 100644 index 00000000000..51f64ae6b60 --- /dev/null +++ b/compiler/testData/ir/irText/stubs/javaSyntheticProperty.fir.kt.txt @@ -0,0 +1,3 @@ +val test: String? + field = J().getFoo() + get diff --git a/compiler/testData/ir/irText/stubs/jdkClassSyntheticProperty.fir.kt.txt b/compiler/testData/ir/irText/stubs/jdkClassSyntheticProperty.fir.kt.txt new file mode 100644 index 00000000000..7b992fe5683 --- /dev/null +++ b/compiler/testData/ir/irText/stubs/jdkClassSyntheticProperty.fir.kt.txt @@ -0,0 +1,4 @@ +val Class<*>.test: Array? + get(): Array? { + return .getDeclaredFields() + } diff --git a/compiler/testData/ir/irText/types/abbreviatedTypes.fir.kt.txt b/compiler/testData/ir/irText/types/abbreviatedTypes.fir.kt.txt new file mode 100644 index 00000000000..4a01af01494 --- /dev/null +++ b/compiler/testData/ir/irText/types/abbreviatedTypes.fir.kt.txt @@ -0,0 +1,17 @@ +typealias I = Int +typealias L = List +fun test1(x: List): List { + return x +} + +fun test2(x: List>): List> { + return x +} + +fun test3(x: List>): List> { + return x +} + +fun test4(x: List>): List> { + return x +} diff --git a/compiler/testData/ir/irText/types/asOnPlatformType.fir.kt.txt b/compiler/testData/ir/irText/types/asOnPlatformType.fir.kt.txt new file mode 100644 index 00000000000..d79d5a6bf74 --- /dev/null +++ b/compiler/testData/ir/irText/types/asOnPlatformType.fir.kt.txt @@ -0,0 +1,16 @@ +fun test() { + val nullStr: String? = nullString() + val nonnullStr: String? = nonnullString() + nullStr.foo() /*~> Unit */ + nonnullStr.foo() /*~> Unit */ + nullStr.fooN() /*~> Unit */ + nonnullStr.fooN() /*~> Unit */ +} + +inline fun T.foo(): T { + return as T +} + +inline fun T.fooN(): T? { + return as T? +} diff --git a/compiler/testData/ir/irText/types/castsInsideCoroutineInference.fir.kt.txt b/compiler/testData/ir/irText/types/castsInsideCoroutineInference.fir.kt.txt new file mode 100644 index 00000000000..7613c9da99e --- /dev/null +++ b/compiler/testData/ir/irText/types/castsInsideCoroutineInference.fir.kt.txt @@ -0,0 +1,143 @@ +@OptIn(markerClass = [ExperimentalTypeInference::class]) +fun scopedFlow(@BuilderInference block: @ExtensionFunctionType @ExtensionFunctionType SuspendFunction2, Unit>): Flow { + return flow(block = local suspend fun FlowCollector.() { + val collector: FlowCollector = + flowScope(block = local suspend fun CoroutineScope.() { + block.invoke(p1 = , p2 = collector) + } +) + } +) +} + +fun Flow.onCompletion(action: @ExtensionFunctionType @ExtensionFunctionType SuspendFunction2, Throwable?, Unit>): Flow { + return unsafeFlow(block = local suspend fun FlowCollector.() { + val safeCollector: SafeCollector = SafeCollector(collector = ) + safeCollector.invokeSafely(action = action) + } +) +} + +suspend fun FlowCollector.invokeSafely(action: @ExtensionFunctionType @ExtensionFunctionType SuspendFunction2, Throwable?, Unit>) { +} + +@OptIn(markerClass = [ExperimentalTypeInference::class]) +inline fun unsafeFlow(@BuilderInference crossinline block: @ExtensionFunctionType @ExtensionFunctionType SuspendFunction1, Unit>): Flow { + return TODO() +} + +@Deprecated(message = "binary compatibility with a version w/o FlowCollector receiver", level = DeprecationLevel.HIDDEN) +fun Flow.onCompletion(action: SuspendFunction1): ErrorType /* ERROR */ { + return error("") /* ERROR CALL */local fun () { + action.invoke(p1 = error("") /* ERROR CALL */) + } +; +} + +private fun CoroutineScope.asFairChannel(flow: Flow<*>): ReceiveChannel { + return .produce(block = local suspend fun ProducerScope.() { + val channel: ChannelCoroutine = .() as ChannelCoroutine + flow.collect(action = local suspend fun (value: Any?) { + return channel.sendFair(element = { // BLOCK + val : Any? = value + when { + EQEQ(arg0 = , arg1 = null) -> Any() + else -> /*as Any */ + } + }) + } +) + } +) +} + +private fun CoroutineScope.asChannel(flow: Flow<*>): ReceiveChannel { + return .produce(block = local suspend fun ProducerScope.() { + flow.collect(action = local suspend fun (value: Any?) { + return .().send(e = { // BLOCK + val : Any? = value + when { + EQEQ(arg0 = , arg1 = null) -> Any() + else -> /*as Any */ + } + }) + } +) + } +) +} + +class SafeCollector : FlowCollector { + constructor(collector: FlowCollector) /* primary */ { + super/*Any*/() + /* () */ + + } + + internal val collector: FlowCollector + field = collector + internal get + + override suspend fun emit(value: T) { + } + +} + +@OptIn(markerClass = [ExperimentalTypeInference::class]) +fun flow(@BuilderInference block: @ExtensionFunctionType @ExtensionFunctionType SuspendFunction1, Unit>): Flow { + return TODO() +} + +@OptIn(markerClass = [ExperimentalTypeInference::class]) +suspend fun flowScope(@BuilderInference block: @ExtensionFunctionType @ExtensionFunctionType SuspendFunction1): R { + return TODO() +} + +suspend inline fun Flow.collect(crossinline action: SuspendFunction1) { +} + +open class ChannelCoroutine { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + suspend fun sendFair(element: E) { + } + +} + +interface CoroutineScope { + +} + +interface Flow { + abstract suspend fun collect(collector: FlowCollector) + +} + +interface FlowCollector { + abstract suspend fun emit(value: T) + +} + +interface ReceiveChannel { + +} + +@OptIn(markerClass = [ExperimentalTypeInference::class]) +fun CoroutineScope.produce(@BuilderInference block: @ExtensionFunctionType @ExtensionFunctionType SuspendFunction1, Unit>): ReceiveChannel { + return TODO() +} + +interface ProducerScope : CoroutineScope, SendChannel { + abstract val channel: SendChannel + abstract get + +} + +interface SendChannel { + abstract suspend fun send(e: E) + +} diff --git a/compiler/testData/ir/irText/types/genericDelegatedDeepProperty.fir.kt.txt b/compiler/testData/ir/irText/types/genericDelegatedDeepProperty.fir.kt.txt new file mode 100644 index 00000000000..f7ebf840dfd --- /dev/null +++ b/compiler/testData/ir/irText/types/genericDelegatedDeepProperty.fir.kt.txt @@ -0,0 +1,145 @@ +class Value> { + constructor(value1: T, value2: IT) /* primary */ { + super/*Any*/() + /* () */ + + } + + var value1: T + field = value1 + get + set + + val value2: IT + field = value2 + get + +} + +interface IDelegate1 { + abstract operator fun getValue(t: T1, p: KProperty<*>): R1 + +} + +interface IDelegate2 { + abstract operator fun getValue(t: T2, p: KProperty<*>): R2 + +} + +interface IR { + abstract fun foo(): R + +} + +class CR : IR { + constructor(r: R) /* primary */ { + super/*Any*/() + /* () */ + + } + + val r: R + field = r + get + + override fun foo(): R { + return .() + } + +} + +class P { + constructor(p1: P1, p2: P2) /* primary */ { + super/*Any*/() + /* () */ + + } + + val p1: P1 + field = p1 + get + + val p2: P2 + field = p2 + get + +} + +val Value>.additionalText: P /* by */ + field = { // BLOCK + local class : IDelegate1>, P> { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + fun qux11(t: F11T): F11T { + return t + } + + fun > qux12(t: F12T): T { + return t.foo() + } + + private val Value>.deepO: T /* by */ + field = { // BLOCK + local class : IDelegate1>, T> { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + override operator fun getValue(t: Value>, p: KProperty<*>): T { + return t.() + } + + fun qux21(t: F21T): F21T { + return t + } + + fun > qux22(t: F22T): T { + return t.foo() + } + + } + + () + } + get(): T { + return .#deepO$delegate.getValue(t = , p = ::deepO) + } + + private val Value>.deepK: T /* by */ + field = { // BLOCK + local class : IDelegate1>, T> { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + override operator fun getValue(t: Value>, p: KProperty<*>): T { + return t.().foo() + } + + } + + () + } + get(): T { + return .#deepK$delegate.getValue(t = , p = ::deepK) + } + + override operator fun getValue(t: Value>, p: KProperty<*>): P { + return P(p1 = (, t).(), p2 = (, t).()) + } + + } + + () + } + get(): P { + return #additionalText$delegate.getValue(t = , p = ::additionalText/*()*/) + } diff --git a/compiler/testData/ir/irText/types/genericFunWithStar.fir.kt.txt b/compiler/testData/ir/irText/types/genericFunWithStar.fir.kt.txt new file mode 100644 index 00000000000..71bcaecd4ee --- /dev/null +++ b/compiler/testData/ir/irText/types/genericFunWithStar.fir.kt.txt @@ -0,0 +1,29 @@ +interface IBase { + +} + +interface IFoo : IBase { + +} + +interface IBar : IBase { + +} + +interface I where G : IFoo, G : IBar { + +} + +abstract class Box : IFoo, IBar where T : IFoo, T : IBar { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + abstract fun foo(tSerializer: I): I> where F : IFoo, F : IBar + fun bar(vararg serializers: I<*>): I<*> { + return .foo(tSerializer = serializers.get(index = 0)) + } + +} diff --git a/compiler/testData/ir/irText/types/genericPropertyReferenceType.fir.kt.txt b/compiler/testData/ir/irText/types/genericPropertyReferenceType.fir.kt.txt new file mode 100644 index 00000000000..4a847278e99 --- /dev/null +++ b/compiler/testData/ir/irText/types/genericPropertyReferenceType.fir.kt.txt @@ -0,0 +1,33 @@ +class C { + constructor(x: T) /* primary */ { + super/*Any*/() + /* () */ + + } + + var x: T + field = x + get + set + +} + +var C.y: T + get(): T { + return .() + } + set(v: T) { + .( = v) + } + +fun use(p: KMutableProperty) { +} + +fun test1() { + use(p = C(x = "abc")::y/*()*/) +} + +fun test2(a: Any) { + a as C /*~> Unit */ + use(p = a /*as C */::y/*()*/) +} diff --git a/compiler/testData/ir/irText/types/intersectionType1_NI.fir.kt.txt b/compiler/testData/ir/irText/types/intersectionType1_NI.fir.kt.txt new file mode 100644 index 00000000000..654a8722f94 --- /dev/null +++ b/compiler/testData/ir/irText/types/intersectionType1_NI.fir.kt.txt @@ -0,0 +1,26 @@ +class In { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +fun select(x: S, y: S): S { + return x +} + +fun foo(a: Array>, b: Array>): Boolean { + return select>>(x = a, y = b).get(index = 0).ofType(y = true) +} + +inline fun In.ofType(y: Any?): Boolean { + return y is K +} + +fun test() { + val a1: Array> = arrayOf>(elements = [In()]) + val a2: Array> = arrayOf>(elements = [In()]) + foo(a = a1, b = a2) /*~> Unit */ +} diff --git a/compiler/testData/ir/irText/types/intersectionType1_OI.fir.kt.txt b/compiler/testData/ir/irText/types/intersectionType1_OI.fir.kt.txt new file mode 100644 index 00000000000..654a8722f94 --- /dev/null +++ b/compiler/testData/ir/irText/types/intersectionType1_OI.fir.kt.txt @@ -0,0 +1,26 @@ +class In { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +fun select(x: S, y: S): S { + return x +} + +fun foo(a: Array>, b: Array>): Boolean { + return select>>(x = a, y = b).get(index = 0).ofType(y = true) +} + +inline fun In.ofType(y: Any?): Boolean { + return y is K +} + +fun test() { + val a1: Array> = arrayOf>(elements = [In()]) + val a2: Array> = arrayOf>(elements = [In()]) + foo(a = a1, b = a2) /*~> Unit */ +} diff --git a/compiler/testData/ir/irText/types/intersectionType2_NI.fir.kt.txt b/compiler/testData/ir/irText/types/intersectionType2_NI.fir.kt.txt new file mode 100644 index 00000000000..5c3a035fec9 --- /dev/null +++ b/compiler/testData/ir/irText/types/intersectionType2_NI.fir.kt.txt @@ -0,0 +1,42 @@ +interface A { + +} + +interface Foo { + +} + +open class B : Foo, A { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +open class C : Foo, A { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +fun run(fn: Function0): T { + return fn.invoke() +} + +fun foo(): Any { + return run(fn = local fun (): Foo { + val mm: B = B() + val nn: C = C() + val c: Foo = when { + true -> mm + else -> nn + } + return c + } +) +} diff --git a/compiler/testData/ir/irText/types/intersectionType2_OI.fir.kt.txt b/compiler/testData/ir/irText/types/intersectionType2_OI.fir.kt.txt new file mode 100644 index 00000000000..5c3a035fec9 --- /dev/null +++ b/compiler/testData/ir/irText/types/intersectionType2_OI.fir.kt.txt @@ -0,0 +1,42 @@ +interface A { + +} + +interface Foo { + +} + +open class B : Foo, A { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +open class C : Foo, A { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +fun run(fn: Function0): T { + return fn.invoke() +} + +fun foo(): Any { + return run(fn = local fun (): Foo { + val mm: B = B() + val nn: C = C() + val c: Foo = when { + true -> mm + else -> nn + } + return c + } +) +} diff --git a/compiler/testData/ir/irText/types/intersectionType3_NI.fir.kt.txt b/compiler/testData/ir/irText/types/intersectionType3_NI.fir.kt.txt new file mode 100644 index 00000000000..92532b9cf0f --- /dev/null +++ b/compiler/testData/ir/irText/types/intersectionType3_NI.fir.kt.txt @@ -0,0 +1,63 @@ +interface In { + +} + +inline fun In.isT(): Boolean { + return is T +} + +inline fun In.asT() { + as T /*~> Unit */ +} + +fun sel(x: S, y: S): S { + return x +} + +interface A { + +} + +interface B { + +} + +interface A1 : A { + +} + +interface A2 : A { + +} + +interface Z1 : A, B { + +} + +interface Z2 : A, B { + +} + +fun testInIs1(x: In, y: In): Boolean { + return sel>(x = x, y = y).isT() +} + +fun testInIs2(x: In, y: In): Boolean { + return sel>(x = x, y = y).isT() +} + +fun testInIs3(x: In, y: In): Boolean { + return sel>(x = x, y = y).isT() +} + +fun testInAs1(x: In, y: In) { + return sel>(x = x, y = y).asT() +} + +fun testInAs2(x: In, y: In) { + return sel>(x = x, y = y).asT() +} + +fun testInAs3(x: In, y: In) { + return sel>(x = x, y = y).asT() +} diff --git a/compiler/testData/ir/irText/types/intersectionType3_OI.fir.kt.txt b/compiler/testData/ir/irText/types/intersectionType3_OI.fir.kt.txt new file mode 100644 index 00000000000..92532b9cf0f --- /dev/null +++ b/compiler/testData/ir/irText/types/intersectionType3_OI.fir.kt.txt @@ -0,0 +1,63 @@ +interface In { + +} + +inline fun In.isT(): Boolean { + return is T +} + +inline fun In.asT() { + as T /*~> Unit */ +} + +fun sel(x: S, y: S): S { + return x +} + +interface A { + +} + +interface B { + +} + +interface A1 : A { + +} + +interface A2 : A { + +} + +interface Z1 : A, B { + +} + +interface Z2 : A, B { + +} + +fun testInIs1(x: In, y: In): Boolean { + return sel>(x = x, y = y).isT() +} + +fun testInIs2(x: In, y: In): Boolean { + return sel>(x = x, y = y).isT() +} + +fun testInIs3(x: In, y: In): Boolean { + return sel>(x = x, y = y).isT() +} + +fun testInAs1(x: In, y: In) { + return sel>(x = x, y = y).asT() +} + +fun testInAs2(x: In, y: In) { + return sel>(x = x, y = y).asT() +} + +fun testInAs3(x: In, y: In) { + return sel>(x = x, y = y).asT() +} diff --git a/compiler/testData/ir/irText/types/javaWildcardType.fir.kt.txt b/compiler/testData/ir/irText/types/javaWildcardType.fir.kt.txt new file mode 100644 index 00000000000..cf408d1cdea --- /dev/null +++ b/compiler/testData/ir/irText/types/javaWildcardType.fir.kt.txt @@ -0,0 +1,53 @@ +interface K { + abstract fun kf1(): Collection + abstract fun kf2(): Collection + abstract fun kg1(c: Collection) + abstract fun kg2(c: Collection) + +} + +class C : J, K { + constructor(j: J, k: K) /* primary */ { + super/*Any*/() + /* () */ + + .#<$$delegate_0> = j + .#<$$delegate_1> = k + } + + override fun jf1(): Collection? { + return .#<$$delegate_0>.jf1() + } + + override fun jf2(): Collection? { + return .#<$$delegate_0>.jf2() + } + + override fun jg1(c: Collection?) { + .#<$$delegate_0>.jg1(c = c) + } + + override fun jg2(c: Collection?) { + .#<$$delegate_0>.jg2(c = c) + } + + local /*final field*/ val <$$delegate_0>: J + override fun kf1(): Collection { + return .#<$$delegate_1>.kf1() + } + + override fun kf2(): Collection { + return .#<$$delegate_1>.kf2() + } + + override fun kg1(c: Collection) { + .#<$$delegate_1>.kg1(c = c) + } + + override fun kg2(c: Collection) { + .#<$$delegate_1>.kg2(c = c) + } + + local /*final field*/ val <$$delegate_1>: K + +} diff --git a/compiler/testData/ir/irText/types/localVariableOfIntersectionType_NI.fir.kt.txt b/compiler/testData/ir/irText/types/localVariableOfIntersectionType_NI.fir.kt.txt new file mode 100644 index 00000000000..b1cd9cd8e15 --- /dev/null +++ b/compiler/testData/ir/irText/types/localVariableOfIntersectionType_NI.fir.kt.txt @@ -0,0 +1,32 @@ +interface In { + +} + +interface Inv { + abstract val t: T + abstract get + +} + +interface Z { + abstract fun create(x: In, y: In): Inv + +} + +interface IA { + abstract fun foo() + +} + +interface IB { + abstract fun bar() + +} + +fun test(a: In, b: In, z: Z) { + z.create(x = a, y = b).().foo() + z.create(x = a, y = b).().bar() + val t: IA = z.create(x = a, y = b).() + t.foo() + t.bar() +} diff --git a/compiler/testData/ir/irText/types/nullChecks/enhancedNullability.fir.kt.txt b/compiler/testData/ir/irText/types/nullChecks/enhancedNullability.fir.kt.txt new file mode 100644 index 00000000000..a7dcb33a84d --- /dev/null +++ b/compiler/testData/ir/irText/types/nullChecks/enhancedNullability.fir.kt.txt @@ -0,0 +1,35 @@ +fun use(s: String) { +} + +fun testUse() { + use(s = notNullString() /*!! String */) +} + +fun testLocalVal() { + val local: String = notNullString() /*!! String */ +} + +fun testReturnValue(): String { + return notNullString() /*!! String */ +} + +val testGlobalVal: String + field = notNullString() /*!! String */ + get + +val testGlobalValGetter: String + get(): String { + return notNullString() /*!! String */ + } + +fun testJUse() { + use(s = nullString()) + use(s = notNullString()) +} + +fun testLocalVarUse() { + val ns: String? = nullString() + use(s = ns) + val nns: String = notNullString() /*!! String */ + use(s = nns) +} diff --git a/compiler/testData/ir/irText/types/nullChecks/enhancedNullabilityInDestructuringAssignment.fir.kt.txt b/compiler/testData/ir/irText/types/nullChecks/enhancedNullabilityInDestructuringAssignment.fir.kt.txt new file mode 100644 index 00000000000..e9c15dc1d1e --- /dev/null +++ b/compiler/testData/ir/irText/types/nullChecks/enhancedNullabilityInDestructuringAssignment.fir.kt.txt @@ -0,0 +1,87 @@ +fun use(x: Any, y: Any) { +} + +class P { + constructor(x: Int, y: Int) /* primary */ { + super/*Any*/() + /* () */ + + } + + val x: Int + field = x + get + + val y: Int + field = y + get + + operator fun component1(): Int { + return .() + } + + operator fun component2(): Int { + return .() + } + +} + +class Q { + constructor(x: T1, y: T2) /* primary */ { + super/*Any*/() + /* () */ + + } + + val x: T1 + field = x + get + + val y: T2 + field = y + get + + operator fun component1(): T1 { + return .() + } + + operator fun component2(): T2 { + return .() + } + +} + +fun test1() { + val : P = notNullP() /*!! P */ + val x: Int = .component1() + val y: Int = .component2() + use(x = x, y = y) +} + +fun test2() { + val : Q<@FlexibleNullability String, String?>? = notNullComponents() + val x: @FlexibleNullability String = .component1() + val y: String? = .component2() + use(x = x, y = y /*!! String */) +} + +fun test2Desugared() { + val tmp: Q<@FlexibleNullability String, String?>? = notNullComponents() + val x: @FlexibleNullability String = tmp.component1() + val y: String? = tmp.component2() + use(x = x, y = y /*!! String */) +} + +fun test3() { + val : Q<@FlexibleNullability String, String?> = notNullQAndComponents() /*!! Q<@FlexibleNullability String, String?> */ + val x: @FlexibleNullability String = .component1() + val y: String? = .component2() + use(x = x, y = y /*!! String */) +} + +fun test4() { + val : IndexedValue = listOfNotNull().withIndex().first>() + val x: Int = .component1() + val y: P? = .component2() + use(x = x, y = y /*!! P */) +} diff --git a/compiler/testData/ir/irText/types/nullChecks/enhancedNullabilityInForLoop.fir.kt.txt b/compiler/testData/ir/irText/types/nullChecks/enhancedNullabilityInForLoop.fir.kt.txt new file mode 100644 index 00000000000..d450046e42d --- /dev/null +++ b/compiler/testData/ir/irText/types/nullChecks/enhancedNullabilityInForLoop.fir.kt.txt @@ -0,0 +1,121 @@ +fun use(s: P) { +} + +fun testForInListUnused() { + { // BLOCK + val : MutableIterator = listOfNotNull().iterator() + while (.hasNext()) { // BLOCK + val x: P? = .next() + } + } +} + +fun testForInListDestructured() { + { // BLOCK + val : MutableIterator = listOfNotNull().iterator() + while (.hasNext()) { // BLOCK + val : P? = .next() + val x: Int = .component1() + val y: Int = .component2() + } + } +} + +fun testDesugaredForInList() { + val iterator: MutableIterator = listOfNotNull().iterator() + while (iterator.hasNext()) { // BLOCK + val x: P? = iterator.next() + } +} + +fun testForInArrayUnused(j: J) { + { // BLOCK + val : Iterator = j.arrayOfNotNull().iterator() + while (.hasNext()) { // BLOCK + val x: P? = .next() + } + } +} + +fun testForInListUse() { + { // BLOCK + val : MutableIterator = listOfNotNull().iterator() + while (.hasNext()) { // BLOCK + val x: P? = .next() + use(s = x /*!! P */) + use(s = x) + } + } +} + +fun testForInArrayUse(j: J) { + { // BLOCK + val : Iterator = j.arrayOfNotNull().iterator() + while (.hasNext()) { // BLOCK + val x: P? = .next() + use(s = x /*!! P */) + use(s = x) + } + } +} + +interface K { + abstract fun arrayOfNotNull(): Array

+ +} + +data class P { + constructor(x: Int, y: Int) /* primary */ { + super/*Any*/() + /* () */ + + } + + val x: Int + field = x + get + + val y: Int + field = y + get + + fun component1(): Int { + return .#x + } + + fun component2(): Int { + return .#y + } + + fun copy(x: Int = .#x, y: Int = .#y): P { + return P(x = x, y = y) + } + + override fun equals(other: Any?): Boolean { + when { + EQEQEQ(arg0 = , arg1 = other) -> return true + } + when { + other !is P -> return false + } + val tmp0_other_with_cast: P = other as P + when { + EQEQ(arg0 = .#x, arg1 = tmp0_other_with_cast.#x).not() -> return false + } + when { + EQEQ(arg0 = .#y, arg1 = tmp0_other_with_cast.#y).not() -> return false + } + return true + } + + override fun hashCode(): Int { + var result: Int = .#x.hashCode() + result = result.times(other = 31).plus(other = .#y.hashCode()) + return result + } + + override fun toString(): String { + return "P(" + "x=" + .#x + ", " + "y=" + .#y + ")" + } + +} diff --git a/compiler/testData/ir/irText/types/nullChecks/explicitEqualsAndCompareToCallsOnPlatformTypeReceiver.fir.kt.txt b/compiler/testData/ir/irText/types/nullChecks/explicitEqualsAndCompareToCallsOnPlatformTypeReceiver.fir.kt.txt new file mode 100644 index 00000000000..32b0c63114c --- /dev/null +++ b/compiler/testData/ir/irText/types/nullChecks/explicitEqualsAndCompareToCallsOnPlatformTypeReceiver.fir.kt.txt @@ -0,0 +1,23 @@ +fun JavaClass.testPlatformEqualsPlatform(): Boolean { + return .null0().equals(other = .null0()) +} + +fun JavaClass.testPlatformEqualsKotlin(): Boolean { + return .null0().equals(other = 0.0D) +} + +fun JavaClass.testKotlinEqualsPlatform(): Boolean { + return 0.0D.equals(other = .null0()) +} + +fun JavaClass.testPlatformCompareToPlatform(): Int { + return .null0().compareTo(other = .null0() /*!! Double */) +} + +fun JavaClass.testPlatformCompareToKotlin(): Int { + return .null0().compareTo(other = 0.0D) +} + +fun JavaClass.testKotlinCompareToPlatform(): Int { + return 0.0D.compareTo(other = .null0() /*!! Double */) +} diff --git a/compiler/testData/ir/irText/types/nullChecks/implicitNotNullOnPlatformType.fir.kt.txt b/compiler/testData/ir/irText/types/nullChecks/implicitNotNullOnPlatformType.fir.kt.txt new file mode 100644 index 00000000000..cb7cf8d81b9 --- /dev/null +++ b/compiler/testData/ir/irText/types/nullChecks/implicitNotNullOnPlatformType.fir.kt.txt @@ -0,0 +1,42 @@ +fun f(s: String) { +} + +class MySet : Set { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + override val size: Int + override get(): Int { + return TODO() + } + + override operator fun contains(element: String): Boolean { + return TODO() + } + + override fun containsAll(elements: Collection): Boolean { + return TODO() + } + + override fun isEmpty(): Boolean { + return TODO() + } + + override operator fun iterator(): Iterator { + return TODO() + } + +} + +fun test() { + f(s = s() /*!! String */) + f(s = #STRING /*!! String */) +} + +fun testContains(m: MySet) { + m.contains(element = #STRING /*!! String */) /*~> Unit */ + m.contains(element = "abc") /*~> Unit */ +} diff --git a/compiler/testData/ir/irText/types/nullChecks/nullCheckOnLambdaResult/stringVsT.fir.kt.txt b/compiler/testData/ir/irText/types/nullChecks/nullCheckOnLambdaResult/stringVsT.fir.kt.txt new file mode 100644 index 00000000000..98dece364c2 --- /dev/null +++ b/compiler/testData/ir/irText/types/nullChecks/nullCheckOnLambdaResult/stringVsT.fir.kt.txt @@ -0,0 +1,10 @@ +fun useT(fn: Function0): T { + return fn.invoke() +} + +fun testNoNullCheck() { + useT(fn = local fun (): String? { + return string() + } +) /*~> Unit */ +} diff --git a/compiler/testData/ir/irText/types/nullChecks/nullCheckOnLambdaResult/stringVsTAny.fir.kt.txt b/compiler/testData/ir/irText/types/nullChecks/nullCheckOnLambdaResult/stringVsTAny.fir.kt.txt new file mode 100644 index 00000000000..c0ce810e64c --- /dev/null +++ b/compiler/testData/ir/irText/types/nullChecks/nullCheckOnLambdaResult/stringVsTAny.fir.kt.txt @@ -0,0 +1,10 @@ +fun useTAny(fn: Function0): T { + return fn.invoke() +} + +fun testNoNullCheck() { + useTAny(fn = local fun (): String? { + return string() + } +) /*~> Unit */ +} diff --git a/compiler/testData/ir/irText/types/nullChecks/nullCheckOnLambdaResult/stringVsTConstrained.fir.kt.txt b/compiler/testData/ir/irText/types/nullChecks/nullCheckOnLambdaResult/stringVsTConstrained.fir.kt.txt new file mode 100644 index 00000000000..f32e62d9a75 --- /dev/null +++ b/compiler/testData/ir/irText/types/nullChecks/nullCheckOnLambdaResult/stringVsTConstrained.fir.kt.txt @@ -0,0 +1,10 @@ +fun useTConstrained(xs: Array, fn: Function0): T { + return fn.invoke() +} + +fun testWithNullCheck(xs: Array) { + useTConstrained(xs = xs, fn = local fun (): String { + return string() /*!! String */ + } +) /*~> Unit */ +} diff --git a/compiler/testData/ir/irText/types/nullChecks/nullCheckOnLambdaResult/stringVsTXArray.fir.kt.txt b/compiler/testData/ir/irText/types/nullChecks/nullCheckOnLambdaResult/stringVsTXArray.fir.kt.txt new file mode 100644 index 00000000000..ab0c1e2394d --- /dev/null +++ b/compiler/testData/ir/irText/types/nullChecks/nullCheckOnLambdaResult/stringVsTXArray.fir.kt.txt @@ -0,0 +1,10 @@ +fun useTX(x: T, fn: Function0): T { + return fn.invoke() +} + +fun testNoNullCheck(xs: Array) { + useTX(x = xs, fn = local fun (): String? { + return string() + } +) /*~> Unit */ +} diff --git a/compiler/testData/ir/irText/types/nullChecks/nullCheckOnLambdaResult/stringVsTXString.fir.kt.txt b/compiler/testData/ir/irText/types/nullChecks/nullCheckOnLambdaResult/stringVsTXString.fir.kt.txt new file mode 100644 index 00000000000..29ddc0f90e3 --- /dev/null +++ b/compiler/testData/ir/irText/types/nullChecks/nullCheckOnLambdaResult/stringVsTXString.fir.kt.txt @@ -0,0 +1,10 @@ +fun useTX(x: T, fn: Function0): T { + return fn.invoke() +} + +fun testNoNullCheck() { + useTX(x = "", fn = local fun (): String? { + return string() + } +) /*~> Unit */ +} diff --git a/compiler/testData/ir/irText/types/nullChecks/nullabilityAssertionOnExtensionReceiver.fir.kt.txt b/compiler/testData/ir/irText/types/nullChecks/nullabilityAssertionOnExtensionReceiver.fir.kt.txt new file mode 100644 index 00000000000..df7c948dfc6 --- /dev/null +++ b/compiler/testData/ir/irText/types/nullChecks/nullabilityAssertionOnExtensionReceiver.fir.kt.txt @@ -0,0 +1,22 @@ +fun String.extension() { +} + +class C { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + fun String.memberExtension() { + } + +} + +fun testExt() { + s().extension() +} + +fun C.testMemberExt() { + (, s()).memberExtension() +} diff --git a/compiler/testData/ir/irText/types/nullChecks/platformTypeReceiver.fir.kt.txt b/compiler/testData/ir/irText/types/nullChecks/platformTypeReceiver.fir.kt.txt new file mode 100644 index 00000000000..69a464ef835 --- /dev/null +++ b/compiler/testData/ir/irText/types/nullChecks/platformTypeReceiver.fir.kt.txt @@ -0,0 +1,7 @@ +fun test1(): Boolean { + return #BOOL_NULL.equals(other = null) +} + +fun test2(): Boolean { + return boolNull().equals(other = null) +} diff --git a/compiler/testData/ir/irText/types/rawTypeInSignature.fir.kt.txt b/compiler/testData/ir/irText/types/rawTypeInSignature.fir.kt.txt new file mode 100644 index 00000000000..3494329f26d --- /dev/null +++ b/compiler/testData/ir/irText/types/rawTypeInSignature.fir.kt.txt @@ -0,0 +1,82 @@ +class GenericInv { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +class GenericIn { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +class GenericOut { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +fun testReturnsRawGenericInv(j: JRaw): GenericInv<*>? { + return j.returnsRawGenericInv() +} + +fun testReturnsRawGenericIn(j: JRaw): GenericIn? { + return j.returnsRawGenericIn() +} + +fun testReturnsRawGenericOut(j: JRaw): GenericOut<*>? { + return j.returnsRawGenericOut() +} + +class KRaw : JRaw { + constructor(j: JRaw) /* primary */ { + super/*Any*/() + /* () */ + + .#<$$delegate_0> = j + } + + override fun takesRawList(list: List<*>?) { + .#<$$delegate_0>.takesRawList(list = list) + } + + override fun returnsRawList(): List<*>? { + return .#<$$delegate_0>.returnsRawList() + } + + override fun takesRawGenericInv(g: GenericInv<*>?) { + .#<$$delegate_0>.takesRawGenericInv(g = g) + } + + override fun returnsRawGenericInv(): GenericInv<*>? { + return .#<$$delegate_0>.returnsRawGenericInv() + } + + override fun takesRawGenericIn(g: GenericIn?) { + .#<$$delegate_0>.takesRawGenericIn(g = g) + } + + override fun returnsRawGenericIn(): GenericIn? { + return .#<$$delegate_0>.returnsRawGenericIn() + } + + override fun takesRawGenericOut(g: GenericOut<*>?) { + .#<$$delegate_0>.takesRawGenericOut(g = g) + } + + override fun returnsRawGenericOut(): GenericOut<*>? { + return .#<$$delegate_0>.returnsRawGenericOut() + } + + local /*final field*/ val <$$delegate_0>: JRaw + +} diff --git a/compiler/testData/ir/irText/types/receiverOfIntersectionType.fir.kt.txt b/compiler/testData/ir/irText/types/receiverOfIntersectionType.fir.kt.txt new file mode 100644 index 00000000000..b646192135e --- /dev/null +++ b/compiler/testData/ir/irText/types/receiverOfIntersectionType.fir.kt.txt @@ -0,0 +1,60 @@ +interface K { + +} + +interface I : K { + abstract fun ff() + +} + +interface J : K { + +} + +class A : I, J { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + override fun ff() { + } + +} + +class B : I, J { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + override fun ff() { + } + +} + +fun testIntersection(a: A, b: B) { + val v: I = when { + true -> a + else -> b + } + v.ff() +} + +fun testFlexible1() { + val v: I? = when { + true -> a() + else -> b() + } + v.ff() +} + +fun testFlexible2(a: A, b: B) { + val v: I? = when { + true -> id(x = a) + else -> id(x = b) + } + v.ff() +} diff --git a/compiler/testData/ir/irText/types/smartCastOnFakeOverrideReceiver.fir.kt.txt b/compiler/testData/ir/irText/types/smartCastOnFakeOverrideReceiver.fir.kt.txt new file mode 100644 index 00000000000..afc88bcfc37 --- /dev/null +++ b/compiler/testData/ir/irText/types/smartCastOnFakeOverrideReceiver.fir.kt.txt @@ -0,0 +1,85 @@ +open class A { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + fun f(): Int { + return 1 + } + + val aVal: Int + field = 42 + get + + fun testA1(x: Any): Int? { + return when { + x is B -> x /*as B */.f() + else -> null + } + } + + fun testA2(x: Any): Int? { + return when { + x is B -> x /*as B */.() + else -> null + } + } + +} + +class B : A { + constructor() /* primary */ { + super/*A*/() + /* () */ + + } + + fun testB1(x: Any): Int? { + return when { + x is B -> x /*as B */.f() + else -> null + } + } + + fun testB2(x: Any): Int? { + return when { + x is B -> x /*as B */.() + else -> null + } + } + +} + +open class GA { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + fun f(): Int { + return 1 + } + + val aVal: Int + field = 42 + get + +} + +class GB : GA { + constructor() /* primary */ { + super/*GA*/() + /* () */ + + } + + fun testGB1(a: Any) { + a as GB /*~> Unit */ + a /*as GB */.f() /*~> Unit */ + a /*as GB */.() /*~> Unit */ + } + +} diff --git a/compiler/testData/ir/irText/types/smartCastOnFieldReceiverOfGenericType.fir.kt.txt b/compiler/testData/ir/irText/types/smartCastOnFieldReceiverOfGenericType.fir.kt.txt new file mode 100644 index 00000000000..9f4b5251168 --- /dev/null +++ b/compiler/testData/ir/irText/types/smartCastOnFieldReceiverOfGenericType.fir.kt.txt @@ -0,0 +1,10 @@ +fun testSetField(a: Any, b: Any) { + a as JCell /*~> Unit */ + b as String /*~> Unit */ + a /*as JCell */.#value = b /*as String */ +} + +fun testGetField(a: Any): String { + a as JCell /*~> Unit */ + return a /*as JCell */.#value /*!! String */ +}