Write enclosing method info for transformed objects

This commit is contained in:
Michael Bogdanov
2016-01-08 12:51:42 +03:00
parent 8ab1190082
commit 657b9ff808
20 changed files with 348 additions and 51 deletions
@@ -0,0 +1,15 @@
import test.*
fun box(): String {
val res = test {
"OK"
}
val enclosingMethod = res.javaClass.enclosingMethod
if (enclosingMethod?.name != "box") return "fail 1: ${enclosingMethod?.name}"
val enclosingClass = res.javaClass.enclosingClass
if (enclosingClass?.name != "ObjectInInlineFun_1Kt") return "fail 2: ${enclosingClass?.name}"
return "OK"
}
@@ -0,0 +1,10 @@
package test
interface Z {
fun a(): String
}
inline fun test(crossinline z: () -> String) =
object : Z {
override fun a() = z()
}
@@ -0,0 +1,23 @@
import test.*
fun box(): String {
/*This captured parameter would be added to object constructor*/
val captured = "OK";
var z: Any = "fail"
val res = test {
z = {
captured
}
(z as Function0<String>)()
}
val enclosingConstructor = z.javaClass.enclosingConstructor
if (enclosingConstructor?.name != "TransformedConstructor_1Kt\$box$\$inlined\$test$1") return "fail 1: ${enclosingConstructor?.name}"
val enclosingClass = z.javaClass.enclosingClass
if (enclosingClass?.name != "TransformedConstructor_1Kt\$box$\$inlined\$test$1") return "fail 2: ${enclosingClass?.name}"
return res.a()
}
@@ -0,0 +1,13 @@
package test
interface Z {
fun a() : String
}
inline fun test(crossinline z: () -> String) =
object : Z {
val p = z()
override fun a() = p
}
@@ -0,0 +1,28 @@
import test.*
fun box(): String {
var z = "OK"
val res = test {
z
}
val javaClass1 = res.javaClass
val enclosingMethod = javaClass1.enclosingMethod
if (enclosingMethod?.name != "box") return "fail 1: ${enclosingMethod?.name}"
val enclosingClass = javaClass1.enclosingClass
if (enclosingClass?.name != "TransformedConstructorWithAdditionalObject_1Kt") return "fail 2: ${enclosingClass?.name}"
val res2 = res.a()
val enclosingConstructor = res2.javaClass.enclosingConstructor
if (enclosingConstructor?.name != javaClass1.name) return "fail 3: ${enclosingConstructor?.name} != ${javaClass1.name}"
val enclosingClass2 = res2.javaClass.enclosingClass
if (enclosingClass2?.name != javaClass1.name) return "fail 4: ${enclosingClass2?.name} != ${javaClass1.name}"
return res2.a()
}
@@ -0,0 +1,18 @@
package test
interface Z<T> {
fun a() : T
}
inline fun test(crossinline z: () -> String) =
object : Z<Z<String>> {
val p: Z<String> = object : Z<String> {
val p2 = z()
override fun a() = p2
}
override fun a() = p
}
@@ -0,0 +1,26 @@
import test.*
fun box(): String {
/*This captured parameter would be added to object constructor*/
val captured = "OK";
var z: Any = "fail"
val res = test {
call {
z = {
captured
}
}
(z as Function0<String>)()
}
val enclosingConstructor = z.javaClass.enclosingConstructor
if (enclosingConstructor?.name != "TransformedConstructorWithNestedInline_1Kt\$box$\$inlined\$test$1") return "fail 1: ${enclosingConstructor?.name}"
val enclosingClass = z.javaClass.enclosingClass
if (enclosingClass?.name != "TransformedConstructorWithNestedInline_1Kt\$box$\$inlined\$test$1") return "fail 2: ${enclosingClass?.name}"
return res.a()
}
@@ -0,0 +1,16 @@
package test
interface Z {
fun a() : String
}
inline fun test(crossinline z: () -> String) =
object : Z {
val p = z()
override fun a() = p
}
inline fun<T> call(crossinline z: () -> T) = z()
@@ -0,0 +1,21 @@
// NO_CHECK_LAMBDA_INLINING
// FULL_JDK
import test.*
import java.util.*
fun box(): String {
val result = Test().callInline("test")
val method = result.javaClass.getMethod("invoke")
val genericReturnType = method.genericReturnType
if (genericReturnType.toString() != "T") return "fail 1: $genericReturnType"
val method2 = Test::class.java.getMethod("callInline", Any::class.java)
val genericParameterType = method2.genericParameterTypes.firstOrNull()
if (genericParameterType != genericReturnType) return "fail 2: $genericParameterType != $genericReturnType"
return "OK"
}
@@ -0,0 +1,12 @@
package test
open class Test {
inline fun <Y> test(z: () -> () -> Y) = z()
fun <T> callInline(p: T) = test<T> {
{
p
}
}
}