Keep inline transformation invariant: all captured parameters stored in topmost lambda/object

Fix for KT-8668: java.lang.ClassFormatError: Duplicate field name&signature (based on property access)

  #KT-8668 Fixed
This commit is contained in:
Michael Bogdanov
2015-11-18 11:56:33 +03:00
parent 93eb09a654
commit d4369c1df9
53 changed files with 1056 additions and 18 deletions
@@ -0,0 +1,7 @@
import test.*
fun box(): String {
var result = "fail"
test { it -> result = it }
return result
}
@@ -0,0 +1,18 @@
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) }()}
}
@@ -0,0 +1,19 @@
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,5 @@
package test
inline fun <T> inlineFun(arg: T, f: (T) -> Unit) {
f(arg)
}
@@ -0,0 +1,15 @@
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,7 @@
package test
inline fun <T> inlineFun(arg: T, crossinline f: (T) -> Unit) {
{
f(arg)
}()
}
@@ -0,0 +1,19 @@
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,7 @@
package test
inline fun <T> inlineFun(arg: T, crossinline f: (T) -> Unit) {
{
f(arg)
}()
}
@@ -0,0 +1,17 @@
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,7 @@
package test
inline fun <T> inlineFun(arg: T, crossinline f: (T) -> Unit) {
{
f(arg)
}()
}
@@ -0,0 +1,7 @@
import test.*
fun box(): String {
var result = "fail"
test { it -> result = it }
return result
}
@@ -0,0 +1,18 @@
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) }()}
}
@@ -0,0 +1,7 @@
import test.*
fun box(): String {
var result = "fail"
B("O", "K").test { it -> result = it }
return result
}
@@ -0,0 +1,22 @@
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) }() }
}
}
@@ -0,0 +1,6 @@
//NO_CHECK_LAMBDA_INLINING
import test.*
fun box(): String {
return A().box()
}
@@ -0,0 +1,30 @@
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"
}
}
@@ -0,0 +1,6 @@
//NO_CHECK_LAMBDA_INLINING
import test.*
fun box(): String {
return A().box()
}
@@ -0,0 +1,28 @@
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"
}
}
@@ -0,0 +1,6 @@
//NO_CHECK_LAMBDA_INLINING
import test.*
fun box(): String {
return A().box()
}
@@ -0,0 +1,24 @@
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"
}
}
@@ -0,0 +1,6 @@
//NO_CHECK_LAMBDA_INLINING
import test.*
fun box(): String {
return A().box()
}
@@ -0,0 +1,26 @@
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"
}
}
@@ -0,0 +1,6 @@
//NO_CHECK_LAMBDA_INLINING
import test.*
fun box(): String {
return A().box()
}
@@ -0,0 +1,29 @@
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"
}
}
@@ -0,0 +1,6 @@
//NO_CHECK_LAMBDA_INLINING
import test.*
fun box(): String {
return A().box()
}
@@ -0,0 +1,29 @@
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"
}
}
@@ -0,0 +1,7 @@
import test.*
fun box(): String {
var result = "fail"
B("O", "fail").test { it -> result = it }
return result
}
@@ -0,0 +1,21 @@
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") }() }
}
}
@@ -0,0 +1,8 @@
//NO_CHECK_LAMBDA_INLINING
import test.*
fun box(): String {
var result = "fail"
B("O", "K").test { it -> result = it }
return result
}
@@ -0,0 +1,22 @@
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) }() }
}
}
@@ -0,0 +1,7 @@
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,22 @@
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) }
}
}
@@ -0,0 +1,7 @@
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,31 @@
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()
}
}
@@ -0,0 +1,7 @@
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,32 @@
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()
}
}
@@ -0,0 +1,6 @@
//NO_CHECK_LAMBDA_INLINING
import test.*
fun box(): String {
return A().testCall()
}
@@ -0,0 +1,20 @@
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()
}()
}
}
@@ -0,0 +1,6 @@
//NO_CHECK_LAMBDA_INLINING
import test.*
fun box(): String {
return Person("OK").sayName()
}
@@ -0,0 +1,15 @@
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()
}
@@ -0,0 +1,9 @@
//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,14 @@
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()
}
@@ -0,0 +1,6 @@
//NO_CHECK_LAMBDA_INLINING
import test.*
fun box(): String {
return Company("OK").sayName()
}
@@ -0,0 +1,17 @@
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()
}
@@ -0,0 +1,6 @@
//NO_CHECK_LAMBDA_INLINING
import test.*
fun box(): String {
return Person("OK").sayName()
}
@@ -0,0 +1,14 @@
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()