diff --git a/compiler/testData/codegen/box/callableReference/function/kt21787.kt b/compiler/testData/codegen/box/callableReference/function/kt21787.kt new file mode 100644 index 00000000000..df995819f8f --- /dev/null +++ b/compiler/testData/codegen/box/callableReference/function/kt21787.kt @@ -0,0 +1,22 @@ +// WITH_RUNTIME +class Container { + var id: Int? = null +} + +class TestClass { + + private fun createContainer(id: Int): Container { val q = Container(); q.id = id; return q } + fun createContainers1(from: Int = 0, to: Int = 100) = (from .. to).map(::createContainer) + fun createContainers2(from: Int = 0, to: Int = 100): List { return (from .. to).map(::createContainer) } +} + +fun box(): String { + val testClass = TestClass() + val containers1 = testClass.createContainers1().size + if (containers1 != 101) return "fail 1: $containers1" + + val containers2 = testClass.createContainers2().size + if (containers2 != 101) return "fail 2: $containers2" + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/anonymousObject/kt15751.kt b/compiler/testData/codegen/boxInline/anonymousObject/kt15751.kt new file mode 100644 index 00000000000..aaff8f1fe30 --- /dev/null +++ b/compiler/testData/codegen/boxInline/anonymousObject/kt15751.kt @@ -0,0 +1,32 @@ +// FILE: 1.kt +// NO_CHECK_LAMBDA_INLINING +class A { + val foo = fun(call: () -> Unit) = + ext { + fun send() { + call() + } + + bar { + send() + } + } + + fun bar(body: () -> Unit) { + body() + } + + inline fun A.ext(init: X.() -> Unit) { + return X().init() + } + + class X +} + +// FILE: 2.kt + +fun box(): String { + var result = "fail" + A().foo { result = "OK" } + return result +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/callableReference/kt15751_2.kt b/compiler/testData/codegen/boxInline/callableReference/kt15751_2.kt new file mode 100644 index 00000000000..b2fac901b2b --- /dev/null +++ b/compiler/testData/codegen/boxInline/callableReference/kt15751_2.kt @@ -0,0 +1,34 @@ +// FILE: 1.kt +// IGNORE_BACKEND: JS +// WITH_RUNTIME +public inline fun T.myalso(block: (T) -> Unit): T { + block(this) + return this +} + +public inline fun Iterable.mymapNotNull(transform: (T) -> R?): List { + return mapNotNullTo(ArrayList(), transform) +} + +// FILE: 2.kt +// NO_CHECK_LAMBDA_INLINING +var result = -1; + +fun box(): String { + fff() + return if (result == 1) "OK" else "fail $result" +} + +fun fff(): Int { + val y = 0 + return 0.myalso { + fun increase(x: Int): Int = x + y + + val values = listOf(1).mymapNotNull { something(::increase, it) } + result = values[0]!! + } +} + +fun something(increase: (Int) -> Int, x: Int): Int? { + return increase(x) +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt16417.kt b/compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt16417.kt new file mode 100644 index 00000000000..085b01c653f --- /dev/null +++ b/compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt16417.kt @@ -0,0 +1,45 @@ +// IGNORE_BACKEND: JVM_IR +// FILE: 1.kt +class A { + var field = 0 + + inline fun a(f: () -> Any): Any { + try { + val value = f() + return value + } finally { + field-- + } + } + + private inline fun b(rule: () -> Unit) { + try { + rule() + } catch (fail: Throwable) {} + } + + fun c(vararg functions: () -> Any): Any = a { + for (function in functions) { + b { return function() } + } + throw RuntimeException() + } +} + +// FILE: 2.kt +// NO_CHECK_LAMBDA_INLINING +fun box(): String { + val a = A() + a.c ({ "OK" }) + if (a.field != -1) return "fail 1: ${a.field}" + + try { + a.c({ null!! }) + } catch (e: RuntimeException) { + // OK + } catch (e: Throwable) { + return "fail 2: $e" + } + + return a.c ({ "OK" }) as String +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/reified/kt15956.kt b/compiler/testData/codegen/boxInline/reified/kt15956.kt new file mode 100644 index 00000000000..69666f441ad --- /dev/null +++ b/compiler/testData/codegen/boxInline/reified/kt15956.kt @@ -0,0 +1,24 @@ +// FILE: 1.kt +// WITH_REFLECT +// IGNORE_BACKEND: JVM_IR + +package foo + +import kotlin.reflect.full.primaryConstructor + +inline fun f(): String { + var result = "" + for (p in T::class.primaryConstructor!!.parameters.sortedBy { it.index }) { + result += p.name + } + return result +} + +// FILE: 2.kt +import foo.* + +class A(val O: Int, val K: Int) + +fun box(): String { + return f() +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index bca955ac803..866ebc5c1f9 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -2085,6 +2085,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/callableReference/function/javaCollectionsStaticMethod.kt"); } + @TestMetadata("kt21787.kt") + public void testKt21787() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/function/kt21787.kt"); + } + @TestMetadata("nestedConstructorFromClass.kt") public void testNestedConstructorFromClass() throws Exception { runTest("compiler/testData/codegen/box/callableReference/function/nestedConstructorFromClass.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java index 9764d369f02..9c4df180af9 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java @@ -136,6 +136,11 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo runTest("compiler/testData/codegen/boxInline/anonymousObject/kt14011_3.kt"); } + @TestMetadata("kt15751.kt") + public void testKt15751() throws Exception { + runTest("compiler/testData/codegen/boxInline/anonymousObject/kt15751.kt"); + } + @TestMetadata("kt16193.kt") public void testKt16193() throws Exception { runTest("compiler/testData/codegen/boxInline/anonymousObject/kt16193.kt"); @@ -714,6 +719,11 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo runTest("compiler/testData/codegen/boxInline/callableReference/kt15449.kt"); } + @TestMetadata("kt15751_2.kt") + public void testKt15751_2() throws Exception { + runTest("compiler/testData/codegen/boxInline/callableReference/kt15751_2.kt"); + } + @TestMetadata("kt16411.kt") public void testKt16411() throws Exception { runTest("compiler/testData/codegen/boxInline/callableReference/kt16411.kt"); @@ -2015,6 +2025,11 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); } + @TestMetadata("kt16417.kt") + public void testKt16417() throws Exception { + runTest("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt16417.kt"); + } + @TestMetadata("kt20433.kt") public void testKt20433() throws Exception { runTest("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt20433.kt"); @@ -2548,6 +2563,11 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo runTest("compiler/testData/codegen/boxInline/reified/kt11677.kt"); } + @TestMetadata("kt15956.kt") + public void testKt15956() throws Exception { + runTest("compiler/testData/codegen/boxInline/reified/kt15956.kt"); + } + @TestMetadata("kt15997.kt") public void testKt15997() throws Exception { runTest("compiler/testData/codegen/boxInline/reified/kt15997.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java index 1fee28d3385..53681dff831 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java @@ -136,6 +136,11 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi runTest("compiler/testData/codegen/boxInline/anonymousObject/kt14011_3.kt"); } + @TestMetadata("kt15751.kt") + public void testKt15751() throws Exception { + runTest("compiler/testData/codegen/boxInline/anonymousObject/kt15751.kt"); + } + @TestMetadata("kt16193.kt") public void testKt16193() throws Exception { runTest("compiler/testData/codegen/boxInline/anonymousObject/kt16193.kt"); @@ -714,6 +719,11 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi runTest("compiler/testData/codegen/boxInline/callableReference/kt15449.kt"); } + @TestMetadata("kt15751_2.kt") + public void testKt15751_2() throws Exception { + runTest("compiler/testData/codegen/boxInline/callableReference/kt15751_2.kt"); + } + @TestMetadata("kt16411.kt") public void testKt16411() throws Exception { runTest("compiler/testData/codegen/boxInline/callableReference/kt16411.kt"); @@ -2015,6 +2025,11 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); } + @TestMetadata("kt16417.kt") + public void testKt16417() throws Exception { + runTest("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt16417.kt"); + } + @TestMetadata("kt20433.kt") public void testKt20433() throws Exception { runTest("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt20433.kt"); @@ -2548,6 +2563,11 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi runTest("compiler/testData/codegen/boxInline/reified/kt11677.kt"); } + @TestMetadata("kt15956.kt") + public void testKt15956() throws Exception { + runTest("compiler/testData/codegen/boxInline/reified/kt15956.kt"); + } + @TestMetadata("kt15997.kt") public void testKt15997() throws Exception { runTest("compiler/testData/codegen/boxInline/reified/kt15997.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index e31595c58b7..a4cf7eb5bfb 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -2085,6 +2085,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/callableReference/function/javaCollectionsStaticMethod.kt"); } + @TestMetadata("kt21787.kt") + public void testKt21787() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/function/kt21787.kt"); + } + @TestMetadata("nestedConstructorFromClass.kt") public void testNestedConstructorFromClass() throws Exception { runTest("compiler/testData/codegen/box/callableReference/function/nestedConstructorFromClass.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 9c257ac5977..42dc70b1766 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -2085,6 +2085,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/callableReference/function/javaCollectionsStaticMethod.kt"); } + @TestMetadata("kt21787.kt") + public void testKt21787() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/function/kt21787.kt"); + } + @TestMetadata("nestedConstructorFromClass.kt") public void testNestedConstructorFromClass() throws Exception { runTest("compiler/testData/codegen/box/callableReference/function/nestedConstructorFromClass.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java index 5a463ebdb58..a7fc65ec2bd 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java @@ -136,6 +136,11 @@ public class IrBlackBoxInlineCodegenTestGenerated extends AbstractIrBlackBoxInli runTest("compiler/testData/codegen/boxInline/anonymousObject/kt14011_3.kt"); } + @TestMetadata("kt15751.kt") + public void testKt15751() throws Exception { + runTest("compiler/testData/codegen/boxInline/anonymousObject/kt15751.kt"); + } + @TestMetadata("kt16193.kt") public void testKt16193() throws Exception { runTest("compiler/testData/codegen/boxInline/anonymousObject/kt16193.kt"); @@ -714,6 +719,11 @@ public class IrBlackBoxInlineCodegenTestGenerated extends AbstractIrBlackBoxInli runTest("compiler/testData/codegen/boxInline/callableReference/kt15449.kt"); } + @TestMetadata("kt15751_2.kt") + public void testKt15751_2() throws Exception { + runTest("compiler/testData/codegen/boxInline/callableReference/kt15751_2.kt"); + } + @TestMetadata("kt16411.kt") public void testKt16411() throws Exception { runTest("compiler/testData/codegen/boxInline/callableReference/kt16411.kt"); @@ -2015,6 +2025,11 @@ public class IrBlackBoxInlineCodegenTestGenerated extends AbstractIrBlackBoxInli KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM_IR, true); } + @TestMetadata("kt16417.kt") + public void testKt16417() throws Exception { + runTest("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt16417.kt"); + } + @TestMetadata("kt20433.kt") public void testKt20433() throws Exception { runTest("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt20433.kt"); @@ -2548,6 +2563,11 @@ public class IrBlackBoxInlineCodegenTestGenerated extends AbstractIrBlackBoxInli runTest("compiler/testData/codegen/boxInline/reified/kt11677.kt"); } + @TestMetadata("kt15956.kt") + public void testKt15956() throws Exception { + runTest("compiler/testData/codegen/boxInline/reified/kt15956.kt"); + } + @TestMetadata("kt15997.kt") public void testKt15997() throws Exception { runTest("compiler/testData/codegen/boxInline/reified/kt15997.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/CallableReferenceInlineTestsGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/CallableReferenceInlineTestsGenerated.java index bd43ebdb9b3..bac365a52c9 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/CallableReferenceInlineTestsGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/CallableReferenceInlineTestsGenerated.java @@ -54,6 +54,11 @@ public class CallableReferenceInlineTestsGenerated extends AbstractCallableRefer runTest("compiler/testData/codegen/boxInline/callableReference/kt15449.kt"); } + @TestMetadata("kt15751_2.kt") + public void testKt15751_2() throws Exception { + runTest("compiler/testData/codegen/boxInline/callableReference/kt15751_2.kt"); + } + @TestMetadata("kt16411.kt") public void testKt16411() throws Exception { runTest("compiler/testData/codegen/boxInline/callableReference/kt16411.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrCallableReferenceInlineTestsGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrCallableReferenceInlineTestsGenerated.java index bbdc3f9dada..34f90ed455e 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrCallableReferenceInlineTestsGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrCallableReferenceInlineTestsGenerated.java @@ -54,6 +54,11 @@ public class IrCallableReferenceInlineTestsGenerated extends AbstractIrCallableR runTest("compiler/testData/codegen/boxInline/callableReference/kt15449.kt"); } + @TestMetadata("kt15751_2.kt") + public void testKt15751_2() throws Exception { + runTest("compiler/testData/codegen/boxInline/callableReference/kt15751_2.kt"); + } + @TestMetadata("kt16411.kt") public void testKt16411() throws Exception { runTest("compiler/testData/codegen/boxInline/callableReference/kt16411.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java index c3a863e57f7..0307631cb16 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java @@ -1610,6 +1610,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/callableReference/function/innerConstructorFromTopLevelOneStringArg.kt"); } + @TestMetadata("kt21787.kt") + public void testKt21787() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/function/kt21787.kt"); + } + @TestMetadata("nestedConstructorFromClass.kt") public void testNestedConstructorFromClass() throws Exception { runTest("compiler/testData/codegen/box/callableReference/function/nestedConstructorFromClass.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrNonLocalReturnsTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrNonLocalReturnsTestGenerated.java index e7c38754ed2..26c5ec5661c 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrNonLocalReturnsTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrNonLocalReturnsTestGenerated.java @@ -129,6 +129,11 @@ public class IrNonLocalReturnsTestGenerated extends AbstractIrNonLocalReturnsTes KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS_IR, true); } + @TestMetadata("kt16417.kt") + public void testKt16417() throws Exception { + runTest("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt16417.kt"); + } + @TestMetadata("kt20433.kt") public void testKt20433() throws Exception { runTest("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt20433.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 3bbbb7649e0..0994c18c23e 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -1610,6 +1610,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/callableReference/function/innerConstructorFromTopLevelOneStringArg.kt"); } + @TestMetadata("kt21787.kt") + public void testKt21787() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/function/kt21787.kt"); + } + @TestMetadata("nestedConstructorFromClass.kt") public void testNestedConstructorFromClass() throws Exception { runTest("compiler/testData/codegen/box/callableReference/function/nestedConstructorFromClass.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/NonLocalReturnsTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/NonLocalReturnsTestGenerated.java index c4baaf7d628..9321824d1d3 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/NonLocalReturnsTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/NonLocalReturnsTestGenerated.java @@ -129,6 +129,11 @@ public class NonLocalReturnsTestGenerated extends AbstractNonLocalReturnsTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true); } + @TestMetadata("kt16417.kt") + public void testKt16417() throws Exception { + runTest("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt16417.kt"); + } + @TestMetadata("kt20433.kt") public void testKt20433() throws Exception { runTest("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt20433.kt");