import kotlin.test.assertEquals

inline fun <reified T, reified R> foo(): Array<String> {
    val x = object {
        inline fun <reified T1, reified T> bar(): Array<String> = array(
                javaClass<T1>().getName(), javaClass<T>().getName(), javaClass<R>().getName()
        )
        fun f1() = bar<T, R>()
        fun f2() = bar<R, T>()
        fun f3() = bar<Boolean, T>()
        fun f4() = bar<T, Boolean>()
    }

    val x1 = x.f1()
    val x2 = x.f2()
    val x3 = x.f3()
    val x4 = x.f4()

    return array(
            x1[0], x1[1], x1[2],
            x2[0], x2[1], x2[2],
            x3[0], x3[1], x3[2],
            x4[0], x4[1], x4[2]
    )
}

fun box(): String {
    val result = foo<Double, Int>()

    val expected = array(
            "java.lang.Double", "java.lang.Integer", "java.lang.Integer",
            "java.lang.Integer", "java.lang.Double", "java.lang.Integer",
            "java.lang.Boolean", "java.lang.Double", "java.lang.Integer",
            "java.lang.Double", "java.lang.Boolean", "java.lang.Integer"
    )

    for (i in expected.indices) {
        assertEquals(expected[i], result[i], "$i-th element")
    }

    return "OK"
}
