[PL][tests] Keep PL test data under "testData/klib/" dir
This commit is contained in:
committed by
Space Team
parent
9e3afe7a1f
commit
5c3e63e19a
@@ -0,0 +1,99 @@
|
||||
@file:Suppress("RedundantSuspendModifier", "NOTHING_TO_INLINE")
|
||||
|
||||
class Cache {
|
||||
private val cache = mutableMapOf<String, String>()
|
||||
fun load(key: String): String? = cache[key]
|
||||
fun store(key: String, value: String) { cache[key] = value }
|
||||
fun dumpToString(): String = cache.entries.sortedBy { it.key }.joinToString(",") { it.key + "=" + it.value }
|
||||
}
|
||||
|
||||
class OperatorsToNonOperators(private val cache: Cache) {
|
||||
operator fun get(key: String): String? = cache.load(key)
|
||||
operator fun set(key: String, value: String) = cache.store(key, value)
|
||||
operator fun invoke(): String = cache.dumpToString()
|
||||
|
||||
companion object {
|
||||
operator fun Cache.get(key: String): String? = load(key)
|
||||
operator fun Cache.set(key: String, value: String) = store(key, value)
|
||||
operator fun Cache.invoke(): String = dumpToString()
|
||||
}
|
||||
}
|
||||
|
||||
class NonOperatorsToOperators(private val cache: Cache) {
|
||||
fun get(key: String): String? = cache.load(key)
|
||||
fun set(key: String, value: String) = cache.store(key, value)
|
||||
fun invoke(): String = cache.dumpToString()
|
||||
|
||||
companion object {
|
||||
fun Cache.get(key: String): String? = load(key)
|
||||
fun Cache.set(key: String, value: String) = store(key, value)
|
||||
fun Cache.invoke(): String = dumpToString()
|
||||
}
|
||||
}
|
||||
|
||||
data class Wrapper(private val value: Int) {
|
||||
private operator fun plus(other: Wrapper): Wrapper = (value + other.value).wrap()
|
||||
fun unwrap(): Int = value
|
||||
|
||||
fun memberNonInfixToInfix(other: Wrapper): Wrapper = this + other
|
||||
infix fun memberInfixToNonInfix(other: Wrapper): Wrapper = this + other
|
||||
|
||||
companion object {
|
||||
fun Wrapper.extensionNonInfixToInfix(other: Wrapper): Wrapper = this + other
|
||||
infix fun Wrapper.extensionInfixToNonInfix(other: Wrapper): Wrapper = this + other
|
||||
}
|
||||
}
|
||||
|
||||
fun Int.wrap(): Wrapper = Wrapper(this)
|
||||
|
||||
object Functions {
|
||||
fun nonTailrecToTailrec(n: Int, r: Int): Int = if (n <= 1) r else nonTailrecToTailrec(n - 1, n * r)
|
||||
tailrec fun tailrecToNonTailrec(n: Int, r: Int): Int = if (n <= 1) r else tailrecToNonTailrec(n - 1, n * r)
|
||||
|
||||
@Suppress("RedundantSuspendModifier") suspend fun <R> wrapCoroutine(coroutine: suspend () -> R): R = coroutine.invoke()
|
||||
suspend fun suspendToNonSuspendFunction(x: Int): Int = wrapCoroutine { -x }
|
||||
fun nonSuspendToSuspendFunction(x: Int): Int = -x
|
||||
|
||||
inline fun inlineLambdaToNoinlineLambda(x: Int, lambda: (Int) -> String): String = "Functions.inlineLambdaToNoinlineLambda($x) { ${lambda(x * 2)} }"
|
||||
inline fun inlineLambdaToCrossinlineLambda(x: Int, lambda: (Int) -> String): String = "Functions.inlineLambdaToCrossinlineLambda($x) { ${lambda(x * 2)} }"
|
||||
|
||||
fun removedFirstDefaultValue(a: Int = 42, b: Int): Int = a + b
|
||||
fun removedVarargFirstDefaultValue(vararg a: Int = intArrayOf(1, 2, 3), b: Int): Int = a.sum() + b
|
||||
fun removedLastDefaultValue(a: Int, b: Int = 42): Int = a + b
|
||||
fun removedVarargLastDefaultValue(a: Int, vararg b: Int = intArrayOf(1, 2, 3)): Int = a + b.sum()
|
||||
}
|
||||
|
||||
class RemovedFirstDefaultValueInConstructor(a: Int = 42, b: Int) {
|
||||
val value = a + b
|
||||
}
|
||||
class RemovedLastDefaultValueInConstructor(a: Int, b: Int = 42) {
|
||||
val value = a + b
|
||||
}
|
||||
|
||||
interface Interface {
|
||||
suspend fun suspendToNonSuspendFunction(x: Int): String
|
||||
fun nonSuspendToSuspendFunction(x: Int): String
|
||||
}
|
||||
|
||||
abstract class AbstractClass {
|
||||
abstract suspend fun suspendToNonSuspendFunction(x: Int): String
|
||||
abstract fun nonSuspendToSuspendFunction(x: Int): String
|
||||
}
|
||||
|
||||
open class OpenClass {
|
||||
open suspend fun suspendToNonSuspendFunction(x: Int): String = Functions.wrapCoroutine { "OpenClass.suspendToNonSuspendFunction($x)" }
|
||||
open fun nonSuspendToSuspendFunction(x: Int): String = "OpenClass.nonSuspendToSuspendFunction($x)"
|
||||
|
||||
open suspend fun suspendToNonSuspendFunctionWithDelegation(x: Int): String = Functions.wrapCoroutine { "OpenClass.suspendToNonSuspendFunctionWithDelegation($x)" }
|
||||
open fun nonSuspendToSuspendFunctionWithDelegation(x: Int): String = "OpenClass.nonSuspendToSuspendFunctionWithDelegation($x)"
|
||||
|
||||
open fun openNonInlineToInlineFunction(x: Int): String = "OpenClass.openNonInlineToInlineFunction($x)"
|
||||
open fun openNonInlineToInlineFunctionWithDelegation(x: Int): String = "OpenClass.openNonInlineToInlineFunctionWithDelegation($x)"
|
||||
//inline fun newInlineFunction1(x: Int): String = "OpenClass.newInlineFunction1($x)"
|
||||
//inline fun newInlineFunction2(x: Int): String = "OpenClass.newInlineFunction2($x)"
|
||||
//fun newNonInlineFunction(x: Int): String = "OpenClass.newNonInlineFunction($x)"
|
||||
|
||||
fun newInlineFunction1Caller(x: Int): String = TODO("Not implemented: OpenClass.newInlineFunction1Caller($x)")
|
||||
fun newInlineFunction2Caller(x: Int): String = TODO("Not implemented: OpenClass.newInlineFunction2Caller($x)")
|
||||
fun newNonInlineFunctionCaller(x: Int): String = TODO("Not implemented: OpenClass.newNonInlineFunctionCaller($x)")
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
@file:Suppress("RedundantSuspendModifier", "NOTHING_TO_INLINE")
|
||||
|
||||
class Cache {
|
||||
private val cache = mutableMapOf<String, String>()
|
||||
fun load(key: String): String? = cache[key]
|
||||
fun store(key: String, value: String) { cache[key] = value }
|
||||
fun dumpToString(): String = cache.entries.sortedBy { it.key }.joinToString(",") { it.key + "=" + it.value }
|
||||
}
|
||||
|
||||
class OperatorsToNonOperators(private val cache: Cache) {
|
||||
fun get(key: String): String? = cache.load(key)
|
||||
fun set(key: String, value: String) = cache.store(key, value)
|
||||
fun invoke(): String = cache.dumpToString()
|
||||
|
||||
companion object {
|
||||
fun Cache.get(key: String): String? = load(key)
|
||||
fun Cache.set(key: String, value: String) = store(key, value)
|
||||
fun Cache.invoke(): String = dumpToString()
|
||||
}
|
||||
}
|
||||
|
||||
class NonOperatorsToOperators(private val cache: Cache) {
|
||||
operator fun get(key: String): String? = cache.load(key)
|
||||
operator fun set(key: String, value: String) = cache.store(key, value)
|
||||
operator fun invoke(): String = cache.dumpToString()
|
||||
|
||||
companion object {
|
||||
operator fun Cache.get(key: String): String? = load(key)
|
||||
operator fun Cache.set(key: String, value: String) = store(key, value)
|
||||
operator fun Cache.invoke(): String = dumpToString()
|
||||
}
|
||||
}
|
||||
|
||||
data class Wrapper(private val value: Int) {
|
||||
private operator fun plus(other: Wrapper): Wrapper = (value + other.value).wrap()
|
||||
fun unwrap(): Int = value
|
||||
|
||||
infix fun memberNonInfixToInfix(other: Wrapper): Wrapper = this + other
|
||||
fun memberInfixToNonInfix(other: Wrapper): Wrapper = this + other
|
||||
|
||||
companion object {
|
||||
infix fun Wrapper.extensionNonInfixToInfix(other: Wrapper): Wrapper = this + other
|
||||
fun Wrapper.extensionInfixToNonInfix(other: Wrapper): Wrapper = this + other
|
||||
}
|
||||
}
|
||||
|
||||
fun Int.wrap(): Wrapper = Wrapper(this)
|
||||
|
||||
object Functions {
|
||||
tailrec fun nonTailrecToTailrec(n: Int, r: Int): Int = if (n <= 1) r else nonTailrecToTailrec(n - 1, n * r)
|
||||
fun tailrecToNonTailrec(n: Int, r: Int): Int = if (n <= 1) r else tailrecToNonTailrec(n - 1, n * r)
|
||||
|
||||
@Suppress("RedundantSuspendModifier") suspend fun <R> wrapCoroutine(coroutine: suspend () -> R): R = coroutine.invoke()
|
||||
fun suspendToNonSuspendFunction(x: Int): Int = -x
|
||||
suspend fun nonSuspendToSuspendFunction(x: Int): Int = wrapCoroutine { -x }
|
||||
|
||||
inline fun inlineLambdaToNoinlineLambda(x: Int, noinline lambda: (Int) -> String): String = "Functions.inlineLambdaToNoinlineLambda($x) { ${lambda(x * 2)} }"
|
||||
inline fun inlineLambdaToCrossinlineLambda(x: Int, crossinline lambda: (Int) -> String): String = "Functions.inlineLambdaToCrossinlineLambda($x) { ${lambda(x * 2)} }"
|
||||
|
||||
fun removedFirstDefaultValue(a: Int /*= 42*/, b: Int): Int = a + b
|
||||
fun removedVarargFirstDefaultValue(vararg a: Int /*= intArrayOf(1, 2, 3)*/, b: Int): Int = a.sum() + b
|
||||
fun removedLastDefaultValue(a: Int, b: Int /*= 42*/): Int = a + b
|
||||
fun removedVarargLastDefaultValue(a: Int, vararg b: Int /*= intArrayOf(1, 2, 3)*/): Int = a + b.sum()
|
||||
}
|
||||
|
||||
class RemovedFirstDefaultValueInConstructor(a: Int /*= 42*/, b: Int) {
|
||||
val value = a + b
|
||||
}
|
||||
class RemovedLastDefaultValueInConstructor(a: Int, b: Int /*= 42*/) {
|
||||
val value = a + b
|
||||
}
|
||||
|
||||
interface Interface {
|
||||
fun suspendToNonSuspendFunction(x: Int): String
|
||||
suspend fun nonSuspendToSuspendFunction(x: Int): String
|
||||
}
|
||||
|
||||
abstract class AbstractClass {
|
||||
abstract fun suspendToNonSuspendFunction(x: Int): String
|
||||
abstract suspend fun nonSuspendToSuspendFunction(x: Int): String
|
||||
}
|
||||
|
||||
open class OpenClass {
|
||||
open fun suspendToNonSuspendFunction(x: Int): String = "OpenClassV2.suspendToNonSuspendFunction($x)"
|
||||
open suspend fun nonSuspendToSuspendFunction(x: Int): String = Functions.wrapCoroutine { "OpenClassV2.nonSuspendToSuspendFunction($x)" }
|
||||
|
||||
open fun suspendToNonSuspendFunctionWithDelegation(x: Int): String = "OpenClassV2.suspendToNonSuspendFunctionWithDelegation($x)"
|
||||
open suspend fun nonSuspendToSuspendFunctionWithDelegation(x: Int): String = Functions.wrapCoroutine { "OpenClassV2.nonSuspendToSuspendFunctionWithDelegation($x)" }
|
||||
|
||||
inline fun openNonInlineToInlineFunction(x: Int): String = "OpenClassV2.openNonInlineToInlineFunction($x)"
|
||||
inline fun openNonInlineToInlineFunctionWithDelegation(x: Int): String = "OpenClassV2.openNonInlineToInlineFunctionWithDelegation($x)"
|
||||
inline fun newInlineFunction1(x: Int): String = "OpenClassV2.newInlineFunction1($x)"
|
||||
inline fun newInlineFunction2(x: Int): String = "OpenClassV2.newInlineFunction2($x)"
|
||||
fun newNonInlineFunction(x: Int): String = "OpenClassV2.newNonInlineFunction($x)"
|
||||
|
||||
fun newInlineFunction1Caller(x: Int): String = newInlineFunction1(x)
|
||||
fun newInlineFunction2Caller(x: Int): String = newInlineFunction2(x)
|
||||
fun newNonInlineFunctionCaller(x: Int): String = newNonInlineFunction(x)
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
STEP 0:
|
||||
dependencies: stdlib
|
||||
STEP 1:
|
||||
dependencies: stdlib
|
||||
modifications:
|
||||
U : l1.kt.1 -> l1.kt
|
||||
@@ -0,0 +1,181 @@
|
||||
import kotlin.coroutines.*
|
||||
|
||||
// Auxiliary function to imitate coroutines.
|
||||
private fun <R> runCoroutine(coroutine: suspend () -> R): R {
|
||||
var coroutineResult: Result<R>? = null
|
||||
|
||||
coroutine.startCoroutine(Continuation(EmptyCoroutineContext) { result ->
|
||||
coroutineResult = result
|
||||
})
|
||||
|
||||
return (coroutineResult ?: error("Coroutine finished without any result")).getOrThrow()
|
||||
}
|
||||
|
||||
private inline fun <R> runInlined(block: () -> R): R = block() // a-la kotlin.run() but without contracts and special annotation
|
||||
|
||||
fun memberOperatorsToNonOperators(vararg pairs: Pair<String, String>): String {
|
||||
check(pairs.isNotEmpty())
|
||||
val instance = OperatorsToNonOperators(Cache())
|
||||
pairs.forEach { (key, value) ->
|
||||
instance[key] = value // set
|
||||
}
|
||||
pairs.forEach { (key, value) ->
|
||||
check(instance[key] == value) // get
|
||||
}
|
||||
return "memberOperatorsToNonOperators: " + instance() // invoke
|
||||
}
|
||||
|
||||
fun extensionOperatorsToNonOperators(vararg pairs: Pair<String, String>): String = with(OperatorsToNonOperators.Companion) {
|
||||
check(pairs.isNotEmpty())
|
||||
val cache = Cache()
|
||||
pairs.forEach { (key, value) ->
|
||||
cache[key] = value // set
|
||||
}
|
||||
pairs.forEach { (key, value) ->
|
||||
check(cache[key] == value) // get
|
||||
}
|
||||
return "extensionOperatorsToNonOperators: " + cache() // invoke
|
||||
}
|
||||
|
||||
fun memberNonOperatorsToOperators(vararg pairs: Pair<String, String>): String {
|
||||
check(pairs.isNotEmpty())
|
||||
val instance = NonOperatorsToOperators(Cache())
|
||||
pairs.forEach { (key, value) ->
|
||||
instance.set(key, value) // set
|
||||
}
|
||||
pairs.forEach { (key, value) ->
|
||||
check(instance.get(key) == value) // get
|
||||
}
|
||||
return "memberNonOperatorsToOperators: " + instance.invoke() // invoke
|
||||
}
|
||||
|
||||
fun extensionNonOperatorsToOperators(vararg pairs: Pair<String, String>): String = with(NonOperatorsToOperators.Companion) {
|
||||
check(pairs.isNotEmpty())
|
||||
val cache = Cache()
|
||||
pairs.forEach { (key, value) ->
|
||||
cache.set(key, value) // set
|
||||
}
|
||||
pairs.forEach { (key, value) ->
|
||||
check(cache.get(key) == value) // get
|
||||
}
|
||||
return "extensionNonOperatorsToOperators: " + cache.invoke() // invoke
|
||||
}
|
||||
|
||||
fun memberNonInfixToInfix(a: Int, b: Int): Int = a.wrap().memberNonInfixToInfix(b.wrap()).unwrap()
|
||||
fun extensionNonInfixToInfix(a: Int, b: Int): Int = with(Wrapper.Companion) { a.wrap().extensionNonInfixToInfix(b.wrap()).unwrap() }
|
||||
fun memberInfixToNonInfix(a: Int, b: Int): Int = (a.wrap() memberInfixToNonInfix b.wrap()).unwrap()
|
||||
fun extensionInfixToNonInfix(a: Int, b: Int): Int = with(Wrapper.Companion) { (a.wrap() extensionInfixToNonInfix b.wrap()).unwrap() }
|
||||
|
||||
fun nonTailrecToTailrec(n: Int): Int = Functions.nonTailrecToTailrec(n, 1)
|
||||
@Suppress("NO_TAIL_CALLS_FOUND") tailrec fun tailrecToNonTailrec(n: Int): Int = Functions.tailrecToNonTailrec(n, 1)
|
||||
|
||||
// This is required to check that default arguments are counter correctly even for inherited classes.
|
||||
open class StableOpenClass {
|
||||
open fun firstDefaultValueInFunction(a: Int = 42, b: Int): Int = a + b
|
||||
open fun lastDefaultValueInFunction(a: Int, b: Int = 42): Int = a + b
|
||||
}
|
||||
open class StableClassImpl : StableOpenClass()
|
||||
class StableClassImpl2 : StableClassImpl() {
|
||||
override fun firstDefaultValueInFunction(a: Int, b: Int): Int = a - b
|
||||
override fun lastDefaultValueInFunction(a: Int, b: Int): Int = a - b
|
||||
}
|
||||
|
||||
fun firstDefaultValueInFunctionInStableOpenClass(stableOpenClass: StableOpenClass, n: Int): Int = stableOpenClass.firstDefaultValueInFunction(b = n)
|
||||
fun lastDefaultValueInFunctionInStableOpenClass(stableOpenClass: StableOpenClass, n: Int): Int = stableOpenClass.lastDefaultValueInFunction(a = n)
|
||||
fun firstDefaultValueInFunctionInStableClassImpl(stableClassImpl: StableClassImpl, n: Int): Int = stableClassImpl.firstDefaultValueInFunction(b = n)
|
||||
fun lastDefaultValueInFunctionInStableClassImpl(stableClassImpl: StableClassImpl, n: Int): Int = stableClassImpl.lastDefaultValueInFunction(a = n)
|
||||
fun firstDefaultValueInFunctionInStableClassImpl2(stableClassImpl2: StableClassImpl2, n: Int): Int = stableClassImpl2.firstDefaultValueInFunction(b = n)
|
||||
fun lastDefaultValueInFunctionInStableClassImpl2(stableClassImpl2: StableClassImpl2, n: Int): Int = stableClassImpl2.lastDefaultValueInFunction(a = n)
|
||||
|
||||
fun removedFirstDefaultValueInFunction(n: Int): Int = Functions.removedFirstDefaultValue(b = n)
|
||||
fun removedVarargFirstDefaultValueInFunction(n: Int): Int = Functions.removedVarargFirstDefaultValue(b = n)
|
||||
fun removedLastDefaultValueInFunction(n: Int): Int = Functions.removedLastDefaultValue(a = n)
|
||||
fun removedVarargLastDefaultValueInFunction(n: Int): Int = Functions.removedVarargLastDefaultValue(a = n)
|
||||
fun removedFirstDefaultValueInConstructor(n: Int): Int = RemovedFirstDefaultValueInConstructor(b = n).value
|
||||
fun removedLastDefaultValueInConstructor(n: Int): Int = RemovedLastDefaultValueInConstructor(a = n).value
|
||||
|
||||
fun singleVarargArgument(vararg elements: Int): Int = elements.sum()
|
||||
fun singleVarargArgumentWithDefaultValue(vararg elements: Int = intArrayOf(-1, -2, -3)): Int = elements.sum()
|
||||
fun varargArgumentAndOtherArguments(first: Int, vararg elements: Int, last: Int): Int = first + elements.sum() + last
|
||||
fun varargArgumentAndOtherArgumentsWithDefaultValues(first: Int = -100, vararg elements: Int, last: Int = -10): Int = first + elements.sum() + last
|
||||
fun varargArgumentWithDefaultValueAndOtherArguments(first: Int, vararg elements: Int = intArrayOf(-1, -2, -3), last: Int): Int = first + elements.sum() + last
|
||||
fun varargArgumentWithDefaultValueAndOtherArgumentsWithDefaultValues(first: Int = -100, vararg elements: Int = intArrayOf(-1, -2, -3), last: Int = -10): Int = first + elements.sum() + last
|
||||
|
||||
fun suspendToNonSuspendFunction1(x: Int): Int = runCoroutine { Functions.suspendToNonSuspendFunction(x) }
|
||||
fun suspendToNonSuspendFunction2(x: Int): Int = runCoroutine { Functions.wrapCoroutine { Functions.suspendToNonSuspendFunction(x) } }
|
||||
fun suspendToNonSuspendFunction3(x: Int): Int = runCoroutine { runInlined { Functions.suspendToNonSuspendFunction(x) } }
|
||||
fun nonSuspendToSuspendFunction1(x: Int): Int = Functions.nonSuspendToSuspendFunction(x)
|
||||
fun nonSuspendToSuspendFunction2(x: Int): Int = runCoroutine { Functions.nonSuspendToSuspendFunction(x) }
|
||||
fun nonSuspendToSuspendFunction3(x: Int): Int = runInlined { Functions.nonSuspendToSuspendFunction(x) }
|
||||
fun nonSuspendToSuspendFunction4(x: Int): Int = runCoroutine { runInlined { Functions.nonSuspendToSuspendFunction(x) } }
|
||||
|
||||
class InterfaceImpl : Interface {
|
||||
override suspend fun suspendToNonSuspendFunction(x: Int): String = Functions.wrapCoroutine { "InterfaceImpl.suspendToNonSuspendFunction($x)" }
|
||||
override fun nonSuspendToSuspendFunction(x: Int): String = "InterfaceImpl.nonSuspendToSuspendFunction($x)"
|
||||
}
|
||||
|
||||
class AbstractClassImpl : AbstractClass() {
|
||||
override suspend fun suspendToNonSuspendFunction(x: Int): String = Functions.wrapCoroutine { "AbstractClassImpl.suspendToNonSuspendFunction($x)" }
|
||||
override fun nonSuspendToSuspendFunction(x: Int): String = "AbstractClassImpl.nonSuspendToSuspendFunction($x)"
|
||||
}
|
||||
|
||||
class OpenClassImpl : OpenClass() {
|
||||
override suspend fun suspendToNonSuspendFunction(x: Int): String = Functions.wrapCoroutine { "OpenClassImpl.suspendToNonSuspendFunction($x)" }
|
||||
override fun nonSuspendToSuspendFunction(x: Int): String = "OpenClassImpl.nonSuspendToSuspendFunction($x)"
|
||||
|
||||
override suspend fun suspendToNonSuspendFunctionWithDelegation(x: Int): String = super.suspendToNonSuspendFunctionWithDelegation(x) + " called from OpenClassImpl.suspendToNonSuspendFunctionWithDelegation($x)"
|
||||
override fun nonSuspendToSuspendFunctionWithDelegation(x: Int): String = super.nonSuspendToSuspendFunctionWithDelegation(x) + " called from OpenClassImpl.nonSuspendToSuspendFunctionWithDelegation($x)"
|
||||
|
||||
override fun openNonInlineToInlineFunction(x: Int): String = "OpenClassImpl.openNonInlineToInlineFunction($x)"
|
||||
override fun openNonInlineToInlineFunctionWithDelegation(x: Int): String = super.openNonInlineToInlineFunctionWithDelegation(x) + " called from OpenClassImpl.openNonInlineToInlineFunctionWithDelegation($x)"
|
||||
fun newInlineFunction1(x: Int): String = "OpenClassImpl.newInlineFunction1($x)" // overrides accidentally appeared inline function
|
||||
@Suppress("NOTHING_TO_INLINE") inline fun newInlineFunction2(x: Int): String = "OpenClassImpl.newInlineFunction2($x)" // overrides accidentally appeared inline function
|
||||
@Suppress("NOTHING_TO_INLINE") inline fun newNonInlineFunction(x: Int): String = "OpenClassImpl.newNonInlineFunction($x)" // overrides accidentally appeared non-inline function
|
||||
}
|
||||
|
||||
fun suspendToNonSuspendFunctionInInterface(i: Interface, x: Int): String = runCoroutine { i.suspendToNonSuspendFunction(x) }
|
||||
fun nonSuspendToSuspendFunctionInInterface(i: Interface, x: Int): String = i.nonSuspendToSuspendFunction(x)
|
||||
fun suspendToNonSuspendFunctionInInterfaceImpl(ii: InterfaceImpl, x: Int): String = runCoroutine { ii.suspendToNonSuspendFunction(x) }
|
||||
fun nonSuspendToSuspendFunctionInInterfaceImpl(ii: InterfaceImpl, x: Int): String = ii.nonSuspendToSuspendFunction(x)
|
||||
fun suspendToNonSuspendFunctionInAbstractClass(ac: AbstractClass, x: Int): String = runCoroutine { ac.suspendToNonSuspendFunction(x) }
|
||||
fun nonSuspendToSuspendFunctionInAbstractClass(ac: AbstractClass, x: Int): String = ac.nonSuspendToSuspendFunction(x)
|
||||
fun suspendToNonSuspendFunctionInAbstractClassImpl(aci: AbstractClassImpl, x: Int): String = runCoroutine { aci.suspendToNonSuspendFunction(x) }
|
||||
fun nonSuspendToSuspendFunctionInAbstractClassImpl(aci: AbstractClassImpl, x: Int): String = aci.nonSuspendToSuspendFunction(x)
|
||||
fun suspendToNonSuspendFunctionInOpenClass(oc: OpenClass, x: Int): String = runCoroutine { oc.suspendToNonSuspendFunction(x) }
|
||||
fun nonSuspendToSuspendFunctionInOpenClass(oc: OpenClass, x: Int): String = oc.nonSuspendToSuspendFunction(x)
|
||||
fun suspendToNonSuspendFunctionInOpenClassImpl(oci: OpenClassImpl, x: Int): String = runCoroutine { oci.suspendToNonSuspendFunction(x) }
|
||||
fun nonSuspendToSuspendFunctionInOpenClassImpl(oci: OpenClassImpl, x: Int): String = oci.nonSuspendToSuspendFunction(x)
|
||||
fun suspendToNonSuspendFunctionWithDelegation(oci: OpenClassImpl, x: Int): String = runCoroutine { oci.suspendToNonSuspendFunctionWithDelegation(x) }
|
||||
fun nonSuspendToSuspendFunctionWithDelegation(oci: OpenClassImpl, x: Int): String = oci.nonSuspendToSuspendFunctionWithDelegation(x)
|
||||
|
||||
fun openNonInlineToInlineFunctionInOpenClass(oc: OpenClass, x: Int): String = oc.openNonInlineToInlineFunction(x)
|
||||
fun openNonInlineToInlineFunctionWithDelegationInOpenClass(oc: OpenClass, x: Int): String = oc.openNonInlineToInlineFunctionWithDelegation(x)
|
||||
fun newInlineFunction1InOpenClass(oc: OpenClass, x: Int): String = oc.newInlineFunction1Caller(x)
|
||||
fun newInlineFunction2InOpenClass(oc: OpenClass, x: Int): String = oc.newInlineFunction2Caller(x)
|
||||
fun newNonInlineFunctionInOpenClass(oc: OpenClass, x: Int): String = oc.newNonInlineFunctionCaller(x)
|
||||
fun openNonInlineToInlineFunctionInOpenClassImpl(oci: OpenClassImpl, x: Int): String = oci.openNonInlineToInlineFunction(x)
|
||||
fun openNonInlineToInlineFunctionWithDelegationInOpenClassImpl(oci: OpenClassImpl, x: Int): String = oci.openNonInlineToInlineFunctionWithDelegation(x)
|
||||
fun newInlineFunction1InOpenClassImpl(oci: OpenClassImpl, x: Int): String = oci.newInlineFunction1(x)
|
||||
fun newInlineFunction2InOpenClassImpl(oci: OpenClassImpl, x: Int): String = oci.newInlineFunction2(x)
|
||||
fun newNonInlineFunctionInOpenClassImpl(oci: OpenClassImpl, x: Int): String = oci.newNonInlineFunction(x)
|
||||
|
||||
fun inlineLambdaToNoinlineLambda(x: Int): String = Functions.inlineLambdaToNoinlineLambda(x) { if (it > 0) it.toString() else return "inlineLambdaToNoinlineLambda($x)" }
|
||||
fun inlineLambdaToCrossinlineLambda(x: Int): String = Functions.inlineLambdaToCrossinlineLambda(x) { if (it > 0) it.toString() else return "inlineLambdaToCrossinlineLambda($x)" }
|
||||
|
||||
fun nonLocalReturnFromArrayConstructorLambda(expected: String, unexpected: String): String = Array(1) outer@{
|
||||
Array(1) {
|
||||
if ('1' in "123") { // The condition that is always true.
|
||||
return@outer expected
|
||||
}
|
||||
unexpected
|
||||
}[0]
|
||||
}[0]
|
||||
|
||||
fun nonLocalReturnFromIntArrayConstructorLambda(expected: Int, unexpected: Int): Int = IntArray(1) outer@{
|
||||
IntArray(1) {
|
||||
if ('1' in "123") { // The condition that is always true.
|
||||
return@outer expected
|
||||
}
|
||||
unexpected
|
||||
}[0]
|
||||
}[0]
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
STEP 0:
|
||||
dependencies: stdlib, lib1
|
||||
@@ -0,0 +1,125 @@
|
||||
@file:Suppress("RemoveRedundantSpreadOperator")
|
||||
|
||||
import abitestutils.abiTest
|
||||
|
||||
fun box() = abiTest {
|
||||
val ii: InterfaceImpl = InterfaceImpl()
|
||||
val i: Interface = ii
|
||||
val aci: AbstractClassImpl = AbstractClassImpl()
|
||||
val ac: AbstractClass = aci
|
||||
val oci: OpenClassImpl = OpenClassImpl()
|
||||
val oc: OpenClass = oci
|
||||
val soc: StableOpenClass = StableOpenClass()
|
||||
val sci: StableClassImpl = StableClassImpl()
|
||||
val sci2: StableClassImpl2 = StableClassImpl2()
|
||||
|
||||
expectSuccess("memberOperatorsToNonOperators: a=Alice,b=Bob") { memberOperatorsToNonOperators("a" to "Alice", "b" to "Bob") }
|
||||
expectSuccess("extensionOperatorsToNonOperators: a=Alice,b=Bob") { extensionOperatorsToNonOperators("a" to "Alice", "b" to "Bob") }
|
||||
expectSuccess("memberNonOperatorsToOperators: a=Alice,b=Bob") { memberNonOperatorsToOperators("a" to "Alice", "b" to "Bob") }
|
||||
expectSuccess("extensionNonOperatorsToOperators: a=Alice,b=Bob") { extensionNonOperatorsToOperators("a" to "Alice", "b" to "Bob") }
|
||||
|
||||
expectSuccess(3) { memberNonInfixToInfix(1, 2) }
|
||||
expectSuccess(3) { extensionNonInfixToInfix(1, 2) }
|
||||
expectSuccess(3) { memberInfixToNonInfix(1, 2) }
|
||||
expectSuccess(3) { extensionInfixToNonInfix(1, 2) }
|
||||
|
||||
expectSuccess(6) { nonTailrecToTailrec(3) }
|
||||
expectSuccess(6) { tailrecToNonTailrec(3) }
|
||||
|
||||
expectSuccess(142) { firstDefaultValueInFunctionInStableOpenClass(soc, 100) }
|
||||
expectSuccess(142) { lastDefaultValueInFunctionInStableOpenClass(soc, 100) }
|
||||
expectSuccess(142) { firstDefaultValueInFunctionInStableClassImpl(sci, 100) }
|
||||
expectSuccess(142) { lastDefaultValueInFunctionInStableClassImpl(sci, 100) }
|
||||
expectSuccess(-58) { firstDefaultValueInFunctionInStableClassImpl2(sci2, 100) }
|
||||
expectSuccess(58) { lastDefaultValueInFunctionInStableClassImpl2(sci2, 100) }
|
||||
|
||||
expectFailure(linkage("Function 'removedFirstDefaultValue' can not be called: The call site provides less value arguments (1) than the function requires (2)")) { removedFirstDefaultValueInFunction(1) }
|
||||
expectSuccess(100) { removedVarargFirstDefaultValueInFunction(100) } // Default IntArray value disappears. So it contrinutes 0 to the sum.
|
||||
expectFailure(linkage("Function 'removedLastDefaultValue' can not be called: The call site provides less value arguments (1) than the function requires (2)")) { removedLastDefaultValueInFunction(1) }
|
||||
expectSuccess(100) { removedVarargLastDefaultValueInFunction(100) } // Default IntArray value disappears. So it contrinutes 0 to the sum.
|
||||
expectFailure(linkage("Constructor 'RemovedFirstDefaultValueInConstructor.<init>' can not be called: The call site provides less value arguments (1) than the constructor requires (2)")) { removedFirstDefaultValueInConstructor(1) }
|
||||
expectFailure(linkage("Constructor 'RemovedLastDefaultValueInConstructor.<init>' can not be called: The call site provides less value arguments (1) than the constructor requires (2)")) { removedLastDefaultValueInConstructor(1) }
|
||||
|
||||
expectSuccess(0) { singleVarargArgument() }
|
||||
expectSuccess(1) { singleVarargArgument(1) }
|
||||
expectSuccess(3) { singleVarargArgument(1, 2) }
|
||||
expectSuccess(1) { singleVarargArgument(*intArrayOf(1)) }
|
||||
expectSuccess(3) { singleVarargArgument(*intArrayOf(1, 2)) }
|
||||
expectSuccess(-6) { singleVarargArgumentWithDefaultValue() }
|
||||
expectSuccess(1) { singleVarargArgumentWithDefaultValue(1) }
|
||||
expectSuccess(3) { singleVarargArgumentWithDefaultValue(1, 2) }
|
||||
expectSuccess(1) { singleVarargArgumentWithDefaultValue(*intArrayOf(1)) }
|
||||
expectSuccess(3) { singleVarargArgumentWithDefaultValue(*intArrayOf(1, 2)) }
|
||||
expectSuccess(110) { varargArgumentAndOtherArguments(100, last = 10) }
|
||||
expectSuccess(111) { varargArgumentAndOtherArguments(100, 1, last = 10) }
|
||||
expectSuccess(113) { varargArgumentAndOtherArguments(100, 1, 2, last = 10) }
|
||||
expectSuccess(111) { varargArgumentAndOtherArguments(100, *intArrayOf(1), last = 10) }
|
||||
expectSuccess(113) { varargArgumentAndOtherArguments(100, *intArrayOf(1, 2), last = 10) }
|
||||
expectSuccess(-110) { varargArgumentAndOtherArgumentsWithDefaultValues() }
|
||||
expectSuccess(90) { varargArgumentAndOtherArgumentsWithDefaultValues(100) }
|
||||
expectSuccess(110) { varargArgumentAndOtherArgumentsWithDefaultValues(100, last = 10) }
|
||||
expectSuccess(91) { varargArgumentAndOtherArgumentsWithDefaultValues(100, 1) }
|
||||
expectSuccess(93) { varargArgumentAndOtherArgumentsWithDefaultValues(100, 1, 2) }
|
||||
expectSuccess(113) { varargArgumentAndOtherArgumentsWithDefaultValues(100, 1, 2, last = 10) }
|
||||
expectSuccess(-109) { @Suppress("REDUNDANT_SPREAD_OPERATOR_IN_NAMED_FORM_IN_FUNCTION") varargArgumentAndOtherArgumentsWithDefaultValues(elements = *intArrayOf(1)) }
|
||||
expectSuccess(-107) { @Suppress("REDUNDANT_SPREAD_OPERATOR_IN_NAMED_FORM_IN_FUNCTION") varargArgumentAndOtherArgumentsWithDefaultValues(elements = *intArrayOf(1, 2)) }
|
||||
expectSuccess(104) { varargArgumentWithDefaultValueAndOtherArguments(100, last = 10) }
|
||||
expectSuccess(111) { varargArgumentWithDefaultValueAndOtherArguments(100, 1, last = 10) }
|
||||
expectSuccess(113) { varargArgumentWithDefaultValueAndOtherArguments(100, 1, 2, last = 10) }
|
||||
expectSuccess(111) { varargArgumentWithDefaultValueAndOtherArguments(100, *intArrayOf(1), last = 10) }
|
||||
expectSuccess(113) { varargArgumentWithDefaultValueAndOtherArguments(100, *intArrayOf(1, 2), last = 10) }
|
||||
expectSuccess(-116) { varargArgumentWithDefaultValueAndOtherArgumentsWithDefaultValues() }
|
||||
expectSuccess(84) { varargArgumentWithDefaultValueAndOtherArgumentsWithDefaultValues(100) }
|
||||
expectSuccess(104) { varargArgumentWithDefaultValueAndOtherArgumentsWithDefaultValues(100, last = 10) }
|
||||
expectSuccess(91) { varargArgumentWithDefaultValueAndOtherArgumentsWithDefaultValues(100, 1) }
|
||||
expectSuccess(93) { varargArgumentWithDefaultValueAndOtherArgumentsWithDefaultValues(100, 1, 2) }
|
||||
expectSuccess(113) { varargArgumentWithDefaultValueAndOtherArgumentsWithDefaultValues(100, 1, 2, last = 10) }
|
||||
expectSuccess(-109) { @Suppress("REDUNDANT_SPREAD_OPERATOR_IN_NAMED_FORM_IN_FUNCTION") varargArgumentWithDefaultValueAndOtherArgumentsWithDefaultValues(elements = *intArrayOf(1)) }
|
||||
expectSuccess(-107) { @Suppress("REDUNDANT_SPREAD_OPERATOR_IN_NAMED_FORM_IN_FUNCTION") varargArgumentWithDefaultValueAndOtherArgumentsWithDefaultValues(elements = *intArrayOf(1, 2)) }
|
||||
|
||||
expectSuccess(-1) { suspendToNonSuspendFunction1(1) }
|
||||
expectSuccess(-2) { suspendToNonSuspendFunction2(2) }
|
||||
expectSuccess(-3) { suspendToNonSuspendFunction3(3) }
|
||||
expectFailure(linkage("Function 'nonSuspendToSuspendFunction' can not be called: Suspend function can be called only from a coroutine or another suspend function")) { nonSuspendToSuspendFunction1(4) }
|
||||
expectSuccess(-5) { nonSuspendToSuspendFunction2(5) }
|
||||
expectFailure(linkage("Function 'nonSuspendToSuspendFunction' can not be called: Suspend function can be called only from a coroutine or another suspend function")) { nonSuspendToSuspendFunction3(6) }
|
||||
expectSuccess(-7) { nonSuspendToSuspendFunction4(7) }
|
||||
|
||||
expectFailure(linkage("Abstract function 'suspendToNonSuspendFunction' is not implemented in non-abstract class 'InterfaceImpl'")) { suspendToNonSuspendFunctionInInterface(i, 1) }
|
||||
expectFailure(linkage("Function 'nonSuspendToSuspendFunction' can not be called: Suspend function can be called only from a coroutine or another suspend function")) { nonSuspendToSuspendFunctionInInterface(i, 2) }
|
||||
expectSuccess("InterfaceImpl.suspendToNonSuspendFunction(3)") { suspendToNonSuspendFunctionInInterfaceImpl(ii, 3) }
|
||||
expectSuccess("InterfaceImpl.nonSuspendToSuspendFunction(4)") { nonSuspendToSuspendFunctionInInterfaceImpl(ii, 4) }
|
||||
|
||||
expectFailure(linkage("Abstract function 'suspendToNonSuspendFunction' is not implemented in non-abstract class 'AbstractClassImpl'")) { suspendToNonSuspendFunctionInAbstractClass(ac, 5) }
|
||||
expectFailure(linkage("Function 'nonSuspendToSuspendFunction' can not be called: Suspend function can be called only from a coroutine or another suspend function")) { nonSuspendToSuspendFunctionInAbstractClass(ac, 6) }
|
||||
expectSuccess("AbstractClassImpl.suspendToNonSuspendFunction(7)") { suspendToNonSuspendFunctionInAbstractClassImpl(aci, 7) }
|
||||
expectSuccess("AbstractClassImpl.nonSuspendToSuspendFunction(8)") { nonSuspendToSuspendFunctionInAbstractClassImpl(aci, 8) }
|
||||
|
||||
expectSuccess("OpenClassV2.suspendToNonSuspendFunction(9)") { suspendToNonSuspendFunctionInOpenClass(oc, 9) } // Function of the base class is called instead of overridden function in inherited class.
|
||||
expectFailure(linkage("Function 'nonSuspendToSuspendFunction' can not be called: Suspend function can be called only from a coroutine or another suspend function")) { nonSuspendToSuspendFunctionInOpenClass(oc, 10) }
|
||||
expectSuccess("OpenClassImpl.suspendToNonSuspendFunction(11)") { suspendToNonSuspendFunctionInOpenClassImpl(oci, 11) }
|
||||
expectSuccess("OpenClassImpl.nonSuspendToSuspendFunction(12)") { nonSuspendToSuspendFunctionInOpenClassImpl(oci, 12) }
|
||||
expectSuccess("OpenClassV2.suspendToNonSuspendFunctionWithDelegation(13) called from OpenClassImpl.suspendToNonSuspendFunctionWithDelegation(13)") { suspendToNonSuspendFunctionWithDelegation(oci, 13) }
|
||||
expectFailure(linkage("Function 'nonSuspendToSuspendFunctionWithDelegation' can not be called: Suspend function can be called only from a coroutine or another suspend function")) { nonSuspendToSuspendFunctionWithDelegation(oci, 14) }
|
||||
|
||||
expectSuccess("OpenClassV2.openNonInlineToInlineFunction(1)") { openNonInlineToInlineFunctionInOpenClass(oc, 1) }
|
||||
expectSuccess("OpenClassV2.openNonInlineToInlineFunctionWithDelegation(2)") { openNonInlineToInlineFunctionWithDelegationInOpenClass(oc, 2) }
|
||||
expectSuccess("OpenClassV2.newInlineFunction1(3)") { newInlineFunction1InOpenClass(oc, 3) }
|
||||
expectSuccess("OpenClassV2.newInlineFunction2(4)") { newInlineFunction2InOpenClass(oc, 4) }
|
||||
expectSuccess( // TODO: this should be fixed in JS, KT-56762
|
||||
if (testMode.isJs) "OpenClassImpl.newNonInlineFunction(5)" else "OpenClassV2.newNonInlineFunction(5)"
|
||||
) { newNonInlineFunctionInOpenClass(oc, 5) }
|
||||
expectSuccess("OpenClassImpl.openNonInlineToInlineFunction(6)") { openNonInlineToInlineFunctionInOpenClassImpl(oci, 6) }
|
||||
expectSuccess("OpenClassV2.openNonInlineToInlineFunctionWithDelegation(7) called from OpenClassImpl.openNonInlineToInlineFunctionWithDelegation(7)") { openNonInlineToInlineFunctionWithDelegationInOpenClassImpl(oci, 7) }
|
||||
expectSuccess("OpenClassImpl.newInlineFunction1(8)") { newInlineFunction1InOpenClassImpl(oci, 8) }
|
||||
expectSuccess("OpenClassImpl.newInlineFunction2(9)") { newInlineFunction2InOpenClassImpl(oci, 9) }
|
||||
expectSuccess("OpenClassImpl.newNonInlineFunction(10)") { newNonInlineFunctionInOpenClassImpl(oci, 10) }
|
||||
|
||||
expectSuccess("Functions.inlineLambdaToNoinlineLambda(3) { 6 }") { inlineLambdaToNoinlineLambda(3) }
|
||||
expectFailure(linkage("Illegal non-local return: The return target is function 'inlineLambdaToNoinlineLambda' while only the following return targets are allowed: lambda in function 'inlineLambdaToNoinlineLambda'")) { inlineLambdaToNoinlineLambda(-3) }
|
||||
expectSuccess("Functions.inlineLambdaToCrossinlineLambda(5) { 10 }") { inlineLambdaToCrossinlineLambda(5) }
|
||||
expectFailure(linkage("Illegal non-local return: The return target is function 'inlineLambdaToCrossinlineLambda' while only the following return targets are allowed: lambda in function 'inlineLambdaToCrossinlineLambda'")) { inlineLambdaToCrossinlineLambda(-5) }
|
||||
|
||||
expectSuccess("success") { nonLocalReturnFromArrayConstructorLambda("success", "failure") }
|
||||
expectSuccess(100) { nonLocalReturnFromIntArrayConstructorLambda(100, -100) }
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
STEP 0:
|
||||
dependencies: stdlib, lib1, lib2
|
||||
@@ -0,0 +1,7 @@
|
||||
MODULES: lib1, lib2, main
|
||||
|
||||
STEP 0:
|
||||
libs: lib1, lib2, main
|
||||
|
||||
STEP 1:
|
||||
libs: lib1
|
||||
Reference in New Issue
Block a user