JS: move inline test to box tests
This commit is contained in:
@@ -0,0 +1 @@
|
||||
@native public fun parseInt(s: String, radix: Int = 10): Int = noImpl
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copy of JVM-backend test
|
||||
* Found at: compiler/testData/codegen/boxInline/anonymousObject/anonymousObjectOnCallSite.1.kt
|
||||
*/
|
||||
|
||||
// FILE: foo.kt
|
||||
package foo
|
||||
|
||||
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"
|
||||
}
|
||||
|
||||
|
||||
// FILE: test.kt
|
||||
package test
|
||||
|
||||
abstract class A<R> {
|
||||
abstract fun getO() : R
|
||||
|
||||
abstract fun getK() : R
|
||||
}
|
||||
|
||||
|
||||
inline fun <R> doWork(job: ()-> R) : R {
|
||||
return job()
|
||||
}
|
||||
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copy of JVM-backend test
|
||||
* Found at: compiler/testData/codegen/boxInline/anonymousObject/anonymousObjectOnCallSiteSuperParams.1.kt
|
||||
*/
|
||||
|
||||
// FILE: foo.kt
|
||||
package foo
|
||||
|
||||
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"
|
||||
}
|
||||
|
||||
|
||||
// FILE: test.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()
|
||||
}
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copy of JVM-backend test
|
||||
* Found at: compiler/testData/codegen/boxInline/anonymousObject/anonymousObjectOnDeclarationSite.1.kt
|
||||
*/
|
||||
|
||||
// FILE: foo.kt
|
||||
package foo
|
||||
|
||||
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"
|
||||
}
|
||||
|
||||
|
||||
// FILE: test.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;
|
||||
}
|
||||
Vendored
+77
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copy of JVM-backend test
|
||||
* Found at: compiler/testData/codegen/boxInline/anonymousObject/anonymousObjectOnDeclarationSiteSuperParams.1.kt
|
||||
*/
|
||||
|
||||
// FILE: foo.kt
|
||||
package foo
|
||||
|
||||
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"
|
||||
}
|
||||
|
||||
|
||||
// FILE: test.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;
|
||||
}
|
||||
@@ -0,0 +1,291 @@
|
||||
/*
|
||||
* Copy of JVM-backend test
|
||||
* Found at: compiler/testData/codegen/boxInline/builders/builders.1.kt
|
||||
*/
|
||||
|
||||
|
||||
// FILE: foo.kt
|
||||
package foo
|
||||
|
||||
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"
|
||||
}
|
||||
|
||||
|
||||
// FILE: bar.kt
|
||||
package foo
|
||||
|
||||
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
|
||||
}
|
||||
@@ -0,0 +1,295 @@
|
||||
/*
|
||||
* Copy of JVM-backend test
|
||||
* Found at: compiler/testData/codegen/boxInline/builders/buildersAndLambdaCapturing.1.kt
|
||||
*/
|
||||
|
||||
// FILE: foo.kt
|
||||
package foo
|
||||
|
||||
|
||||
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"
|
||||
}
|
||||
|
||||
|
||||
// FILE: bar.kt
|
||||
package foo
|
||||
|
||||
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
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copy of JVM-backend test
|
||||
* Found at: compiler/testData/codegen/boxInline/capture/captureInlinable.1.kt
|
||||
*/
|
||||
|
||||
// FILE: foo.kt
|
||||
package foo
|
||||
|
||||
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"
|
||||
}
|
||||
|
||||
|
||||
// FILE: test.kt
|
||||
package test
|
||||
|
||||
|
||||
inline fun <R> doWork(crossinline job: ()-> R) : R {
|
||||
return notInline({job()})
|
||||
}
|
||||
|
||||
fun <R> notInline(job: ()-> R) : R {
|
||||
return job()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copy of JVM-backend test
|
||||
* Found at: compiler/testData/codegen/boxInline/capture/captureInlinableAndOther.1.kt
|
||||
*/
|
||||
|
||||
// FILE: foo.kt
|
||||
package foo
|
||||
|
||||
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"
|
||||
}
|
||||
|
||||
|
||||
// FILE: test.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()
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copy of JVM-backend test
|
||||
* Found at: compiler/testData/codegen/boxInline/capture/captureThisAndReceiver.1.kt
|
||||
*/
|
||||
|
||||
// FILE: foo.kt
|
||||
package foo
|
||||
|
||||
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"
|
||||
}
|
||||
|
||||
|
||||
// FILE: bar.kt
|
||||
package foo
|
||||
|
||||
class My(val value: Int)
|
||||
|
||||
inline fun <T, R> T.perform(job: (T)-> R) : R {
|
||||
return job(this)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copy of JVM-backend test
|
||||
* Found at: compiler/testData/codegen/boxInline/complex/closureChain.1.kt
|
||||
*/
|
||||
|
||||
// FILE: foo.kt
|
||||
package foo
|
||||
|
||||
fun test1(): Int {
|
||||
val inlineX = Inline()
|
||||
return inlineX.foo({ z: Int -> "" + z}, 25, { -> this.length })
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (test1() != 2) return "test1: ${test1()}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
|
||||
// FILE: bar.kt
|
||||
package foo
|
||||
|
||||
class Inline() {
|
||||
|
||||
inline fun foo(closure1 : (l: Int) -> String, param: Int, closure2: String.() -> Int) : Int {
|
||||
return closure1(param).closure2()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copy of JVM-backend test
|
||||
* Found at: compiler/testData/codegen/boxInline/defaultValues/defaultMethod.1.kt
|
||||
*/
|
||||
|
||||
// FILE: foo.kt
|
||||
package foo
|
||||
|
||||
import test.*
|
||||
|
||||
fun simple(): String {
|
||||
val k = "K"
|
||||
return simpleFun(lambda = {it + "O"}) + simpleFun("K", {k + it})
|
||||
}
|
||||
|
||||
fun simpleR(): String {
|
||||
val k = "K"
|
||||
return simpleFunR({it + "O"}) + simpleFunR({k + it}, "K")
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
|
||||
var result = simple()
|
||||
if (result != "OOKK") return "fail1: ${result}"
|
||||
|
||||
result = simpleR()
|
||||
if (result != "OOKK") return "fail2: ${result}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
|
||||
// FILE: test.kt
|
||||
package test
|
||||
|
||||
inline fun <T> simpleFun(arg: String = "O", lambda: (String) -> T): T {
|
||||
return lambda(arg)
|
||||
}
|
||||
|
||||
inline fun <T> simpleFunR(lambda: (String) -> T, arg: String = "O"): T {
|
||||
return lambda(arg)
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copy of JVM-backend test
|
||||
* Found at: compiler/testData/codegen/boxInline/capture/generics.1.kt
|
||||
*/
|
||||
|
||||
// FILE: foo.kt
|
||||
package foo
|
||||
|
||||
import test.*
|
||||
|
||||
fun test1(s: Int): String {
|
||||
var result = "OK"
|
||||
result = mfun(s) { a ->
|
||||
result + doSmth(s) + doSmth(a)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val result = test1(11)
|
||||
if (result != "OK1111") return "fail1: ${result}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
|
||||
// FILE: test.kt
|
||||
package test
|
||||
|
||||
inline fun <T, R> mfun(arg: T, f: (T) -> R) : R {
|
||||
return f(arg)
|
||||
}
|
||||
|
||||
inline fun <T> doSmth(a: T): String {
|
||||
return a.toString()
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copy of JVM-backend test
|
||||
* Found at: compiler/testData/codegen/boxInline/defaultValues/inlineInDefaultParameter.1.kt
|
||||
*/
|
||||
|
||||
// FILE: foo.kt
|
||||
package foo
|
||||
|
||||
import test.*
|
||||
|
||||
fun testCompilation(arg: String = getStringInline()): String {
|
||||
return arg
|
||||
}
|
||||
|
||||
inline fun testCompilationInline(arg: String = getStringInline()): String {
|
||||
return arg
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = testCompilation()
|
||||
if (result != "OK") return "fail1: ${result}"
|
||||
|
||||
result = testCompilation("OKOK")
|
||||
if (result != "OKOK") return "fail2: ${result}"
|
||||
|
||||
|
||||
result = testCompilationInline()
|
||||
if (result != "OK") return "fail3: ${result}"
|
||||
|
||||
result = testCompilationInline("OKOK")
|
||||
if (result != "OKOK") return "fail4: ${result}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
|
||||
// FILE: test.kt
|
||||
package test
|
||||
|
||||
inline fun getStringInline(): String {
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// FILE: a.kt
|
||||
package foo
|
||||
|
||||
inline fun sum(a: Int, b: Int): Int {
|
||||
return a + b
|
||||
}
|
||||
|
||||
|
||||
// FILE: b.kt
|
||||
package foo
|
||||
|
||||
// CHECK_NOT_CALLED: sum
|
||||
|
||||
fun box(): String {
|
||||
val sum3 = sum(1, 2)
|
||||
assertEquals(3, sum3)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copy of JVM-backend test
|
||||
* Found at: compiler/testData/codegen/boxInline/lambdaTransformation/lambdaCloning.1.kt
|
||||
*/
|
||||
|
||||
// FILE: foo.kt
|
||||
package foo
|
||||
|
||||
import test.*
|
||||
|
||||
fun test1(s: Long): String {
|
||||
return doSmth(s)
|
||||
}
|
||||
|
||||
fun test2(s: Int): String {
|
||||
return doSmth2(s)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = test1(11)
|
||||
if (result != "11") return "fail1: ${result}"
|
||||
|
||||
result = test2(11)
|
||||
if (result != "11") return "fail2: ${result}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
|
||||
// FILE: test.kt
|
||||
package test
|
||||
|
||||
inline fun <T> doSmth(a: T) : String {
|
||||
return {a.toString()}()
|
||||
}
|
||||
|
||||
inline fun <T> doSmth2(a: T) : String {
|
||||
return {{a.toString()}()}()
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copy of JVM-backend test
|
||||
* Found at: compiler/testData/codegen/boxInline/lambdaTransformation/lambdaInLambda2.1.kt
|
||||
*/
|
||||
|
||||
// FILE: foo.kt
|
||||
package foo
|
||||
|
||||
import test.*
|
||||
|
||||
fun test1(prefix: String): String {
|
||||
var result = "fail"
|
||||
mfun {
|
||||
concat("start") {
|
||||
if (it.startsWith(prefix)) {
|
||||
result = "OK"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (test1("start") != "OK") return "fail1"
|
||||
if (test1("nostart") != "fail") return "fail2"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
|
||||
// FILE: test.kt
|
||||
package test
|
||||
|
||||
inline fun <R> mfun(f: () -> R) {
|
||||
f()
|
||||
}
|
||||
|
||||
fun concat(suffix: String, l: (s: String) -> Unit) {
|
||||
l(suffix)
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copy of JVM-backend test
|
||||
* Found at: compiler/testData/codegen/boxInline/lambdaTransformation/lambdaInLambdaNoInline.1.kt
|
||||
*/
|
||||
|
||||
// FILE: foo.kt
|
||||
package foo
|
||||
|
||||
import test.*
|
||||
|
||||
fun test1(param: String): String {
|
||||
var result = "fail1"
|
||||
noInlineFun(param) { a ->
|
||||
concat("start") {
|
||||
result = doSmth(a).toString()
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
fun test11(param: String): String {
|
||||
var result = "fail1"
|
||||
noInlineFun("stub") { a ->
|
||||
concat("start") {
|
||||
result = doSmth(param).toString()
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
inline fun test2(crossinline param: () -> String): String {
|
||||
var result = "fail1"
|
||||
noInlineFun("stub") { a ->
|
||||
concat(param()) {
|
||||
result = doSmth(param()).toString()
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
inline fun test22(crossinline param: () -> String): String {
|
||||
var result = "fail1"
|
||||
{{result = param()}()}()
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
if (test1("start") != "start") return "fail1: ${test1("start")}"
|
||||
if (test1("nostart") != "nostart") return "fail2: ${test1("nostart")}"
|
||||
if (test11("start") != "start") return "fail3: ${test11("start")}"
|
||||
|
||||
if (test2({"start"}) != "start") return "fail4: ${test2({"start"})}"
|
||||
if (test22({"start"}) != "start") return "fail5: ${test22({"start"})}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
|
||||
// FILE: test.kt
|
||||
package test
|
||||
|
||||
fun concat(suffix: String, l: (s: String) -> Unit) {
|
||||
l(suffix)
|
||||
}
|
||||
|
||||
fun <T> noInlineFun(arg: T, f: (T) -> Unit) {
|
||||
f(arg)
|
||||
}
|
||||
|
||||
inline fun doSmth(a: String): String {
|
||||
return a.toString()
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copy of JVM-backend test
|
||||
* Found at: compiler/testData/codegen/boxInline/lambdaTransformation/regeneratedLambdaName.1.kt
|
||||
*/
|
||||
|
||||
// FILE: foo.kt
|
||||
package foo
|
||||
|
||||
import test.*
|
||||
|
||||
fun sameName(s: Long): Long {
|
||||
return call {
|
||||
s
|
||||
}
|
||||
}
|
||||
|
||||
fun sameName(s: Int): Int {
|
||||
return call {
|
||||
s
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val result = sameName(1)
|
||||
if (result != 1) return "fail1: ${result}"
|
||||
|
||||
val result2 = sameName(2)
|
||||
if (result2 != 2) return "fail2: ${result2}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
|
||||
// FILE: test.kt
|
||||
package test
|
||||
|
||||
|
||||
inline fun <R> call(crossinline f: () -> R) : R {
|
||||
return {f()} ()
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copy of JVM-backend test
|
||||
* Found at: compiler/testData/codegen/boxInline/lambdaTransformation/sameCaptured.1.kt
|
||||
*/
|
||||
|
||||
// FILE: foo.kt
|
||||
package foo
|
||||
|
||||
import test.*
|
||||
|
||||
fun testSameCaptured() : String {
|
||||
var result = 0;
|
||||
result = doWork({result+=1; result}, {result += 11; result})
|
||||
return if (result == 12) "OK" else "fail ${result}"
|
||||
}
|
||||
|
||||
inline fun testSameCaptured(crossinline lambdaWithResultCaptured: () -> Unit) : String {
|
||||
var result = 1;
|
||||
result = doWork({result+=11; lambdaWithResultCaptured(); result})
|
||||
return if (result == 12) "OK" else "fail ${result}"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (testSameCaptured() != "OK") return "test1 : ${testSameCaptured()}"
|
||||
|
||||
var result = 0;
|
||||
if (testSameCaptured{result += 1111} != "OK") return "test2 : ${testSameCaptured{result = 1111}}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
|
||||
// FILE: test.kt
|
||||
package test
|
||||
|
||||
|
||||
inline fun <R> doWork(crossinline job: ()-> R) : R {
|
||||
val k = 10;
|
||||
return notInline({k; job()})
|
||||
}
|
||||
|
||||
inline fun <R> doWork(crossinline job: ()-> R, crossinline job2: () -> R) : R {
|
||||
val k = 10;
|
||||
return notInline({k; job(); job2()})
|
||||
}
|
||||
|
||||
fun <R> notInline(job: ()-> R) : R {
|
||||
return job()
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copy of JVM-backend test
|
||||
* Found at: compiler/testData/codegen/boxInline/capture/simpleCapturingInClass.1.kt
|
||||
*/
|
||||
|
||||
// FILE: a.kt
|
||||
package foo
|
||||
|
||||
fun testAll(): String {
|
||||
val inlineX = InlineAll()
|
||||
|
||||
return inlineX.inline({ a1: Int, a2: Double, a3: Double, a4: String, a5: Long ->
|
||||
"" + a1 + a2 + a3 + a4 + a5},
|
||||
1, 12.5, 13.5, "14", 15)
|
||||
}
|
||||
|
||||
fun testAllWithCapturedVal(): String {
|
||||
val inlineX = InlineAll()
|
||||
|
||||
val c1 = 21
|
||||
val c2 = 22.5
|
||||
val c3 = 23.5
|
||||
val c4 = "24"
|
||||
val c5 = 25
|
||||
val c6 = 'H'
|
||||
val c7 = 26
|
||||
val c8 = 27
|
||||
val c9 = 28.5
|
||||
|
||||
return inlineX.inline({ a1: Int, a2: Double, a3: Double, a4: String, a5: Long ->
|
||||
"" + a1 + a2 + a3 + a4 + a5 + c1 + c2 + c3 + c4 + c5 + c6 + c7 + c8 + c9},
|
||||
1, 12.5, 13.5, "14", 15)
|
||||
}
|
||||
|
||||
fun testAllWithCapturedVar(): String {
|
||||
val inlineX = InlineAll()
|
||||
|
||||
var c1 = 21
|
||||
var c2 = 22.5
|
||||
var c3 = 23.5
|
||||
var c4 = "24"
|
||||
var c5 = 25
|
||||
var c6 = 'H'
|
||||
var c7 = 26
|
||||
var c8 = 27
|
||||
val c9 = 28.5
|
||||
|
||||
return inlineX.inline({ a1: Int, a2: Double, a3: Double, a4: String, a5: Long ->
|
||||
"" + a1 + a2 + a3 + a4 + a5 + c1 + c2 + c3 + c4 + c5 + c6 + c7 + c8 + c9},
|
||||
1, 12.5, 13.5, "14", 15)
|
||||
}
|
||||
|
||||
fun testAllWithCapturedValAndVar(): String {
|
||||
val inlineX = InlineAll()
|
||||
|
||||
var c1 = 21
|
||||
var c2 = 22.5
|
||||
val c3 = 23.5
|
||||
val c4 = "24"
|
||||
var c5 = 25
|
||||
val c6 = 'H'
|
||||
var c7 = 26
|
||||
var c8 = 27
|
||||
val c9 = 28.5
|
||||
|
||||
return inlineX.inline({ a1: Int, a2: Double, a3: Double, a4: String, a5: Long ->
|
||||
"" + a1 + a2 + a3 + a4 + a5 + c1 + c2 + c3 + c4 + c5 + c6 + c7 + c8 + c9},
|
||||
1, 12.5, 13.5, "14", 15)
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
if (testAll() != "112.513.51415") return "testAll: ${testAll()}"
|
||||
if (testAllWithCapturedVal() != "112.513.514152122.523.52425H262728.5") return "testAllWithCapturedVal: ${testAllWithCapturedVal()}"
|
||||
if (testAllWithCapturedVar() != "112.513.514152122.523.52425H262728.5") return "testAllWithCapturedVar: ${testAllWithCapturedVar()}"
|
||||
if (testAllWithCapturedValAndVar() != "112.513.514152122.523.52425H262728.5") return "testAllWithCapturedVal: ${testAllWithCapturedValAndVar()}"
|
||||
return "OK"
|
||||
}
|
||||
|
||||
|
||||
// FILE: b.kt
|
||||
package foo
|
||||
|
||||
class InlineAll {
|
||||
|
||||
inline fun inline(s: (Int, Double, Double, String, Long) -> String,
|
||||
a1: Int, a2: Double, a3: Double, a4: String, a5: Long): String {
|
||||
return s(a1, a2, a3, a4, a5)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copy of JVM-backend test
|
||||
* Found at: compiler/testData/codegen/boxInline/capture/simpleCapturingInPackage.1.kt
|
||||
*/
|
||||
|
||||
// FILE: a.kt
|
||||
package foo
|
||||
|
||||
fun testAll(): String {
|
||||
return inline({ a1: Int, a2: Double, a3: Double, a4: String, a5: Long ->
|
||||
"" + a1 + a2 + a3 + a4 + a5},
|
||||
1, 12.5, 13.5, "14", 15)
|
||||
}
|
||||
|
||||
fun testAllWithCapturedVal(): String {
|
||||
val c1 = 21
|
||||
val c2 = 22.5
|
||||
val c3 = 23.5
|
||||
val c4 = "24"
|
||||
val c5 = 25
|
||||
val c6 = 'H'
|
||||
val c7 = 26
|
||||
val c8 = 27
|
||||
val c9 = 28.5
|
||||
|
||||
return inline({ a1: Int, a2: Double, a3: Double, a4: String, a5: Long ->
|
||||
"" + a1 + a2 + a3 + a4 + a5 + c1 + c2 + c3 + c4 + c5 + c6 + c7 + c8 + c9},
|
||||
1, 12.5, 13.5, "14", 15)
|
||||
}
|
||||
|
||||
fun testAllWithCapturedVar(): String {
|
||||
var c1 = 21
|
||||
var c2 = 22.5
|
||||
var c3 = 23.5
|
||||
var c4 = "24"
|
||||
var c5 = 25
|
||||
var c6 = 'H'
|
||||
var c7 = 26
|
||||
var c8 = 27
|
||||
val c9 = 28.5
|
||||
|
||||
return inline({ a1: Int, a2: Double, a3: Double, a4: String, a5: Long ->
|
||||
"" + a1 + a2 + a3 + a4 + a5 + c1 + c2 + c3 + c4 + c5 + c6 + c7 + c8 + c9},
|
||||
1, 12.5, 13.5, "14", 15)
|
||||
}
|
||||
|
||||
fun testAllWithCapturedValAndVar(): String {
|
||||
var c1 = 21
|
||||
var c2 = 22.5
|
||||
val c3 = 23.5
|
||||
val c4 = "24"
|
||||
var c5 = 25
|
||||
val c6 = 'H'
|
||||
var c7 = 26
|
||||
var c8 = 27
|
||||
val c9 = 28.5
|
||||
|
||||
return inline({ a1: Int, a2: Double, a3: Double, a4: String, a5: Long ->
|
||||
"" + a1 + a2 + a3 + a4 + a5 + c1 + c2 + c3 + c4 + c5 + c6 + c7 + c8 + c9},
|
||||
1, 12.5, 13.5, "14", 15)
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
if (testAll() != "112.513.51415") return "testAll: ${testAll()}"
|
||||
if (testAllWithCapturedVal() != "112.513.514152122.523.52425H262728.5") return "testAllWithCapturedVal: ${testAllWithCapturedVal()}"
|
||||
if (testAllWithCapturedVar() != "112.513.514152122.523.52425H262728.5") return "testAllWithCapturedVar: ${testAllWithCapturedVar()}"
|
||||
if (testAllWithCapturedValAndVar() != "112.513.514152122.523.52425H262728.5") return "testAllWithCapturedVal: ${testAllWithCapturedValAndVar()}"
|
||||
return "OK"
|
||||
}
|
||||
|
||||
|
||||
// FILE: b.kt
|
||||
package foo
|
||||
|
||||
inline fun inline(s: (Int, Double, Double, String, Long) -> String,
|
||||
a1: Int, a2: Double, a3: Double, a4: String, a5: Long): String {
|
||||
return s(a1, a2, a3, a4, a5)
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copy of JVM-backend test
|
||||
* Found at: compiler/testData/codegen/boxInline/defaultValues/simpleDefaultMethod.1.kt
|
||||
*/
|
||||
|
||||
// FILE: foo.kt
|
||||
package foo
|
||||
|
||||
import test.*
|
||||
|
||||
fun testCompilation(): String {
|
||||
emptyFun()
|
||||
emptyFun("K")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
fun simple(): String {
|
||||
return simpleFun() + simpleFun("K")
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = testCompilation()
|
||||
if (result != "OK") return "fail1: ${result}"
|
||||
|
||||
result = simple()
|
||||
if (result != "OK") return "fail2: ${result}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
|
||||
// FILE: test.kt
|
||||
package test
|
||||
|
||||
inline fun emptyFun(arg: String = "O") {
|
||||
|
||||
}
|
||||
|
||||
inline fun simpleFun(arg: String = "O"): String {
|
||||
val r = arg;
|
||||
return r;
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copy of JVM-backend test
|
||||
* Found at: compiler/testData/codegen/boxInline/trait/trait.1.kt
|
||||
*/
|
||||
|
||||
// FILE: foo.kt
|
||||
package foo
|
||||
|
||||
import test.*
|
||||
|
||||
// CHECK_CONTAINS_NO_CALLS: testClassObject
|
||||
|
||||
internal fun testFinalInline(): String {
|
||||
return Z().finalInline({"final"})
|
||||
}
|
||||
|
||||
internal fun testFinalInline2(instance: InlineTrait): String {
|
||||
return instance.finalInline({"final2"})
|
||||
}
|
||||
|
||||
internal fun testClassObject(): String {
|
||||
return InlineTrait.finalInline({"classobject"})
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (testFinalInline() != "final") return "test1: ${testFinalInline()}"
|
||||
if (testFinalInline2(Z()) != "final2") return "test2: ${testFinalInline2(Z())}"
|
||||
if (testClassObject() != "classobject") return "test3: ${testClassObject()}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
|
||||
// FILE: test.kt
|
||||
package test
|
||||
|
||||
internal interface InlineTrait {
|
||||
|
||||
public fun finalInline(s: () -> String): String {
|
||||
return s()
|
||||
}
|
||||
|
||||
companion object {
|
||||
public inline final fun finalInline(s: () -> String): String {
|
||||
return s()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Z: InlineTrait {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copy of JVM-backend test
|
||||
* Found at: compiler/testData/codegen/boxInline/tryCatchFinally/tryCatch.1.kt
|
||||
*/
|
||||
|
||||
// FILE: a.kt
|
||||
package foo
|
||||
|
||||
fun test1() : Int {
|
||||
val inlineX = My(111)
|
||||
var result = 0
|
||||
val res = inlineX.perform<My, Int>{
|
||||
|
||||
try {
|
||||
throw RuntimeException()
|
||||
} catch (e: RuntimeException) {
|
||||
result = -1
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
fun test11() : Int {
|
||||
val inlineX = My(111)
|
||||
val res = inlineX.perform<My, Int>{
|
||||
try {
|
||||
throw RuntimeException()
|
||||
} catch (e: RuntimeException) {
|
||||
-1
|
||||
}
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
fun test2() : Int {
|
||||
try {
|
||||
val inlineX = My(111)
|
||||
var result = 0
|
||||
val res = inlineX.perform<My, Int>{
|
||||
try {
|
||||
throw RuntimeExceptionWithValue("-1")
|
||||
} catch (e: RuntimeException) {
|
||||
throw RuntimeExceptionWithValue("-2")
|
||||
}
|
||||
}
|
||||
return result
|
||||
} catch (e: RuntimeExceptionWithValue) {
|
||||
return e.value.toInt2()!!
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (test1() != -1) return "test1: ${test1()}"
|
||||
if (test11() != -1) return "test11: ${test11()}"
|
||||
if (test2() != -2) return "test2: ${test2()}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
// FILE: b.kt
|
||||
package foo
|
||||
|
||||
class My(val value: Int)
|
||||
|
||||
inline fun <T, R> T.perform(job: (T)-> R) : R {
|
||||
return job(this)
|
||||
}
|
||||
|
||||
inline fun String.toInt2() : Int = parseInt(this)
|
||||
|
||||
class RuntimeExceptionWithValue(val value: String) : RuntimeException()
|
||||
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
* Copy of JVM-backend test
|
||||
* Found at: compiler/testData/codegen/boxInline/tryCatchFinally/tryCatch2.1.kt
|
||||
*/
|
||||
|
||||
// FILE: a.kt
|
||||
package foo
|
||||
|
||||
fun test1(): Int {
|
||||
val res = My(111).performWithFail<My, Int>(
|
||||
{
|
||||
throw RuntimeExceptionWithValue()
|
||||
}, {
|
||||
it.value
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
||||
fun test11(): Int {
|
||||
val res = My(111).performWithFail2<My, Int>(
|
||||
{
|
||||
try {
|
||||
throw RuntimeExceptionWithValue("1")
|
||||
} catch (e: RuntimeExceptionWithValue) {
|
||||
throw RuntimeExceptionWithValue("2")
|
||||
}
|
||||
},
|
||||
{ ex, thizz ->
|
||||
if (ex.value == "2") {
|
||||
thizz.value
|
||||
} else {
|
||||
-11111
|
||||
}
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
||||
fun test2(): Int {
|
||||
val res = My(111).performWithFail<My, Int>(
|
||||
{
|
||||
it.value
|
||||
},
|
||||
{
|
||||
it.value + 1
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
||||
fun test22(): Int {
|
||||
val res = My(111).performWithFail2<My, Int>(
|
||||
{
|
||||
try {
|
||||
throw RuntimeExceptionWithValue("1")
|
||||
} catch (e: RuntimeExceptionWithValue) {
|
||||
it.value
|
||||
111
|
||||
}
|
||||
},
|
||||
{ ex, thizz ->
|
||||
-11111
|
||||
})
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
|
||||
fun test3(): Int {
|
||||
try {
|
||||
val res = My(111).performWithFail<My, Int>(
|
||||
{
|
||||
throw RuntimeExceptionWithValue("-1")
|
||||
}, {
|
||||
throw RuntimeExceptionWithValue("-2")
|
||||
})
|
||||
return res
|
||||
} catch (e: RuntimeExceptionWithValue) {
|
||||
return e.value.toInt2()!!
|
||||
}
|
||||
}
|
||||
|
||||
fun test33(): Int {
|
||||
try {
|
||||
val res = My(111).performWithFail2<My, Int>(
|
||||
{
|
||||
try {
|
||||
throw RuntimeExceptionWithValue("-1")
|
||||
} catch (e: RuntimeExceptionWithValue) {
|
||||
throw RuntimeExceptionWithValue("-2")
|
||||
}
|
||||
},
|
||||
{ ex, thizz ->
|
||||
if (ex.value == "-2") {
|
||||
throw RuntimeExceptionWithValue("-3")
|
||||
} else {
|
||||
-11111
|
||||
}
|
||||
})
|
||||
return res
|
||||
} catch (e: RuntimeExceptionWithValue) {
|
||||
return e.value.toInt2()!!
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (test1() != 111) return "test1: ${test1()}"
|
||||
if (test11() != 111) return "test11: ${test11()}"
|
||||
|
||||
if (test2() != 111) return "test2: ${test2()}"
|
||||
if (test22() != 111) return "test22: ${test22()}"
|
||||
|
||||
if (test3() != -2) return "test3: ${test3()}"
|
||||
if (test33() != -3) return "test33: ${test33()}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
|
||||
// FILE: b.kt
|
||||
package foo
|
||||
|
||||
class My(val value: Int)
|
||||
|
||||
inline fun <T, R> T.performWithFail(job: (T)-> R, failJob: (T) -> R): R {
|
||||
try {
|
||||
return job(this)
|
||||
} catch (e: RuntimeExceptionWithValue) {
|
||||
return failJob(this)
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <T, R> T.performWithFail2(job: (T)-> R, failJob: (e: RuntimeExceptionWithValue, T) -> R): R {
|
||||
try {
|
||||
return job(this)
|
||||
} catch (e: RuntimeExceptionWithValue) {
|
||||
return failJob(e, this)
|
||||
}
|
||||
}
|
||||
|
||||
@native object Number {
|
||||
fun parseInt(str: String): Int = noImpl
|
||||
}
|
||||
|
||||
inline fun String.toInt2(): Int = parseInt(this)
|
||||
|
||||
class RuntimeExceptionWithValue(val value: String = "") : RuntimeException()
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Copy of JVM-backend test
|
||||
* Found at: compiler/testData/codegen/boxInline/tryCatchFinally/tryCatchFinally.1.kt
|
||||
*/
|
||||
|
||||
// FILE: a.kt
|
||||
package foo
|
||||
|
||||
fun test1(): Int {
|
||||
|
||||
var res = My(111).performWithFinally<My, Int>(
|
||||
{
|
||||
1
|
||||
}, {
|
||||
it.value
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
||||
fun test11(): Int {
|
||||
var result = -1;
|
||||
val res = My(111).performWithFinally<My, Int>(
|
||||
{
|
||||
try {
|
||||
result = it.value
|
||||
throw RuntimeException("1")
|
||||
} catch (e: RuntimeException) {
|
||||
++result
|
||||
throw RuntimeException("2")
|
||||
}
|
||||
},
|
||||
{
|
||||
++result
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
||||
fun test2(): Int {
|
||||
var res = My(111).performWithFinally<My, Int>(
|
||||
{
|
||||
throw RuntimeException("1")
|
||||
},
|
||||
{
|
||||
it.value
|
||||
})
|
||||
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
fun test3(): Int {
|
||||
try {
|
||||
var result = -1;
|
||||
val res = My(111).performWithFailFinally<My, Int>(
|
||||
{
|
||||
result = it.value;
|
||||
throw RuntimeException("-1")
|
||||
},
|
||||
{ e, z ->
|
||||
++result
|
||||
throw RuntimeException("-2")
|
||||
},
|
||||
{
|
||||
++result
|
||||
})
|
||||
return res
|
||||
} catch (e: RuntimeException) {
|
||||
return e.message?.toInt2()!!
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (test1() != 111) return "test1: ${test1()}"
|
||||
if (test11() != 113) return "test11: ${test11()}"
|
||||
|
||||
if (test2() != 111) return "test2: ${test2()}"
|
||||
|
||||
if (test3() != 113) return "test3: ${test3()}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
|
||||
// FILE: b.kt
|
||||
package foo
|
||||
|
||||
class My(val value: Int)
|
||||
|
||||
inline fun <T, R> T.performWithFinally(job: (T)-> R, finallyFun: (T) -> R) : R {
|
||||
try {
|
||||
job(this)
|
||||
} finally {
|
||||
return finallyFun(this)
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <T, R> T.performWithFailFinally(job: (T)-> R, failJob : (e: RuntimeException, T) -> R, finallyFun: (T) -> R) : R {
|
||||
try {
|
||||
job(this)
|
||||
} catch (e: RuntimeException) {
|
||||
failJob(e, this)
|
||||
} finally {
|
||||
return finallyFun(this)
|
||||
}
|
||||
}
|
||||
|
||||
inline fun String.toInt2() : Int = parseInt(this)
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copy of JVM-backend test
|
||||
* Found at: compiler/testData/codegen/boxInline/complex/use.1.kt
|
||||
*/
|
||||
|
||||
// FILE: foo.kt
|
||||
package foo
|
||||
|
||||
import test.*
|
||||
|
||||
fun Data.test1(d: Data) : Int {
|
||||
val input2 = Input(this)
|
||||
val input = Input(this)
|
||||
return input.use<Input, Int>{
|
||||
val output = Output(d)
|
||||
output.use<Output,Int>{
|
||||
input.copyTo(output, 10)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
|
||||
val result = Data().test1(Data())
|
||||
if (result != 100) return "test1: ${result}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
|
||||
// FILE: test.kt
|
||||
package test
|
||||
|
||||
public class Data()
|
||||
|
||||
public data class Input(val d: Data) : Closeable {
|
||||
public fun data() : Int = 100
|
||||
}
|
||||
|
||||
public class Output(val d: Data) : Closeable {
|
||||
public fun doOutput(data: Int): Int = data
|
||||
}
|
||||
|
||||
public interface Closeable {
|
||||
open public fun close() {}
|
||||
}
|
||||
|
||||
public fun Input.copyTo(output: Output, size: Int): Int {
|
||||
return output.doOutput(this.data())
|
||||
}
|
||||
|
||||
public inline fun <T: Closeable, R> T.use(block: (T)-> R) : R {
|
||||
var closed = false
|
||||
try {
|
||||
return block(this)
|
||||
} catch (e: Exception) {
|
||||
closed = true
|
||||
try {
|
||||
this.close()
|
||||
} catch (closeException: Exception) {
|
||||
|
||||
}
|
||||
throw e
|
||||
} finally {
|
||||
if (!closed) {
|
||||
this.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copy of JVM-backend test
|
||||
* Found at: compiler/testData/codegen/boxInline/complex/with.1.kt
|
||||
*/
|
||||
|
||||
// FILE: foo.kt
|
||||
package foo
|
||||
|
||||
import test.*
|
||||
|
||||
fun Data.test1(d: Data) : Int {
|
||||
val input = Input(this)
|
||||
var result = 10
|
||||
with(input) {
|
||||
result = use<Int>{
|
||||
val output = Output(d)
|
||||
use<Int>{
|
||||
data()
|
||||
copyTo(output, 10)
|
||||
}
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
fun Data.test2(d: Data) : Int {
|
||||
val input = Input(this)
|
||||
var result = 10
|
||||
with2(input) {
|
||||
result = use<Int>{
|
||||
val output = Output(d)
|
||||
useNoInline<Int>{
|
||||
data()
|
||||
copyTo(output, 10)
|
||||
}
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
|
||||
val result = Data().test1(Data())
|
||||
if (result != 100) return "test1: ${result}"
|
||||
|
||||
val result2 = Data().test2(Data())
|
||||
if (result2 != 100) return "test2: ${result2}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
|
||||
// FILE: test.kt
|
||||
package test
|
||||
|
||||
|
||||
public class Data()
|
||||
|
||||
public class Input(val d: Data) : Closeable {
|
||||
public fun data() : Int = 100
|
||||
}
|
||||
public class Output(val d: Data) : Closeable {
|
||||
public fun doOutput(data: Int): Int = data
|
||||
}
|
||||
|
||||
public interface Closeable {
|
||||
open public fun close() {}
|
||||
}
|
||||
|
||||
public inline fun <R> use(block: ()-> R) : R {
|
||||
return block()
|
||||
}
|
||||
|
||||
public fun <R> useNoInline(block: ()-> R) : R {
|
||||
return block()
|
||||
}
|
||||
|
||||
|
||||
public fun Input.copyTo(output: Output, size: Int): Int {
|
||||
return output.doOutput(this.data())
|
||||
}
|
||||
|
||||
public inline fun <T> with2(receiver : T, crossinline body : T.() -> Unit) : Unit = {receiver.body()}()
|
||||
Reference in New Issue
Block a user