[IR] dumpKotlinLike: add testdata for FIR tests

This commit is contained in:
Zalim Bashorov
2020-11-20 18:18:14 +03:00
committed by teamcityserver
parent d7bd4240e1
commit c68040753d
298 changed files with 12186 additions and 0 deletions
@@ -0,0 +1,32 @@
fun use(f: @ExtensionFunctionType @ExtensionFunctionType Function2<C, Int, Unit>) {
}
class C {
constructor() /* primary */ {
super/*Any*/()
/* <init>() */
}
}
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)
}
@@ -0,0 +1,45 @@
fun useUnit0(fn: Function0<Unit>) {
}
fun useUnit1(fn: Function1<Int, Unit>) {
}
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])
}
)
}
@@ -0,0 +1,18 @@
package test
inline fun foo(x: Function0<Unit>) {
}
fun String.id(s: String = <this>, vararg xs: Int): String {
return s
}
fun test() {
foo(x = { // BLOCK
local fun String.id() {
receiver.id()
}
"Fail"::id
})
}
@@ -0,0 +1,97 @@
fun interface IFoo {
abstract fun foo(i: Int)
}
fun interface IFoo2 : IFoo {
}
object A {
private constructor() /* primary */ {
super/*Any*/()
/* <init>() */
}
}
object B {
private constructor() /* primary */ {
super/*Any*/()
/* <init>() */
}
}
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 <<array>>: A = A
val <<index_0>>: KFunction1<IntArray, Int> = ::withVararg
error("") /* ERROR CALL */<<index_0>>; error("") /* ERROR CALL */<<index_0>>; .plus(other = 1);
}
}
fun test2() {
{ // BLOCK
val <<array>>: B = B
val <<index_0>>: KFunction1<IntArray, Int> = ::withVararg
error("") /* ERROR CALL */<<index_0>>; error("") /* ERROR CALL */<<index_0>>; .plus(other = 1);
}
}
fun test3(fn: Function1<Int, Unit>) {
{ // BLOCK
val <<array>>: A = A
val <<index_0>>: Function1<Int, Unit> = fn
<<array>>.set(i = <<index_0>> /*-> IFoo */, newValue = <<array>>.get(i = <<index_0>> /*-> IFoo */).plus(other = 1))
}
}
fun test4(fn: Function1<Int, Unit>) {
when {
fn is IFoo -> { // BLOCK
val <<array>>: A = A
val <<index_0>>: IFoo = fn /*as IFoo */
<<array>>.set(i = <<index_0>>, newValue = <<array>>.get(i = <<index_0>>).plus(other = 1))
}
}
}
fun test5(a: Any) {
a as Function1<Int, Unit> /*~> Unit */
{ // BLOCK
val <<array>>: A = A
val <<index_0>>: Function1<Int, Unit> = a /*as Function1<Int, Unit> */
<<array>>.set(i = <<index_0>> /*-> IFoo */, newValue = <<array>>.get(i = <<index_0>> /*-> IFoo */).plus(other = 1))
}
}
fun test6(a: Any) {
a as Function1<Int, Unit> /*~> Unit */
a /*as Function1<Int, Unit> */ as IFoo /*~> Unit */
{ // BLOCK
val <<array>>: A = A
val <<index_0>>: Function1<Int, Unit> = a /*as Function1<Int, Unit> */
<<array>>.set(i = <<index_0>>, newValue = <<array>>.get(i = <<index_0>>).plus(other = 1))
}
}
@@ -0,0 +1,42 @@
fun use(fn: Function1<Int, Any>): Any {
return fn.invoke(p1 = 42)
}
class C {
constructor(vararg xs: Int) /* primary */ {
super/*Any*/()
/* <init>() */
}
}
class Outer {
constructor() /* primary */ {
super/*Any*/()
/* <init>() */
}
inner class Inner {
constructor(vararg xs: Int) /* primary */ {
super/*Any*/()
/* <init>() */
}
}
}
fun testConstructor(): Any {
return use(fn = C::<init>)
}
fun testInnerClassConstructor(outer: Outer): Any {
return use(fn = outer::<init>)
}
fun testInnerClassConstructorCapturingOuter(): Any {
return use(fn = Outer()::<init>)
}
@@ -0,0 +1,28 @@
fun foo(x: String = ""): String {
return x
}
class C {
constructor(x: String = "") /* primary */ {
super/*Any*/()
/* <init>() */
}
val x: String
field = x
get
}
fun use(fn: Function0<Any>): Any {
return fn.invoke()
}
fun testFn(): Any {
return use(fn = ::foo)
}
fun testCtor(): Any {
return use(fn = C::<init>)
}
@@ -0,0 +1,99 @@
fun useSuspend(fn: SuspendFunction0<Unit>) {
}
fun useSuspendInt(fn: SuspendFunction1<Int, Unit>) {
}
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*/()
/* <init>() */
}
fun bar() {
}
}
fun testLambda() {
useSuspend(fn = local suspend fun <anonymous>() {
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
})
}
@@ -0,0 +1,29 @@
object Host {
private constructor() /* primary */ {
super/*Any*/()
/* <init>() */
}
inline fun <reified T : Any?> objectMember(x: T) {
}
}
inline fun <reified T : Any?> topLevel1(x: T) {
}
inline fun <reified T : Any?> topLevel2(x: List<T>) {
}
val test1: Function1<Int, Unit>
field = ::topLevel1/*<Int>()*/
get
val test2: Function1<List<String>, Unit>
field = ::topLevel2/*<String>()*/
get
val test3: Function1<Int, Unit>
field = Host::objectMember/*<Int>()*/
get
@@ -0,0 +1,58 @@
fun use1(fn: Function2<A, Int, Unit>) {
}
fun use2(fn: Function1<Int, Unit>) {
}
open class A {
constructor() /* primary */ {
super/*Any*/()
/* <init>() */
}
open fun foo(vararg xs: Int): Int {
return 1
}
}
object Obj : A {
private constructor() /* primary */ {
super/*A*/()
/* <init>() */
}
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
})
}
@@ -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 */)
}
@@ -0,0 +1,71 @@
fun use(fn: Function1<Int, String>): String {
return fn.invoke(p1 = 1)
}
fun use0(fn: Function0<String>): String {
return fn.invoke()
}
fun coerceToUnit(fn: Function1<Int, Unit>) {
}
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*/()
/* <init>() */
}
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)
}
@@ -0,0 +1,68 @@
fun use(fn: Function1<Int, Unit>) {
fn.invoke(p1 = 1)
}
class Host {
constructor() /* primary */ {
super/*Any*/()
/* <init>() */
}
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
})
}
}
@@ -0,0 +1,52 @@
fun sum(vararg args: Int): Int {
var result: Int = 0
{ // BLOCK
val <iterator>: IntIterator = args.iterator()
while (<iterator>.hasNext()) { // BLOCK
val arg: Int = <iterator>.next()
result = result.plus(other = arg)
}
}
return result
}
fun nsum(vararg args: Number): Int {
return sum(args = [*IntArray(size = args.<get-size>(), init = local fun <anonymous>(it: Int): Int {
return args.get(index = it).toInt()
}
)])
}
fun zap(vararg b: String, k: Int = 42) {
}
fun usePlainArgs(fn: Function2<Int, Int, Int>) {
}
fun usePrimitiveArray(fn: Function1<IntArray, Int>) {
}
fun useArray(fn: Function1<Array<Int>, Int>) {
}
fun useStringArray(fn: Function1<Array<String>, 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)
}