tests: Update external tests (1.1.2-dev-393)

This commit is contained in:
Ilya Matveev
2017-03-13 12:38:08 +03:00
committed by ilmat192
parent ac56fccb15
commit bc074e6d39
3178 changed files with 22396 additions and 696 deletions
@@ -0,0 +1,45 @@
// FILE: 1.kt
package test
abstract class A<R> {
abstract fun getO() : R
abstract fun getK() : R
}
inline fun <R> doWork(job: ()-> R) : R {
return job()
}
// FILE: 2.kt
//NO_CHECK_LAMBDA_INLINING
import test.*
fun box() : String {
val o = "O"
val p = "GOOD"
val result = doWork {
val k = "K"
val s = object : A<String>() {
val param = p;
override fun getO(): String {
return o;
}
override fun getK(): String {
return k;
}
}
s.getO() + s.getK() + s.param
}
if (result != "OKGOOD") return "fail $result"
return "OK"
}
@@ -0,0 +1,41 @@
// FILE: 1.kt
package test
abstract class A<R>(val param: R) {
abstract fun getO() : R
abstract fun getK() : R
}
inline fun <R> doWork(job: ()-> R) : R {
return job()
}
// FILE: 2.kt
//NO_CHECK_LAMBDA_INLINING
import test.*
fun box() : String {
val o = "O"
val result = doWork {
val k = "K"
val s = object : A<String>("11") {
override fun getO(): String {
return o;
}
override fun getK(): String {
return k;
}
}
s.getO() + s.getK() + s.param
}
if (result != "OK11") return "fail $result"
return "OK"
}
@@ -0,0 +1,85 @@
// FILE: 1.kt
package test
abstract class A<R> {
abstract fun getO() : R
abstract fun getK() : R
abstract fun getParam() : R
}
inline fun <R> doWork(crossinline jobO: ()-> R, crossinline jobK: ()-> R, param: R) : A<R> {
val s = object : A<R>() {
override fun getO(): R {
return jobO()
}
override fun getK(): R {
return jobK()
}
override fun getParam(): R {
return param
}
}
return s;
}
inline fun <R> doWorkInConstructor(crossinline jobO: ()-> R, crossinline jobK: ()-> R, param: R) : A<R> {
val s = object : A<R>() {
val p = param;
val o1 = jobO()
val k1 = jobK()
override fun getO(): R {
return o1
}
override fun getK(): R {
return k1
}
override fun getParam(): R {
return p
}
}
return s;
}
// FILE: 2.kt
//NO_CHECK_LAMBDA_INLINING
import test.*
fun test1(): String {
val o = "O"
val result = doWork ({o}, {"K"}, "GOOD")
return result.getO() + result.getK() + result.getParam()
}
fun test2() : String {
//same names as in object
val o1 = "O"
val k1 = "K"
val result = doWorkInConstructor ({o1}, {k1}, "GOOD")
return result.getO() + result.getK() + result.getParam()
}
fun box() : String {
val result1 = test1();
if (result1 != "OKGOOD") return "fail1 $result1"
val result2 = test2();
if (result2 != "OKGOOD") return "fail2 $result2"
return "OK"
}
@@ -0,0 +1,72 @@
// FILE: 1.kt
package test
abstract class A<R>(val param : R) {
abstract fun getO() : R
abstract fun getK() : R
}
inline fun <R> doWork(crossinline jobO: ()-> R, crossinline jobK: ()-> R, param: R) : A<R> {
val s = object : A<R>(param) {
override fun getO(): R {
return jobO()
}
override fun getK(): R {
return jobK()
}
}
return s;
}
inline fun <R> doWorkInConstructor(crossinline jobO: ()-> R, crossinline jobK: ()-> R, crossinline param: () -> R) : A<R> {
val s = object : A<R>(param()) {
val o1 = jobO()
val k1 = jobK()
override fun getO(): R {
return o1
}
override fun getK(): R {
return k1
}
}
return s;
}
// FILE: 2.kt
//NO_CHECK_LAMBDA_INLINING
import test.*
fun test1(): String {
val o = "O"
val result = doWork ({o}, {"K"}, "11")
return result.getO() + result.getK() + result.param
}
fun test2() : String {
//same names as in object
val o1 = "O"
val k1 = "K"
val param = "11"
val result = doWorkInConstructor ({o1}, {k1}, {param})
return result.getO() + result.getK() + result.param
}
fun box() : String {
val result1 = test1();
if (result1 != "OK11") return "fail1 $result1"
val result2 = test2();
if (result2 != "OK11") return "fail2 $result2"
return "OK"
}
@@ -0,0 +1,18 @@
// FILE: 1.kt
package test
inline fun bar(crossinline y: () -> String) = {
call(y)
}
public inline fun <T> call(f: () -> T): T = f()
// FILE: 2.kt
//NO_CHECK_LAMBDA_INLINING
import test.*
fun box(): String {
return bar {"OK"} ()
}
@@ -0,0 +1,18 @@
// FILE: 1.kt
package test
inline fun bar(crossinline y: () -> String) = {
{ { call(y) }() }()
}
public inline fun <T> call(f: () -> T): T = f()
// FILE: 2.kt
//NO_CHECK_LAMBDA_INLINING
import test.*
fun box(): String {
return bar {"OK"} ()
}
@@ -0,0 +1,24 @@
// FILE: 1.kt
package test
inline fun bar(crossinline y: () -> String) = {
{ { call(y) }() }()
}
public inline fun <T> call(crossinline f: () -> T): T = {{ f() }()}()
// FILE: 2.kt
//NO_CHECK_LAMBDA_INLINING
import test.*
fun box(): String {
val bar1 = bar {"123"} ()
val bar2 = bar2 { "1234" } ()
return if (bar1 == "123" && bar2 == "1234") "OK" else "fail: $bar1 $bar2"
}
inline fun bar2(crossinline y: () -> String) = {
{ { call(y) }() }()
}
@@ -0,0 +1,28 @@
// FILE: 1.kt
package test
internal interface A<T> {
fun run(): T;
}
internal inline fun bar(crossinline y: () -> String) = object : A<String> {
override fun run() : String {
return call(y)
}
}
public inline fun <T> call(crossinline f: () -> T): T = object : A<T> {
override fun run() : T {
return f()
}
}.run()
// FILE: 2.kt
//NO_CHECK_LAMBDA_INLINING
import test.*
fun box(): String {
return bar { "OK" }.run()
}
@@ -0,0 +1,30 @@
// FILE: 1.kt
package test
open class Entity(val value: String)
public abstract class Task<T>() {
abstract fun calc(): T
}
fun <Self : Entity> nullableTask(factory: () -> Task<Self>): Task<Self> {
return factory()
}
inline fun<reified Self : Entity> Self.directed(): Task<Self> =
nullableTask {
object : Task<Self>() {
override fun calc(): Self = this@directed
}
}
// FILE: 2.kt
//NO_CHECK_LAMBDA_INLINING
//KT-7490
import test.*
fun box(): String {
return Entity("OK").directed().calc().value
}
@@ -0,0 +1,23 @@
// FILE: 1.kt
package test
interface Run {
fun run(): String
}
internal class A {
inline fun doSomething(): Run {
return object : Run {
override fun run(): String = "OK"
}
}
}
// FILE: 2.kt
import test.*
fun box(): String {
return A().doSomething().run()
}
@@ -0,0 +1,19 @@
// FILE: 1.kt
package test
internal class A {
inline fun doSomething(): String {
return {
"OK"
}()
}
}
// FILE: 2.kt
import test.*
fun box(): String {
return A().doSomething()
}
@@ -0,0 +1,19 @@
// FILE: 1.kt
package test
internal class A {
inline fun doSomething(s: String): String {
return {
s
}()
}
}
// FILE: 2.kt
import test.*
fun box(): String {
return A().doSomething("OK")
}
@@ -0,0 +1,54 @@
// FILE: 1.kt
package test
interface Run {
fun run(): String
}
inline fun i2(crossinline s: () -> String): Run {
return i1 {
object : Run {
override fun run(): String {
return s()
}
}.run()
}
}
inline fun i1(crossinline s: () -> String): Run {
return object : Run {
override fun run(): String {
return s()
}
}
}
// FILE: 2.kt
import test.*
inline fun i4(crossinline s: () -> String): Run {
return i3 {
object : Run {
override fun run(): String {
return s()
}
}.run()
}
}
inline fun i3(crossinline s: () -> String): Run {
return i2 {
object : Run {
override fun run(): String {
return s()
}
}.run()
}
}
fun box(): String {
val i4 = i4 { "OK" }
return i4.run()
}
@@ -0,0 +1,30 @@
// NO_CHECK_LAMBDA_INLINING
// FILE: 1.kt
package test
enum class X {
A,
B
}
inline fun test(x: X, s: (X) -> String): String {
return s(x)
}
// FILE: 2.kt
import test.*
fun box(): String {
return test(X.A) {
when(it) {
X.A-> "O"
X.B-> "K"
}
} + test(X.B) {
when(it) {
X.A-> "O"
X.B-> "K"
}
}
}
@@ -0,0 +1,22 @@
// FILE: 1.kt
package test
enum class X {
A,
B
}
inline fun test(e: X): String {
return when(e) {
X.A-> "O"
X.B-> "K"
}
}
// FILE: 2.kt
import test.*
fun box(): String {
return test(X.A) + test(X.B)
}
@@ -0,0 +1,34 @@
// FILE: 1.kt
package test
enum class X {
A,
B
}
enum class Y {
A,
B
}
inline fun test(e: X): String {
return when(e) {
X.A-> "O"
X.B-> "K"
}
}
fun funForAdditionalMappingArrayInMappingFile(e: Y): String {
return when(e) {
Y.A-> "O"
Y.B-> "K"
}
}
// FILE: 2.kt
import test.*
fun box(): String {
return test(X.A) + test(X.B)
}
@@ -0,0 +1,34 @@
// FILE: 1.kt
package test
enum class X {
A,
B
}
enum class Y {
A,
B
}
fun funForAdditionalMappingArrayInMappingFile(e: Y): String {
return when(e) {
Y.A-> "O"
Y.B-> "K"
}
}
inline fun test(e: X): String {
return when(e) {
X.A-> "O"
X.B-> "K"
}
}
// FILE: 2.kt
import test.*
fun box(): String {
return test(X.A) + test(X.B)
}
@@ -0,0 +1,34 @@
// IGNORE_BACKEND: NATIVE
// WITH_REFLECT
// FILE: 1.kt
package test
inline fun inf(crossinline cif: Any.() -> String): () -> String {
return {
object : () -> String {
override fun invoke() = cif()
}
}()
}
// FILE: 2.kt
import test.*
fun box(): String {
val simpleName = inf {
javaClass.simpleName
}()
if (simpleName != "" ) return "fail 1: $simpleName"
val name = inf {
javaClass.name
}()
if (name != "_2Kt\$box$\$inlined\$inf$2$1" ) return "fail 2: $name"
return "OK"
}
@@ -0,0 +1,25 @@
// FILE: 1.kt
package test
inline fun test(cond: Boolean, crossinline cif: () -> String): String {
return if (cond) {
{ cif() }()
}
else {
cif()
}
}
// FILE: 2.kt
import test.*
fun box(): String {
val s = "OK"
return test(true) {
{
s
}()
}
}
@@ -0,0 +1,37 @@
// FILE: 1.kt
package test
interface IZ {
fun z()
}
interface IZZ : IZ {
fun zz()
}
inline fun implZZ(zImpl: IZ, crossinline zzImpl: () -> Unit): IZZ =
object : IZZ, IZ by zImpl {
override fun zz() = zzImpl()
}
// FILE: 2.kt
import test.*
var result = "fail";
object ZImpl : IZ {
override fun z() {
result = "O"
}
}
fun box(): String {
val zz = implZZ(ZImpl) { result += "K" }
zz.z()
zz.zz()
return result
}
@@ -0,0 +1,21 @@
// FILE: 1.kt
package test
inline fun inline1(crossinline action: () -> Unit) {
action();
{ action() }()
}
inline fun inline2(crossinline action: () -> Unit) = { action() }
// FILE: 2.kt
import test.*
var result = "fail"
fun box(): String {
inline1 { inline2 { result = "OK" }() }
return result
}
@@ -0,0 +1,21 @@
// FILE: 1.kt
package test
inline fun inline1(crossinline action: () -> Unit) {
{ action () }
action();
}
inline fun inline2(crossinline action: () -> Unit) = { action() }
// FILE: 2.kt
import test.*
var result = "fail"
fun box(): String {
inline1 { inline2 { result ="OK" }() }
return result
}
@@ -0,0 +1,25 @@
// FILE: 1.kt
package test
inline fun inline1(crossinline action: () -> Unit) {
{ action () }
action();
}
inline fun inline2(crossinline action: () -> Unit) = {
action()
}
// FILE: 2.kt
import test.*
var result = "fail"
fun box(): String {
inline1 {
inline2 { { result ="OK" }() }()
}
return result
}
@@ -0,0 +1,30 @@
// IGNORE_BACKEND: NATIVE
//WITH_RUNTIME
//FULL_JDK
// FILE: 1.kt
package test
inline fun crashMe(crossinline callback: () -> Unit): Function0<Unit> {
return object: Function0<Unit> {
override fun invoke() {
callback()
}
}
}
// FILE: 2.kt
import test.*
import java.lang.reflect.Modifier
var result = "fail"
fun box(): String {
val crashMe = crashMe { result = "OK" }
val modifiers = crashMe::class.java.getDeclaredConstructor().modifiers
if (!Modifier.isPublic(modifiers)) return "fail $modifiers"
crashMe.invoke()
return result
}
@@ -0,0 +1,18 @@
// FILE: 1.kt
package test
public enum class X { A, B }
public inline fun switch(x: X): String = when (x) {
X.A -> "O"
X.B -> "K"
}
// FILE: 2.kt
import test.*
fun box(): String {
return switch(X.A) + switch(X.B)
}
@@ -0,0 +1,23 @@
// NO_CHECK_LAMBDA_INLINING
// FILE: 1.kt
package test
public inline fun <T, R> T.myLet(f: (T) -> R): R = f(this)
// FILE: 2.kt
import test.*
interface foo {
fun bar(): String
}
fun box(): String {
val baz = "OK".myLet {
object : foo {
override fun bar() = it
}
}
return baz.bar()
}
@@ -0,0 +1,31 @@
// FILE: 1.kt
package test
class Test(val _member: String) {
val _parameter: Z = test {
object : Z {
override val property = _member
}
}
}
interface Z {
val property: String
}
inline fun test(s: () -> Z): Z {
return s()
}
// FILE: 2.kt
//NO_CHECK_LAMBDA_INLINING
import test.*
fun box(): String {
val test = Test("OK")
return test._parameter.property
}
@@ -0,0 +1,35 @@
// FILE: 1.kt
package test
class Test(val _member: String) {
val _parameter: Z<Z<String>> = test {
object : Z<Z<String>> {
override val property = test {
object : Z<String> {
override val property = _member
}
}
}
}
}
interface Z<T> {
val property: T
}
inline fun <T> test(s: () -> Z<T>): Z<T> {
return s()
}
// FILE: 2.kt
//NO_CHECK_LAMBDA_INLINING
import test.*
fun box(): String {
val test = Test("OK")
return test._parameter.property.property
}
@@ -0,0 +1,29 @@
// NO_CHECK_LAMBDA_INLINING
// WITH_RUNTIME
// FILE: 1.kt
package test
inline fun inlineFun(p: () -> Unit) {
p()
}
// FILE: 2.kt
import test.*
public fun box(): String {
var z = "fail"
inlineFun {
val obj = object {
val _delegate by lazy {
z = "OK"
}
}
obj._delegate
}
return z;
}
@@ -0,0 +1,33 @@
// NO_CHECK_LAMBDA_INLINING
// WITH_RUNTIME
// FILE: 1.kt
package test
fun <T> T.noInline(p: (T) -> Unit) {
p(this)
}
inline fun inlineCall(p: () -> Unit) {
p()
}
// FILE: 2.kt
import test.*
fun box(): String {
val loci = listOf("a", "b", "c")
var gene = "g1"
inlineCall {
val value = 10.0
loci.forEach {
var locusMap = 1.0
{
locusMap = value
gene = "OK"
}()
}
}
return gene
}
@@ -0,0 +1,28 @@
// NO_CHECK_LAMBDA_INLINING
// FILE: 1.kt
package test
inline fun inlineCall(p: () -> Unit) {
p()
}
// FILE: 2.kt
import test.*
fun box(): String {
var gene = "g1"
inlineCall {
val value = 10.0
inlineCall {
{
value
gene = "OK"
}()
}
}
return gene
}
@@ -0,0 +1,27 @@
// FILE: 1.kt
package test
public inline fun myRun(block: () -> Unit) {
return block()
}
// FILE: 2.kt
//NO_CHECK_LAMBDA_INLINING
import test.*
fun box(): String {
var res = ""
myRun {
val x = object {
fun foo() {
res = "OK"
}
}
object {
fun bar() = x.foo()
}.bar()
}
return res
}
@@ -0,0 +1,29 @@
// FILE: 1.kt
package test
interface A {
fun run()
}
inline fun testNested(crossinline f: (String) -> Unit) {
object : A {
override fun run() {
f("OK")
}
}.run()
}
inline fun test(crossinline f: (String) -> Unit) {
testNested { it -> { f(it) }()}
}
// FILE: 2.kt
import test.*
fun box(): String {
var result = "fail"
test { it -> result = it }
return result
}
@@ -0,0 +1,30 @@
// NO_CHECK_LAMBDA_INLINING
// FILE: 1.kt
package test
inline fun <T> inlineFun(arg: T, f: (T) -> Unit) {
f(arg)
}
// FILE: 2.kt
import test.*
fun box(): String {
val param = "start"
var result = "fail"
inlineFun("1") { c ->
{
inlineFun("2") { a ->
{
{
result = param + c + a
}()
}()
}
}()
}
return if (result == "start12") "OK" else "fail: $result"
}
@@ -0,0 +1,27 @@
// FILE: 1.kt
package test
inline fun <T> inlineFun(arg: T, crossinline f: (T) -> Unit) {
{
f(arg)
}()
}
// FILE: 2.kt
import test.*
fun box(): String {
val param = "start"
var result = "fail"
inlineFun("2") { a ->
{
result = param + a
}()
}
return if (result == "start2") "OK" else "fail: $result"
}
@@ -0,0 +1,31 @@
// FILE: 1.kt
package test
inline fun <T> inlineFun(arg: T, crossinline f: (T) -> Unit) {
{
f(arg)
}()
}
// FILE: 2.kt
import test.*
fun box(): String {
val param = "start"
var result = "fail"
inlineFun("1") { c ->
{
inlineFun("2") { a ->
{
{
result = param + c + a
}()
}()
}
}()
}
return if (result == "start12") "OK" else "fail: $result"
}
@@ -0,0 +1,29 @@
// FILE: 1.kt
package test
inline fun <T> inlineFun(arg: T, crossinline f: (T) -> Unit) {
{
f(arg)
}()
}
// FILE: 2.kt
import test.*
fun box(): String {
val param = "start"
var result = "fail"
inlineFun("1") { c ->
{
inlineFun("2") { a ->
{
result = param + c + a
}()
}
}()
}
return if (result == "start12") "OK" else "fail: $result"
}
@@ -0,0 +1,29 @@
// FILE: 1.kt
package test
interface A {
fun run()
}
inline fun testNested(crossinline f: (String) -> Unit) {
object : A {
override fun run() {
f("OK")
}
}.run()
}
fun test(f: (String) -> Unit) {
testNested { it -> { f(it) }()}
}
// FILE: 2.kt
import test.*
fun box(): String {
var result = "fail"
test { it -> result = it }
return result
}
@@ -0,0 +1,34 @@
// FILE: 1.kt
package test
interface A {
fun run()
}
class B(val o: String, val k: String) {
inline fun testNested(crossinline f: (String) -> Unit) {
object : A {
override fun run() {
f(o)
}
}.run()
}
inline fun test(crossinline f: (String) -> Unit) {
testNested { it -> { f(it + k) }() }
}
}
// FILE: 2.kt
import test.*
fun box(): String {
var result = "fail"
B("O", "K").test { it -> result = it }
return result
}
@@ -0,0 +1,41 @@
// FILE: 1.kt
package test
class A {
val param = "start"
var result = "fail"
var addParam = "_additional_"
inline fun inlineFun(arg: String, crossinline f: (String) -> Unit) {
{
f(arg + addParam)
}()
}
fun box(): String {
{
inlineFun("1") { c ->
inlineFun("2") { a ->
{
{
result = param + c + a
}()
}()
}
}
}()
return if (result == "start1_additional_2_additional_") "OK" else "fail: $result"
}
}
// FILE: 2.kt
//NO_CHECK_LAMBDA_INLINING
import test.*
fun box(): String {
return A().box()
}
@@ -0,0 +1,39 @@
// FILE: 1.kt
package test
class A {
val param = "start"
var result = "fail"
var addParam = "_additional_"
inline fun inlineFun(arg: String, f: (String) -> Unit) {
f(arg + addParam)
}
fun box(): String {
inlineFun("1") { c ->
{
inlineFun("2") { a ->
{
{
result = param + c + a
}()
}()
}
}()
}
return if (result == "start1_additional_2_additional_") "OK" else "fail: $result"
}
}
// FILE: 2.kt
//NO_CHECK_LAMBDA_INLINING
import test.*
fun box(): String {
return A().box()
}
@@ -0,0 +1,35 @@
// FILE: 1.kt
package test
class A {
val param = "start"
var result = "fail"
var addParam = "_additional_"
inline fun inlineFun(arg: String, crossinline f: (String) -> Unit) {
{
f(arg + addParam)
}()
}
fun box(): String {
inlineFun("2") { a ->
{
result = param + a
}()
}
return if (result == "start2_additional_") "OK" else "fail: $result"
}
}
// FILE: 2.kt
//NO_CHECK_LAMBDA_INLINING
import test.*
fun box(): String {
return A().box()
}
@@ -0,0 +1,37 @@
// FILE: 1.kt
package test
class A {
val param = "start"
var result = "fail"
var addParam = "_additional_"
inline fun inlineFun(arg: String, crossinline f: (String) -> Unit) {
{
f(arg + addParam)
}()
}
fun box(): String {
{
inlineFun("2") { a ->
{
result = param + a
}()
}
}()
return if (result == "start2_additional_") "OK" else "fail: $result"
}
}
// FILE: 2.kt
//NO_CHECK_LAMBDA_INLINING
import test.*
fun box(): String {
return A().box()
}
@@ -0,0 +1,40 @@
// FILE: 1.kt
package test
class A {
val param = "start"
var result = "fail"
var addParam = "_additional_"
inline fun inlineFun(arg: String, crossinline f: (String) -> Unit) {
{
f(arg + addParam)
}()
}
fun box(): String {
inlineFun("1") { c ->
{
inlineFun("2") { a ->
{
{
result = param + c + a
}()
}()
}
}()
}
return if (result == "start1_additional_2_additional_") "OK" else "fail: $result"
}
}
// FILE: 2.kt
//NO_CHECK_LAMBDA_INLINING
import test.*
fun box(): String {
return A().box()
}
@@ -0,0 +1,40 @@
// FILE: 1.kt
package test
class A {
val param = "start"
var result = "fail"
var addParam = "_additional_"
inline fun inlineFun(arg: String, crossinline f: (String) -> Unit) {
{
f(arg + addParam)
}()
}
fun box(): String {
inlineFun("1") { c ->
{
inlineFun("2") { a ->
{
result = param + c + a
}()
}
}()
}
return if (result == "start1_additional_2_additional_") "OK" else "fail: $result"
}
}
// FILE: 2.kt
//NO_CHECK_LAMBDA_INLINING
import test.*
fun box(): String {
return A().box()
}
@@ -0,0 +1,33 @@
// FILE: 1.kt
package test
interface A {
fun run()
}
class B(val o: String, val k: String) {
inline fun testNested(crossinline f: (String) -> Unit) {
object : A {
override fun run() {
f(o)
}
}.run()
}
inline fun test(crossinline f: (String) -> Unit) {
testNested { it -> { f(it + "K") }() }
}
}
// FILE: 2.kt
import test.*
fun box(): String {
var result = "fail"
B("O", "fail").test { it -> result = it }
return result
}
@@ -0,0 +1,35 @@
// FILE: 1.kt
package test
interface A {
fun run()
}
class B(val o: String, val k: String) {
inline fun testNested(crossinline f: (String) -> Unit) {
object : A {
override fun run() {
f(o)
}
}.run()
}
fun test(f: (String) -> Unit) {
testNested { it -> { f(it + k) }() }
}
}
// FILE: 2.kt
//NO_CHECK_LAMBDA_INLINING
import test.*
fun box(): String {
var result = "fail"
B("O", "K").test { it -> result = it }
return result
}
@@ -0,0 +1,34 @@
// FILE: 1.kt
package test
interface A {
fun run()
}
class B(val o: String, val k: String) {
inline fun testNested(crossinline f2: (String) -> Unit, crossinline f3: (String) -> Unit) {
object : A {
override fun run() {
f2(o)
f3(k)
}
}.run()
}
inline fun test(crossinline f: (String) -> Unit) {
testNested ({ it -> f(it + o) }) { it -> f(it + k) }
}
}
// FILE: 2.kt
import test.*
fun box(): String {
var result = ""
B("O", "K").test { it -> result += it }
return if (result == "OOKK") "OK" else "fail: $result"
}
@@ -0,0 +1,43 @@
// FILE: 1.kt
package test
interface A {
fun run()
}
class B(val o: String, val k: String) {
inline fun testNested(crossinline f: (String) -> Unit, crossinline f2: (String) -> Unit) {
object : A {
override fun run() {
f(o)
f2(k)
}
}.run()
}
inline fun test(crossinline f: (String) -> Unit) {
call {
{
testNested ({ it -> { f(it + o) }() }) { it -> { f(it + k) }() }
}()
}
}
inline fun call(f: () -> Unit) {
f()
}
}
// FILE: 2.kt
import test.*
fun box(): String {
var result = ""
B("O", "K").test { it -> result += it }
return if (result == "OOKK") "OK" else "fail: $result"
}
@@ -0,0 +1,44 @@
// FILE: 1.kt
package test
interface A {
fun run()
}
class B(val o: String, val k: String) {
inline fun testNested(crossinline f: (String) -> Unit, crossinline f2: (String) -> Unit) {
object : A {
override fun run() {
f(o)
f2(k)
}
}.run()
}
inline fun test(crossinline f: (String) -> Unit) {
call {
f("start");
{
testNested ({ it -> { f(it + o) }() }) { it -> { f(it + k) }() }
}()
}
}
inline fun call(f: () -> Unit) {
f()
}
}
// FILE: 2.kt
import test.*
fun box(): String {
var result = ""
B("O", "K").test { it -> result += it }
return if (result == "startOOKK") "OK" else "fail: $result"
}
@@ -0,0 +1,24 @@
// FILE: 1.kt
package test
class W(val value: Any)
inline fun W.safe(crossinline body : Any.() -> Unit) {
{
this.value?.body()
}()
}
// FILE: 2.kt
import test.*
fun box(): String {
var result = "fail"
W("OK").safe {
result = this as String
}
return result
}
@@ -0,0 +1,26 @@
// FILE: 1.kt
package test
class W(val value: Any)
inline fun W.safe(crossinline body : Any.() -> Unit) {
{
this.value?.body()
}()
}
// FILE: 2.kt
import test.*
fun box(): String {
var result = "fail"
W("OK").safe {
{
result = this as String
}()
}
return result
}
@@ -0,0 +1,20 @@
// IGNORE_BACKEND: NATIVE
// FILE: 1.kt
package test
inline fun <reified T> makeRunnable(noinline lambda: ()->Unit) : Runnable {
return Runnable(lambda)
}
// FILE: 2.kt
import test.*
fun box(): String {
var result = "fail"
makeRunnable<String> { result = "OK" }.run()
return result
}
@@ -0,0 +1,31 @@
// FILE: 1.kt
package test
class A {
fun callK(): String {
return "K"
}
fun callO(): String {
return "O"
}
fun testCall(): String = test { callO() }
inline fun test(crossinline l: () -> String): String {
return {
l() + callK()
}()
}
}
// FILE: 2.kt
//NO_CHECK_LAMBDA_INLINING
import test.*
fun box(): String {
return A().testCall()
}
@@ -0,0 +1,25 @@
// FILE: 1.kt
package test
class Person(val name: String) {
fun sayName() = doSayName { name }
inline fun doSayName(crossinline call: () -> String): String {
return nestedSayName1 { nestedSayName2 { call() } }
}
fun nestedSayName1(call: () -> String) = call()
inline fun nestedSayName2(call: () -> String) = call()
}
// FILE: 2.kt
//NO_CHECK_LAMBDA_INLINING
import test.*
fun box(): String {
return Person("OK").sayName()
}
@@ -0,0 +1,28 @@
// FILE: 1.kt
package test
class Person(val name: String) {
fun sayName() = doSayName { name }
inline fun doSayName(crossinline call: () -> String): String {
return nestedSayName1 { name + Person("sub").nestedSayName2 { call() } }
}
fun nestedSayName1(call: () -> String) = call()
inline fun nestedSayName2(call: () -> String) = name + call()
}
// FILE: 2.kt
//NO_CHECK_LAMBDA_INLINING
import test.*
fun box(): String {
val res = Person("OK").sayName()
if (res != "OKsubOK") return "fail: $res"
return "OK"
}
@@ -0,0 +1,28 @@
// FILE: 1.kt
package test
class Company(val name: String) {
fun sayName() = Person("test").doSayName { name }
}
class Person(val name: String) {
inline fun doSayName(crossinline call: () -> String): String {
return companyName { parsonName { call() } }
}
inline fun parsonName(call: () -> String) = call()
fun companyName(call: () -> String) = call()
}
// FILE: 2.kt
//NO_CHECK_LAMBDA_INLINING
import test.*
fun box(): String {
return Company("OK").sayName()
}
@@ -0,0 +1,24 @@
// FILE: 1.kt
package test
fun Person.sayName() = doSayName { name }
class Person(val name: String)
inline fun Person.doSayName(crossinline call: () -> String): String {
return companyName { parsonName { call() } }
}
inline fun Person.parsonName(call: () -> String) = call()
fun Person.companyName(call: () -> String) = call()
// FILE: 2.kt
//NO_CHECK_LAMBDA_INLINING
import test.*
fun box(): String {
return Person("OK").sayName()
}
@@ -0,0 +1,41 @@
// NO_CHECK_LAMBDA_INLINING
// FILE: 1.kt
package test
inline fun test(a: String, b: String, c: () -> String): String {
return a + b + c();
}
// FILE: 2.kt
import test.*
var res = ""
fun String.id() = this
val receiver: String
get() {
res += "L"
return "L"
}
fun box(): String {
res = ""
var call = test(b = { res += "K"; "K" }(), a = { res += "O"; "O" }(), c = receiver::id)
if (res != "KOL" || call != "OKL") return "fail 1: $res != KOL or $call != OKL"
res = ""
call = test(b = { res += "K"; "K" }(), c = receiver::id, a = { res += "O"; "O" }())
if (res != "KLO" || call != "OKL") return "fail 2: $res != KLO or $call != OKL"
res = ""
call = test(c = receiver::id, b = { res += "K"; "K" }(), a = { res += "O"; "O" }())
if (res != "LKO" || call != "OKL") return "fail 3: $res != LKO or $call != OKL"
return "OK"
}
@@ -0,0 +1,41 @@
// NO_CHECK_LAMBDA_INLINING
// FILE: 1.kt
package test
inline fun test(a: String, b: Long, c: () -> String): String {
return a + b + c();
}
// FILE: 2.kt
import test.*
var res = ""
fun String.id() = this
val receiver: String
get() {
res += "L"
return "L"
}
fun box(): String {
res = ""
var call = test(b = { res += "K"; 1L }(), a = { res += "O"; "O" }(), c = receiver::id)
if (res != "KOL" || call != "O1L") return "fail 1: $res != KOL or $call != O1L"
res = ""
call = test(b = { res += "K"; 1L }(), c = receiver::id, a = { res += "O"; "O" }())
if (res != "KLO" || call != "O1L") return "fail 2: $res != KLO or $call != O1L"
res = ""
call = test(c = receiver::id, b = { res += "K"; 1L }(), a = { res += "O"; "O" }())
if (res != "LKO" || call != "O1L") return "fail 3: $res != LKO or $call != O1L"
return "OK"
}
@@ -0,0 +1,39 @@
// FILE: 1.kt
package test
inline fun test(a: Int, b: Long, crossinline c: () -> String): String {
return { "${a}_${b}_${c()}"} ()
}
// FILE: 2.kt
import test.*
fun box(): String {
var invokeOrder = "";
val expectedResult = "0_1_9"
val expectedInvokeOrder = "1_0_9"
var l = 1L
var i = 0
val captured = 9L
var result = test(b = {invokeOrder += "1_"; l}(), a = {invokeOrder+="0_"; i}(), c = {invokeOrder += "$captured"; "$captured"})
if (invokeOrder != expectedInvokeOrder || result != expectedResult) return "fail 1: $invokeOrder != $expectedInvokeOrder or $result != $expectedResult"
invokeOrder = "";
result = test(b = {invokeOrder += "1_"; l}(), c = {invokeOrder += "$captured"; "$captured"}, a = {invokeOrder+="0_"; i}())
if (invokeOrder != expectedInvokeOrder || result != expectedResult) return "fail 2: $invokeOrder != $expectedInvokeOrder or $result != $expectedResult"
invokeOrder = "";
result = test(c = {invokeOrder += "$captured"; "$captured"}, b = {invokeOrder += "1_"; l}(), a = {invokeOrder+="0_"; i}())
if (invokeOrder != expectedInvokeOrder || result != expectedResult) return "fail 3: $invokeOrder != $expectedInvokeOrder or $result != $expectedResult"
invokeOrder = "";
result = test(a = {invokeOrder+="0_"; i}(), c = {invokeOrder += "$captured"; "$captured"}, b = {invokeOrder += "1_"; l}())
if (invokeOrder != "0_1_9" || result != expectedResult) return "fail 4: $invokeOrder != 0_1_9 or $result != $expectedResult"
return "OK"
}
@@ -0,0 +1,39 @@
// FILE: 1.kt
package test
inline fun Double.test(a: Int, b: Long, crossinline c: () -> String): String {
return { "${this}_${a}_${b}_${c()}"} ()
}
// FILE: 2.kt
import test.*
fun box(): String {
var invokeOrder = "";
val expectedResult = "1.0_0_1_9"
val expectedInvokeOrder = "1_0_9"
var l = 1L
var i = 0
val captured = 9L
var result = 1.0.test(b = {invokeOrder += "1_"; l}(), a = {invokeOrder+="0_"; i}(), c = {invokeOrder += "$captured"; "$captured"})
if (invokeOrder != expectedInvokeOrder || result != expectedResult) return "fail 1: $invokeOrder != $expectedInvokeOrder or $result != $expectedResult"
invokeOrder = "";
result = 1.0.test(b = {invokeOrder += "1_"; l}(), c = {invokeOrder += "${captured}"; "${captured}"}, a = {invokeOrder+="0_"; i}())
if (invokeOrder != expectedInvokeOrder || result != expectedResult) return "fail 2: $invokeOrder != $expectedInvokeOrder or $result != $expectedResult"
invokeOrder = "";
result = 1.0.test(c = {invokeOrder += "${captured}"; "${captured}"}, b = {invokeOrder += "1_"; l}(), a = {invokeOrder+="0_"; i}())
if (invokeOrder != expectedInvokeOrder || result != expectedResult) return "fail 3: $invokeOrder != $expectedInvokeOrder or $result != $expectedResult"
invokeOrder = "";
result = 1.0.test(a = {invokeOrder+="0_"; i}(), c = {invokeOrder += "${captured}"; "${captured}"}, b = {invokeOrder += "1_"; l}())
if (invokeOrder != "0_1_9" || result != expectedResult) return "fail 4: $invokeOrder != 0_1_9 or $result != $expectedResult"
return "OK"
}
@@ -0,0 +1,39 @@
// NO_CHECK_LAMBDA_INLINING
// FILE: 1.kt
package test
inline fun Double.test(a: Int, b: Long, c: () -> String): String {
return "${this}_${a}_${b}_${c()}"
}
// FILE: 2.kt
import test.*
fun box(): String {
var invokeOrder = "";
val expectedResult = "1.0_0_1_L"
val expectedInvokeOrder = "1_0_L"
var l = 1L
var i = 0
var result = 1.0.test(b = {invokeOrder += "1_"; l}(), a = {invokeOrder+="0_"; i}(), c = {invokeOrder += "L"; "L"})
if (invokeOrder != expectedInvokeOrder || result != expectedResult) return "fail 1: $invokeOrder != $expectedInvokeOrder or $result != $expectedResult"
invokeOrder = "";
result = 1.0.test(b = {invokeOrder += "1_"; l}(), c = {invokeOrder += "L"; "L"}, a = {invokeOrder+="0_"; i}())
if (invokeOrder != expectedInvokeOrder || result != expectedResult) return "fail 2: $invokeOrder != $expectedInvokeOrder or $result != $expectedResult"
invokeOrder = "";
result = 1.0.test(c = {invokeOrder += "L"; "L"}, b = {invokeOrder += "1_"; l}(), a = {invokeOrder+="0_"; i}())
if (invokeOrder != expectedInvokeOrder || result != expectedResult) return "fail 3: $invokeOrder != $expectedInvokeOrder or $result != $expectedResult"
invokeOrder = "";
result = 1.0.test(a = {invokeOrder+="0_"; i}(), c = {invokeOrder += "L"; "L"}, b = {invokeOrder += "1_"; l}())
if (invokeOrder != "0_1_L" || result != expectedResult) return "fail 4: $invokeOrder != 0_1_L or $result != $expectedResult"
return "OK"
}
@@ -0,0 +1,43 @@
// NO_CHECK_LAMBDA_INLINING
// FILE: 1.kt
// WITH_RUNTIME
package test
class Z {
inline fun Double.test(a: Int, b: Long, c: () -> String): String {
return "${this}_${a}_${b}_${c()}"
}
}
// FILE: 2.kt
import test.*
fun box(): String {
with (Z()) {
var invokeOrder = "";
val expectedResult = "1.0_0_1_L"
val expectedInvokeOrder = "1_0_L"
var l = 1L
var i = 0
var result = 1.0.test(b = { invokeOrder += "1_"; l }(), a = { invokeOrder += "0_"; i }(), c = { invokeOrder += "L"; "L" })
if (invokeOrder != expectedInvokeOrder || result != expectedResult) return "fail 1: $invokeOrder != $expectedInvokeOrder or $result != $expectedResult"
invokeOrder = "";
result = 1.0.test(b = { invokeOrder += "1_"; l }(), c = { invokeOrder += "L"; "L" }, a = { invokeOrder += "0_"; i }())
if (invokeOrder != expectedInvokeOrder || result != expectedResult) return "fail 2: $invokeOrder != $expectedInvokeOrder or $result != $expectedResult"
invokeOrder = "";
result = 1.0.test(c = { invokeOrder += "L"; "L" }, b = { invokeOrder += "1_"; l }(), a = { invokeOrder += "0_"; i }())
if (invokeOrder != expectedInvokeOrder || result != expectedResult) return "fail 3: $invokeOrder != $expectedInvokeOrder or $result != $expectedResult"
invokeOrder = "";
result = 1.0.test(a = { invokeOrder += "0_"; i }(), c = { invokeOrder += "L"; "L" }, b = { invokeOrder += "1_"; l }())
if (invokeOrder != "0_1_L" || result != expectedResult) return "fail 4: $invokeOrder != 0_1_L or $result != $expectedResult"
}
return "OK"
}
@@ -0,0 +1,30 @@
// NO_CHECK_LAMBDA_INLINING
// FILE: 1.kt
package test
inline fun test(a: String, b: String, c: () -> String): String {
return a + b + c();
}
// FILE: 2.kt
import test.*
fun box(): String {
var res = "";
var call = test(a = {res += "K"; "K"}(), b = {res+="O"; "O"}(), c = {res += "L"; "L"})
if (res != "KOL" || call != "KOL") return "fail 1: $res != KOL or $call != KOL"
res = "";
call = test(a = {res += "K"; "K"}(), c = {res += "L"; "L"}, b = {res+="O"; "O"}())
if (res != "KOL" || call != "KOL") return "fail 2: $res != KOL or $call != KOL"
res = "";
call = test(c = {res += "L"; "L"}, a = {res += "K"; "K"}(), b = {res+="O"; "O"}())
if (res != "KOL" || call != "KOL") return "fail 3: $res != KOL or $call != KOL"
return "OK"
}
@@ -0,0 +1,34 @@
// NO_CHECK_LAMBDA_INLINING
// FILE: 1.kt
package test
class Z(val p: String) {
inline fun test(a: String, b: String, c: () -> String): String {
return a + b + c() + p;
}
}
// FILE: 2.kt
import test.*
fun box(): String {
var res = "";
var call = Z("Z").test(a = {res += "K"; "K"}(), b = {res+="O"; "O"}(), c = {res += "L"; "L"})
if (res != "KOL" || call != "KOLZ") return "fail 1: $res != KOL or $call != KOLZ"
res = "";
call = Z("Z").test(a = {res += "K"; "K"}(), c = {res += "L"; "L"}, b = {res+="O"; "O"}())
if (res != "KOL" || call != "KOLZ") return "fail 2: $res != KOL or $call != KOLZ"
res = "";
call = Z("Z").test(c = {res += "L"; "L"}, a = {res += "K"; "K"}(), b = {res+="O"; "O"}())
if (res != "KOL" || call != "KOLZ") return "fail 3: $res != KOL or $call != KOLZ"
return "OK"
}
@@ -0,0 +1,30 @@
// NO_CHECK_LAMBDA_INLINING
// FILE: 1.kt
package test
inline fun test(a: String, b: String, c: () -> String): String {
return a + b + c();
}
// FILE: 2.kt
import test.*
fun box(): String {
var res = "";
var call = test(b = {res += "K"; "K"}(), a = {res+="O"; "O"}(), c = {res += "L"; "L"})
if (res != "KOL" || call != "OKL") return "fail 1: $res != KOL or $call != OKL"
res = "";
call = test(b = {res += "K"; "K"}(), c = {res += "L"; "L"}, a = {res+="O"; "O"}())
if (res != "KOL" || call != "OKL") return "fail 2: $res != KOL or $call != OKL"
res = "";
call = test(c = {res += "L"; "L"}, b = {res += "K"; "K"}(), a = {res+="O"; "O"}())
if (res != "KOL" || call != "OKL") return "fail 3: $res != KOL or $call != OKL"
return "OK"
}
@@ -0,0 +1,32 @@
// NO_CHECK_LAMBDA_INLINING
// FILE: 1.kt
package test
class Z(val p: String) {
inline fun test(a: String, b: String, c: () -> String): String {
return a + b + c() + p;
}
}
// FILE: 2.kt
import test.*
fun box(): String {
var res = "";
var call = Z("Z").test(b = {res += "K"; "K"}(), a = {res+="O"; "O"}(), c = {res += "L"; "L"})
if (res != "KOL" || call != "OKLZ") return "fail 1: $res != KOL or $call != OKLZ"
res = "";
call = Z("Z").test(b = {res += "K"; "K"}(), c = {res += "L"; "L"}, a = {res+="O"; "O"}())
if (res != "KOL" || call != "OKLZ") return "fail 2: $res != KOL or $call != OKLZ"
res = "";
call = Z("Z").test(c = {res += "L"; "L"}, b = {res += "K"; "K"}(), a = {res+="O"; "O"}())
if (res != "KOL" || call != "OKLZ") return "fail 3: $res != KOL or $call != OKLZ"
return "OK"
}
@@ -0,0 +1,29 @@
// FILE: 1.kt
package test
var res = 1
inline operator fun Int.get(z: Int, p: Int) = this + z + p
inline operator fun Int.set(z: Int, p: Int, l: Int) {
res = this + z + p + l
}
// FILE: 2.kt
import test.*
fun box(): String {
val z = 1;
val p = z[2, 3]
if (p != 6) return "fail 1: $p"
z[2, 3] = p
if (res != 12) return "fail 2: $res"
return "OK"
}
@@ -0,0 +1,35 @@
// FILE: 1.kt
// WITH_RUNTIME
package test
var res = 1
class A {
inline operator fun Int.get(z: Int, p: Int) = this + z + p
inline operator fun Int.set(z: Int, p: Int, l: Int) {
res = this + z + p + l
}
}
// FILE: 2.kt
import test.*
fun box(): String {
with(A()) {
val z = 1;
val p = z[2, 3]
if (p != 6) return "fail 1: $p"
z[2, 3] = p
if (res != 12) return "fail 2: $res"
}
return "OK"
}
@@ -0,0 +1,30 @@
// FILE: 1.kt
package test
var res = 1
inline operator fun Int.get(z: Int, p: () -> Int, defaultt: Int = 100) = this + z + p() + defaultt
inline operator fun Int.set(z: Int, p: () -> Int, l: Int/*, x : Int = 1000*/) {
res = this + z + p() + l /*+ x*/
}
// FILE: 2.kt
import test.*
fun box(): String {
val z = 1;
val p = z[2, { 3 }]
if (p != 106) return "fail 1: $p"
val captured = 3;
z[2, { captured } ] = p
if (res != 112) return "fail 2: $res"
return "OK"
}
@@ -0,0 +1,36 @@
// FILE: 1.kt
// WITH_RUNTIME
package test
var res = 1
class A {
inline operator fun Int.get(z: Int, p: () -> Int, defaultt: Int = 100) = this + z + p() + defaultt
inline operator fun Int.set(z: Int, p: () -> Int, l: Int/*, x : Int = 1000*/) {
res = this + z + p() + l /*+ x*/
}
}
// FILE: 2.kt
import test.*
fun box(): String {
val z = 1;
with(A()) {
val p = z[2, { 3 }]
if (p != 106) return "fail 1: $p"
val captured = 3;
z[2, { captured }] = p
if (res != 112) return "fail 2: $res"
}
return "OK"
}
@@ -0,0 +1,30 @@
// FILE: 1.kt
package test
var res = 1
inline operator fun Int.get(z: Int, p: () -> Int) = this + z + p()
inline operator fun Int.set(z: Int, p: () -> Int, l: Int) {
res = this + z + p() + l
}
// FILE: 2.kt
import test.*
fun box(): String {
val z = 1;
val p = z[2, { 3 }]
if (p != 6) return "fail 1: $p"
val captured = 3;
z[2, { captured } ] = p
if (res != 12) return "fail 2: $res"
return "OK"
}
@@ -0,0 +1,37 @@
// FILE: 1.kt
// WITH_RUNTIME
package test
var res = 1
class A {
inline operator fun Int.get(z: Int, p: () -> Int) = this + z + p()
inline operator fun Int.set(z: Int, p: () -> Int, l: Int) {
res = this + z + p() + l
}
}
// FILE: 2.kt
import test.*
fun box(): String {
val z = 1;
with(A()) {
val p = z[2, { 3 }]
if (p != 6) return "fail 1: $p"
val captured = 3;
z[2, { captured }] = p
if (res != 12) return "fail 2: $res"
}
return "OK"
}
@@ -0,0 +1,288 @@
// IGNORE_BACKEND: NATIVE
// FILE: 1.kt
// WITH_RUNTIME
package builders
import java.util.ArrayList
import java.util.HashMap
abstract class Element {
abstract fun render(builder: StringBuilder, indent: String)
override fun toString(): String {
val builder = StringBuilder()
render(builder, "")
return builder.toString()
}
}
class TextElement(val text: String) : Element() {
override fun render(builder: StringBuilder, indent: String) {
builder.append("$indent$text\n")
}
}
abstract class Tag(val name: String) : Element() {
val children = ArrayList<Element>()
val attributes = HashMap<String, String>()
inline protected fun <T : Element> initTag(tag: T, init: T.() -> Unit): T {
tag.init()
children.add(tag)
return tag
}
override fun render(builder: StringBuilder, indent: String) {
builder.append("$indent<$name${renderAttributes()}>\n")
for (c in children) {
c.render(builder, indent + " ")
}
builder.append("$indent</$name>\n")
}
private fun renderAttributes(): String? {
val builder = StringBuilder()
for (a in attributes.keys) {
builder.append(" $a=\"${attributes[a]}\"")
}
return builder.toString()
}
}
abstract class TagWithText(name: String) : Tag(name) {
operator fun String.unaryPlus() {
children.add(TextElement(this))
}
}
class HTML() : TagWithText("html") {
inline fun head(init: Head.() -> Unit) = initTag(Head(), init)
inline fun body(init: Body.() -> Unit) = initTag(Body(), init)
fun bodyNoInline(init: Body.() -> Unit) = initTag(Body(), init)
}
class Head() : TagWithText("head") {
inline fun title(init: Title.() -> Unit) = initTag(Title(), init)
}
class Title() : TagWithText("title")
abstract class BodyTag(name: String) : TagWithText(name) {
inline fun b(init: B.() -> Unit) = initTag(B(), init)
inline fun p(init: P.() -> Unit) = initTag(P(), init)
inline fun pNoInline(init: P.() -> Unit) = initTag(P(), init)
inline fun h1(init: H1.() -> Unit) = initTag(H1(), init)
inline fun ul(init: UL.() -> Unit) = initTag(UL(), init)
inline fun a(href: String, init: A.() -> Unit) {
val a = initTag(A(), init)
a.href = href
}
}
class Body() : BodyTag("body")
class UL() : BodyTag("ul") {
inline fun li(init: LI.() -> Unit) = initTag(LI(), init)
}
class B() : BodyTag("b")
class LI() : BodyTag("li")
class P() : BodyTag("p")
class H1() : BodyTag("h1")
class A() : BodyTag("a") {
public var href: String
get() = attributes["href"]!!
set(value) {
attributes["href"] = value
}
}
inline fun html(init: HTML.() -> Unit): HTML {
val html = HTML()
html.init()
return html
}
fun htmlNoInline(init: HTML.() -> Unit): HTML {
val html = HTML()
html.init()
return html
}
// FILE: 2.kt
//NO_CHECK_LAMBDA_INLINING
import builders.*
fun testAllInline() : String {
val args = arrayOf("1", "2", "3")
val result =
html {
val htmlVal = 0
head {
title { +"XML encoding with Kotlin" }
}
body {
var bodyVar = 1
h1 { +"XML encoding with Kotlin" }
p { +"this format can be used as an alternative markup to XML" }
// an element with attributes and text content
a(href = "http://jetbrains.com/kotlin") { +"Kotlin" }
// mixed content
p {
+"This is some"
b { +"mixed" }
+"text. For more see the"
a(href = "http://jetbrains.com/kotlin") { +"Kotlin" }
+"project"
}
p { +"some text" }
// content generated from command-line arguments
p {
+"Command line arguments were:"
ul {
for (arg in args)
li { +arg; +"$htmlVal"; +"$bodyVar" }
}
}
}
}
return result.toString()!!
}
fun testHtmlNoInline() : String {
val args = arrayOf("1", "2", "3")
val result =
htmlNoInline() {
val htmlVal = 0
head {
title { +"XML encoding with Kotlin" }
}
body {
var bodyVar = 1
h1 { +"XML encoding with Kotlin" }
p { +"this format can be used as an alternative markup to XML" }
// an element with attributes and text content
a(href = "http://jetbrains.com/kotlin") { +"Kotlin" }
// mixed content
p {
+"This is some"
b { +"mixed" }
+"text. For more see the"
a(href = "http://jetbrains.com/kotlin") { +"Kotlin" }
+"project"
}
p { +"some text" }
// content generated from command-line arguments
p {
+"Command line arguments were:"
ul {
for (arg in args)
li { +arg; +"$htmlVal"; +"$bodyVar" }
}
}
}
}
return result.toString()!!
}
fun testBodyNoInline() : String {
val args = arrayOf("1", "2", "3")
val result =
html {
val htmlVal = 0
head {
title { +"XML encoding with Kotlin" }
}
bodyNoInline {
var bodyVar = 1
h1 { +"XML encoding with Kotlin" }
p { +"this format can be used as an alternative markup to XML" }
// an element with attributes and text content
a(href = "http://jetbrains.com/kotlin") { +"Kotlin" }
// mixed content
p {
+"This is some"
b { +"mixed" }
+"text. For more see the"
a(href = "http://jetbrains.com/kotlin") { +"Kotlin" }
+"project"
}
p { +"some text" }
// content generated from command-line arguments
p {
+"Command line arguments were:"
ul {
for (arg in args)
li { +arg; +"$htmlVal"; +"$bodyVar" }
}
}
}
}
return result.toString()!!
}
fun testBodyHtmlNoInline() : String {
val args = arrayOf("1", "2", "3")
val result =
htmlNoInline {
val htmlVal = 0
head {
title { +"XML encoding with Kotlin" }
}
bodyNoInline {
var bodyVar = 1
h1 { +"XML encoding with Kotlin" }
p { +"this format can be used as an alternative markup to XML" }
// an element with attributes and text content
a(href = "http://jetbrains.com/kotlin") { +"Kotlin" }
// mixed content
p {
+"This is some"
b { +"mixed" }
+"text. For more see the"
a(href = "http://jetbrains.com/kotlin") { +"Kotlin" }
+"project"
}
p { +"some text" }
// content generated from command-line arguments
p {
+"Command line arguments were:"
ul {
for (arg in args)
li { +arg; +"$htmlVal"; +"$bodyVar" }
}
}
}
}
return result.toString()!!
}
fun box(): String {
var expected = testAllInline();
if (expected != testHtmlNoInline()) return "fail 1: ${testHtmlNoInline()}\nbut expected\n${expected} "
if (expected != testBodyNoInline()) return "fail 2: ${testBodyNoInline()}\nbut expected\n${expected} "
if (expected != testBodyHtmlNoInline()) return "fail 3: ${testBodyHtmlNoInline()}\nbut expected\n${expected} "
return "OK"
}
@@ -0,0 +1,292 @@
// IGNORE_BACKEND: NATIVE
// FILE: 1.kt
// WITH_RUNTIME
package builders
import java.util.ArrayList
import java.util.HashMap
abstract class Element {
abstract fun render(builder: StringBuilder, indent: String)
override fun toString(): String {
val builder = StringBuilder()
render(builder, "")
return builder.toString()
}
}
class TextElement(val text: String) : Element() {
override fun render(builder: StringBuilder, indent: String) {
builder.append("$indent$text\n")
}
}
abstract class Tag(val name: String) : Element() {
val children = ArrayList<Element>()
val attributes = HashMap<String, String>()
inline protected fun <T : Element> initTag(tag: T, init: T.() -> Unit): T {
tag.init()
children.add(tag)
return tag
}
override fun render(builder: StringBuilder, indent: String) {
builder.append("$indent<$name${renderAttributes()}>\n")
for (c in children) {
c.render(builder, indent + " ")
}
builder.append("$indent</$name>\n")
}
private fun renderAttributes(): String? {
val builder = StringBuilder()
for (a in attributes.keys) {
builder.append(" $a=\"${attributes[a]}\"")
}
return builder.toString()
}
}
abstract class TagWithText(name: String) : Tag(name) {
operator fun String.unaryPlus() {
children.add(TextElement(this))
}
}
class HTML() : TagWithText("html") {
inline fun head(init: Head.() -> Unit) = initTag(Head(), init)
inline fun body(init: Body.() -> Unit) = initTag(Body(), init)
fun bodyNoInline(init: Body.() -> Unit) = initTag(Body(), init)
}
class Head() : TagWithText("head") {
inline fun title(init: Title.() -> Unit) = initTag(Title(), init)
}
class Title() : TagWithText("title")
abstract class BodyTag(name: String) : TagWithText(name) {
inline fun b(init: B.() -> Unit) = initTag(B(), init)
inline fun p(init: P.() -> Unit) = initTag(P(), init)
fun pNoInline(init: P.() -> Unit) = initTag(P(), init)
inline fun h1(init: H1.() -> Unit) = initTag(H1(), init)
inline fun ul(init: UL.() -> Unit) = initTag(UL(), init)
inline fun a(href: String, init: A.() -> Unit) {
val a = initTag(A(), init)
a.href = href
}
}
class Body() : BodyTag("body")
class UL() : BodyTag("ul") {
inline fun li(init: LI.() -> Unit) = initTag(LI(), init)
}
class B() : BodyTag("b")
class LI() : BodyTag("li")
class P() : BodyTag("p")
class H1() : BodyTag("h1")
class A() : BodyTag("a") {
public var href: String
get() = attributes["href"]!!
set(value) {
attributes["href"] = value
}
}
inline fun html(init: HTML.() -> Unit): HTML {
val html = HTML()
html.init()
return html
}
fun htmlNoInline(init: HTML.() -> Unit): HTML {
val html = HTML()
html.init()
return html
}
// FILE: 2.kt
//NO_CHECK_LAMBDA_INLINING
import builders.*
inline fun testAllInline(f: () -> String) : String {
val args = arrayOf("1", "2", "3")
val result =
html {
val htmlVal = 0
head {
title { +"XML encoding with Kotlin" }
}
body {
var bodyVar = 1
h1 { +"XML encoding with Kotlin" }
p { +"this format can be used as an alternative markup to XML" }
// an element with attributes and text content
a(href = "http://jetbrains.com/kotlin") { +"Kotlin" }
// mixed content
p {
+"This is some"
b { +"mixed" }
+"text. For more see the"
a(href = "http://jetbrains.com/kotlin") { +"Kotlin" }
+"project"
}
p { +"some text" }
// content generated from command-line arguments
p {
+"Command line arguments were:"
ul {
for (arg in args)
li { +arg; +"$htmlVal"; +"$bodyVar"; +"${f()}" }
}
}
}
}
return result.toString()!!
}
inline fun testHtmlNoInline(crossinline f: () -> String) : String {
val args = arrayOf("1", "2", "3")
val result =
htmlNoInline() {
val htmlVal = 0
head {
title { +"XML encoding with Kotlin" }
}
body {
var bodyVar = 1
h1 { +"XML encoding with Kotlin" }
p { +"this format can be used as an alternative markup to XML" }
// an element with attributes and text content
a(href = "http://jetbrains.com/kotlin") { +"Kotlin" }
// mixed content
p {
+"This is some"
b { +"mixed" }
+"text. For more see the"
a(href = "http://jetbrains.com/kotlin") { +"Kotlin" }
+"project"
}
p { +"some text" }
// content generated from command-line arguments
p {
+"Command line arguments were:"
ul {
for (arg in args)
li { +arg; +"$htmlVal"; +"$bodyVar"; +"${f()}" }
}
}
}
}
return result.toString()!!
}
inline fun testBodyNoInline(crossinline f: () -> String) : String {
val args = arrayOf("1", "2", "3")
val result =
html {
val htmlVal = 0
head {
title { +"XML encoding with Kotlin" }
}
bodyNoInline {
var bodyVar = 1
h1 { +"XML encoding with Kotlin" }
p { +"this format can be used as an alternative markup to XML" }
// an element with attributes and text content
a(href = "http://jetbrains.com/kotlin") { +"Kotlin" }
// mixed content
p {
+"This is some"
b { +"mixed" }
+"text. For more see the"
a(href = "http://jetbrains.com/kotlin") { +"Kotlin" }
+"project"
}
p { +"some text" }
// content generated from command-line arguments
p {
+"Command line arguments were:"
ul {
for (arg in args)
li { +arg; +"$htmlVal"; +"$bodyVar"; +"${f()}" }
}
}
}
}
return result.toString()!!
}
inline fun testBodyHtmlNoInline(crossinline f: () -> String) : String {
val args = arrayOf("1", "2", "3")
val result =
htmlNoInline {
val htmlVal = 0
head {
title { +"XML encoding with Kotlin" }
}
bodyNoInline {
var bodyVar = 1
h1 { +"XML encoding with Kotlin" }
p { +"this format can be used as an alternative markup to XML" }
// an element with attributes and text content
a(href = "http://jetbrains.com/kotlin") { +"Kotlin" }
// mixed content
p {
+"This is some"
b { +"mixed" }
+"text. For more see the"
a(href = "http://jetbrains.com/kotlin") { +"Kotlin" }
+"project"
}
p { +"some text" }
// content generated from command-line arguments
p {
+"Command line arguments were:"
ul {
for (arg in args)
li { +arg; +"$htmlVal"; +"$bodyVar"; +"${f()}" }
}
}
}
}
return result.toString()!!
}
fun box(): String {
var expected = testAllInline({"x"});
print(expected + " " + testHtmlNoInline({"x"}))
if (expected != testHtmlNoInline({"x"})) return "fail 1: ${testHtmlNoInline({"x"})}\nbut expected\n${expected} "
if (expected != testBodyNoInline({"x"})) return "fail 2: ${testBodyNoInline({"x"})}\nbut expected\n${expected} "
if (expected != testBodyHtmlNoInline({"x"})) return "fail 3: ${testBodyHtmlNoInline({"x"})}\nbut expected\n${expected} "
var captured = "x"
if (expected != testHtmlNoInline({captured})) return "fail 4: ${testHtmlNoInline({captured})}\nbut expected\n${expected} "
if (expected != testBodyNoInline({captured})) return "fail 5: ${testBodyNoInline({captured})}\nbut expected\n${expected} "
if (expected != testBodyHtmlNoInline({captured})) return "fail 6: ${testBodyHtmlNoInline({captured})}\nbut expected\n${expected} "
return "OK"
}
@@ -0,0 +1,17 @@
// FILE: 1.kt
package test
class Foo(val a: String)
inline fun test(s: () -> String): String {
return s()
}
// FILE: 2.kt
import test.*
fun box(): String {
return test(Foo("OK")::a)
}
@@ -0,0 +1,17 @@
// FILE: 1.kt
package test
inline fun go(f: () -> String) = f()
fun String.id(): String = this
fun foo(x: String, y: String): String {
return go((x + y)::id)
}
// FILE: 2.kt
import test.*
fun box() = foo("O", "K")
@@ -0,0 +1,20 @@
// FILE: 1.kt
package test
inline fun foo(x: () -> String, z: String) = x() + z
fun String.id() = this
// FILE: 2.kt
import test.*
fun String.test() : String {
return foo(this::id, "K")
}
fun box() : String {
return "O".test()
}
@@ -0,0 +1,21 @@
// WITH_RUNTIME
// FILE: 1.kt
package test
inline fun stub(f: () -> String): String = f()
// FILE: 2.kt
import test.*
class A(val z: String) {
fun filter(s: String) = z == s
}
fun box(): String {
val a = A("OK")
val s = arrayOf("OK")
return s.filter(a::filter).first()
}
@@ -0,0 +1,17 @@
// FILE: 1.kt
package test
inline fun foo(x: (String) -> String, z: String) = x(z)
fun String.id() = this
// FILE: 2.kt
import test.*
fun box() : String {
var zeroSlot = "fail";
val z = "O"
return foo(z::plus, "K")
}
@@ -0,0 +1,21 @@
// WITH_RUNTIME
// FILE: 1.kt
package test
inline fun stub(f: () -> String): String = f()
// FILE: 2.kt
import test.*
class A(val z: String) {
fun map(s: String) = z + s
}
fun box(): String {
val a = A("O")
val s = arrayOf("K")
return s.map(a::map).first()
}
@@ -0,0 +1,19 @@
// FILE: 1.kt
package test
object Foo {
val a: String = "OK"
}
inline fun test(s: () -> String): String {
return s()
}
// FILE: 2.kt
import test.*
fun box(): String {
return test(Foo::a)
}
@@ -0,0 +1,20 @@
// FILE: 1.kt
package test
object Foo {
val a: String = "OK"
}
inline fun test(s: () -> String): String {
return s()
}
// FILE: 2.kt
import test.Foo.a
import test.test
fun box(): String {
return test(::a)
}
@@ -0,0 +1,17 @@
// FILE: 1.kt
package test
inline fun foo(x: () -> String, z: String) = x() + z
fun String.id() = this
// FILE: 2.kt
import test.*
fun box() : String {
var zeroSlot = "fail";
val z = "O"
return foo(z::id, "K")
}
@@ -0,0 +1,20 @@
// FILE: 1.kt
package test
class Foo(val z: String)
val Foo.a: String
get() = z
inline fun test(s: () -> String): String {
return s()
}
// FILE: 2.kt
import test.*
fun box(): String {
return test(Foo("OK")::a)
}
@@ -0,0 +1,20 @@
// FILE: 1.kt
package test
class A(val z: Int) {
fun calc() = z
}
inline fun call(p: A, s: A.() -> Int): Int {
return p.s()
}
// FILE: 2.kt
import test.*
fun box() : String {
val call = call(A(11), A::calc)
return if (call == 11) "OK" else "fail"
}
@@ -0,0 +1,22 @@
// FILE: 1.kt
package test
class A(val z: Int) {
fun calc() = z
fun test() = call(A(z), A::calc)
}
inline fun call(p: A, s: A.() -> Int): Int {
return p.s()
}
// FILE: 2.kt
import test.*
fun box() : String {
val call = A(11).test()
return if (call == 11) "OK" else "fail"
}
@@ -0,0 +1,20 @@
// FILE: 1.kt
package test
class A(val z: Int) {
fun calc() = z
}
inline fun call(p: Int, s: (Int) -> A): Int {
return s(p).z
}
// FILE: 2.kt
import test.*
fun box() : String {
val call = call(11, ::A)
return if (call == 11) "OK" else "fail"
}
@@ -0,0 +1,16 @@
// Enable when callable references to builtin members and using lambdas as extension lambdas (KT-13312) is supported
// FILE: 1.kt
package test
inline fun call(a: String, b: String, s: String.(String) -> String): String {
return a.s(b)
}
// FILE: 2.kt
import test.*
fun box() : String {
return call("O", "K", String::plus)
}
@@ -0,0 +1,40 @@
// FILE: 1.kt
package test
inline fun linearLayout2(init: X.() -> Unit) {
return X().init()
}
var result = "fail"
class X {
fun calc() {
result = "OK"
}
}
// FILE: 2.kt
//NO_CHECK_LAMBDA_INLINING
import test.*
class A {
fun test() {
linearLayout2 {
{
apply2 {
this@linearLayout2::calc
}()
}()
}
}
public fun <T, Z> T.apply2(block: T.() -> Z): Z {
return block()
}
}
fun box(): String {
A().test()
return result
}
@@ -0,0 +1,17 @@
// FILE: 1.kt
inline fun <R> startFlow(
flowConstructor: (String) -> R
): R {
return flowConstructor("OK")
}
object Foo {
class Requester(val dealToBeOffered: String)
}
// FILE: 2.kt
fun box(): String {
return startFlow(Foo::Requester).dealToBeOffered
}
@@ -0,0 +1,16 @@
// Enable when callable references to builtin members and using lambdas as extension lambdas (KT-13312) is supported
// FILE: 1.kt
package test
inline fun call(p: String, s: String.() -> Int): Int {
return p.s()
}
// FILE: 2.kt
import test.*
fun box() : String {
return if (call("123", String::length) == 3) "OK" else "fail"
}
@@ -0,0 +1,17 @@
// FILE: 1.kt
package test
class Foo(val a: String)
inline fun <T> test(receiver: T, selector: (T) -> String): String {
return selector(receiver)
}
// FILE: 2.kt
import test.*
fun box(): String {
return test(Foo("OK"), Foo::a)
}
@@ -0,0 +1,19 @@
// FILE: 1.kt
package test
inline fun call(p: Int, s: (Int) -> Int): Int {
return s(p)
}
// FILE: 2.kt
import test.*
fun box() : String {
return if (call(10, ::calc) == 5) "OK" else "fail"
}
fun calc(p: Int) : Int {
return p / 2
}
@@ -0,0 +1,19 @@
// FILE: 1.kt
package test
inline fun call(p: Int, s: Int.(Int) -> Int): Int {
return p.s(p)
}
// FILE: 2.kt
import test.*
fun box() : String {
return if (call(10, Int::calc) == 100) "OK" else "fail"
}
fun Int.calc(p: Int) : Int {
return p * this
}
@@ -0,0 +1,18 @@
// FILE: 1.kt
package test
val a: String
get() = "OK"
inline fun test(s: () -> String): String {
return s()
}
// FILE: 2.kt
import test.*
fun box(): String {
return test(::a)
}
@@ -0,0 +1,27 @@
// FILE: 1.kt
package test
inline fun <R> doWork(crossinline job: ()-> R) : R {
return notInline({job()})
}
fun <R> notInline(job: ()-> R) : R {
return job()
}
// FILE: 2.kt
//NO_CHECK_LAMBDA_INLINING
import test.*
fun box(): String {
val result = doWork({11})
if (result != 11) return "test1: ${result}"
val result2 = doWork({12; result+1})
if (result2 != 12) return "test2: ${result2}"
return "OK"
}
@@ -0,0 +1,28 @@
// FILE: 1.kt
package test
inline fun <R> doWork(crossinline job: ()-> R) : R {
val k = 10;
return notInline({k; job()})
}
fun <R> notInline(job: ()-> R) : R {
return job()
}
// FILE: 2.kt
//NO_CHECK_LAMBDA_INLINING
import test.*
fun box(): String {
val result = doWork({11})
if (result != 11) return "test1: ${result}"
val result2 = doWork({12; result+1})
if (result2 != 12) return "test2: ${result2}"
return "OK"
}
@@ -0,0 +1,38 @@
// FILE: 1.kt
class My(val value: Int)
inline fun <T, R> T.perform(job: (T)-> R) : R {
return job(this)
}
// FILE: 2.kt
fun test1() : Int {
val inlineX = My(111)
return inlineX.perform<My, Int>{
val outX = My(1111111)
outX.perform<My, Int>(
{inlineX.value}
)
}
}
inline fun My.execute(): Int {
return perform { this.value }
}
fun test2(): Int {
val inlineX = My(11)
return inlineX.execute()
}
fun box(): String {
if (test1() != 111) return "test1: ${test1()}"
if (test2() != 11) return "test2: ${test2()}"
return "OK"
}

Some files were not shown because too many files have changed in this diff Show More