From 0c8b231fde75fa984a277f9ba02ab4a8914236b0 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Wed, 23 Aug 2017 17:21:10 +0300 Subject: [PATCH] Add tests on coercion to Unit for callable references #KT-11723 --- .../callableReference/bound/coercionToUnit.kt | 20 +++++++++++++++++++ .../function/coercionToUnit.kt | 16 +++++++++++++++ .../bothWithCoercionToUnit.kt | 17 ++++++++++++++++ .../ir/IrBlackBoxCodegenTestGenerated.java | 15 ++++++++++++++ .../codegen/BlackBoxCodegenTestGenerated.java | 15 ++++++++++++++ .../LightAnalysisModeTestGenerated.java | 15 ++++++++++++++ .../IrJsCodegenBoxTestGenerated.java | 15 ++++++++++++++ .../semantics/JsCodegenBoxTestGenerated.java | 15 ++++++++++++++ 8 files changed, 128 insertions(+) create mode 100644 compiler/testData/codegen/box/callableReference/bound/coercionToUnit.kt create mode 100644 compiler/testData/codegen/box/callableReference/function/coercionToUnit.kt create mode 100644 compiler/testData/codegen/box/callableReference/varargAndDefaults/bothWithCoercionToUnit.kt diff --git a/compiler/testData/codegen/box/callableReference/bound/coercionToUnit.kt b/compiler/testData/codegen/box/callableReference/bound/coercionToUnit.kt new file mode 100644 index 00000000000..6a2a214776f --- /dev/null +++ b/compiler/testData/codegen/box/callableReference/bound/coercionToUnit.kt @@ -0,0 +1,20 @@ +// !LANGUAGE: +NewInference +// IGNORE_BACKEND: JS_IR, JVM_IR +// WITH_RUNTIME + +class Foo + +class Builder { + var size: Int = 0 + + fun addFoo(foo: Foo): Builder { + size++ + return this + } +} + +fun box(): String { + val b = Builder() + listOf(Foo(), Foo(), Foo()).forEach(b::addFoo) + return if (b.size == 3) "OK" else "Fail" +} diff --git a/compiler/testData/codegen/box/callableReference/function/coercionToUnit.kt b/compiler/testData/codegen/box/callableReference/function/coercionToUnit.kt new file mode 100644 index 00000000000..d85344da9be --- /dev/null +++ b/compiler/testData/codegen/box/callableReference/function/coercionToUnit.kt @@ -0,0 +1,16 @@ +// !LANGUAGE: +NewInference +// IGNORE_BACKEND: JVM_IR + +fun foo(s: String): Boolean { + if (s != "kotlin") throw AssertionError(s) + return true +} + +fun bar(f: (String) -> Unit) { + f("kotlin") +} + +fun box(): String { + bar(::foo) + return "OK" +} diff --git a/compiler/testData/codegen/box/callableReference/varargAndDefaults/bothWithCoercionToUnit.kt b/compiler/testData/codegen/box/callableReference/varargAndDefaults/bothWithCoercionToUnit.kt new file mode 100644 index 00000000000..6566782f901 --- /dev/null +++ b/compiler/testData/codegen/box/callableReference/varargAndDefaults/bothWithCoercionToUnit.kt @@ -0,0 +1,17 @@ +// !LANGUAGE: +NewInference +// IGNORE_BACKEND: JS, JS_IR, JVM_IR + +fun foo(s: String = "kotlin", vararg t: String): Boolean { + if (s != "kotlin") throw AssertionError(s) + if (t.size != 0) throw AssertionError(t.size.toString()) + return true +} + +fun bar(f: () -> Unit) { + f() +} + +fun box(): String { + bar(::foo) + return "OK" +} diff --git a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index a68bd55ebea..6f91c82c548 100644 --- a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -1647,6 +1647,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/callableReference/bound/boundJvmFieldInInterfaceCompanion.kt"); } + @TestMetadata("coercionToUnit.kt") + public void testCoercionToUnit() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/bound/coercionToUnit.kt"); + } + @TestMetadata("companionObjectReceiver.kt") public void testCompanionObjectReceiver() throws Exception { runTest("compiler/testData/codegen/box/callableReference/bound/companionObjectReceiver.kt"); @@ -1841,6 +1846,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/callableReference/function/classMemberFromTopLevelUnitOneStringArg.kt"); } + @TestMetadata("coercionToUnit.kt") + public void testCoercionToUnit() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/function/coercionToUnit.kt"); + } + @TestMetadata("constructorFromTopLevelNoArgs.kt") public void testConstructorFromTopLevelNoArgs() throws Exception { runTest("compiler/testData/codegen/box/callableReference/function/constructorFromTopLevelNoArgs.kt"); @@ -2348,6 +2358,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/callableReference/varargAndDefaults"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM_IR, true); } + @TestMetadata("bothWithCoercionToUnit.kt") + public void testBothWithCoercionToUnit() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/varargAndDefaults/bothWithCoercionToUnit.kt"); + } + @TestMetadata("boundReferences.kt") public void testBoundReferences() throws Exception { runTest("compiler/testData/codegen/box/callableReference/varargAndDefaults/boundReferences.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index cd677a37b9f..03300fe942b 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -1647,6 +1647,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/callableReference/bound/boundJvmFieldInInterfaceCompanion.kt"); } + @TestMetadata("coercionToUnit.kt") + public void testCoercionToUnit() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/bound/coercionToUnit.kt"); + } + @TestMetadata("companionObjectReceiver.kt") public void testCompanionObjectReceiver() throws Exception { runTest("compiler/testData/codegen/box/callableReference/bound/companionObjectReceiver.kt"); @@ -1841,6 +1846,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/callableReference/function/classMemberFromTopLevelUnitOneStringArg.kt"); } + @TestMetadata("coercionToUnit.kt") + public void testCoercionToUnit() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/function/coercionToUnit.kt"); + } + @TestMetadata("constructorFromTopLevelNoArgs.kt") public void testConstructorFromTopLevelNoArgs() throws Exception { runTest("compiler/testData/codegen/box/callableReference/function/constructorFromTopLevelNoArgs.kt"); @@ -2348,6 +2358,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/callableReference/varargAndDefaults"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); } + @TestMetadata("bothWithCoercionToUnit.kt") + public void testBothWithCoercionToUnit() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/varargAndDefaults/bothWithCoercionToUnit.kt"); + } + @TestMetadata("boundReferences.kt") public void testBoundReferences() throws Exception { runTest("compiler/testData/codegen/box/callableReference/varargAndDefaults/boundReferences.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index dd9961b7220..613f65718cd 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -1647,6 +1647,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/callableReference/bound/boundJvmFieldInInterfaceCompanion.kt"); } + @TestMetadata("coercionToUnit.kt") + public void testCoercionToUnit() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/bound/coercionToUnit.kt"); + } + @TestMetadata("companionObjectReceiver.kt") public void testCompanionObjectReceiver() throws Exception { runTest("compiler/testData/codegen/box/callableReference/bound/companionObjectReceiver.kt"); @@ -1841,6 +1846,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/callableReference/function/classMemberFromTopLevelUnitOneStringArg.kt"); } + @TestMetadata("coercionToUnit.kt") + public void testCoercionToUnit() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/function/coercionToUnit.kt"); + } + @TestMetadata("constructorFromTopLevelNoArgs.kt") public void testConstructorFromTopLevelNoArgs() throws Exception { runTest("compiler/testData/codegen/box/callableReference/function/constructorFromTopLevelNoArgs.kt"); @@ -2348,6 +2358,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/callableReference/varargAndDefaults"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); } + @TestMetadata("bothWithCoercionToUnit.kt") + public void testBothWithCoercionToUnit() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/varargAndDefaults/bothWithCoercionToUnit.kt"); + } + @TestMetadata("boundReferences.kt") public void testBoundReferences() throws Exception { runTest("compiler/testData/codegen/box/callableReference/varargAndDefaults/boundReferences.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 3227620e3ef..89a8563ed59 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 @@ -1567,6 +1567,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/callableReference/bound/array.kt"); } + @TestMetadata("coercionToUnit.kt") + public void testCoercionToUnit() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/bound/coercionToUnit.kt"); + } + @TestMetadata("companionObjectReceiver.kt") public void testCompanionObjectReceiver() throws Exception { runTest("compiler/testData/codegen/box/callableReference/bound/companionObjectReceiver.kt"); @@ -1751,6 +1756,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/callableReference/function/classMemberFromTopLevelUnitOneStringArg.kt"); } + @TestMetadata("coercionToUnit.kt") + public void testCoercionToUnit() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/function/coercionToUnit.kt"); + } + @TestMetadata("constructorFromTopLevelNoArgs.kt") public void testConstructorFromTopLevelNoArgs() throws Exception { runTest("compiler/testData/codegen/box/callableReference/function/constructorFromTopLevelNoArgs.kt"); @@ -2258,6 +2268,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/callableReference/varargAndDefaults"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS_IR, true); } + @TestMetadata("bothWithCoercionToUnit.kt") + public void testBothWithCoercionToUnit() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/varargAndDefaults/bothWithCoercionToUnit.kt"); + } + @TestMetadata("boundReferences.kt") public void testBoundReferences() throws Exception { runTest("compiler/testData/codegen/box/callableReference/varargAndDefaults/boundReferences.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 5a1c1f29bd3..2b1b2257e12 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 @@ -1587,6 +1587,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/callableReference/bound/array.kt"); } + @TestMetadata("coercionToUnit.kt") + public void testCoercionToUnit() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/bound/coercionToUnit.kt"); + } + @TestMetadata("companionObjectReceiver.kt") public void testCompanionObjectReceiver() throws Exception { runTest("compiler/testData/codegen/box/callableReference/bound/companionObjectReceiver.kt"); @@ -1771,6 +1776,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/callableReference/function/classMemberFromTopLevelUnitOneStringArg.kt"); } + @TestMetadata("coercionToUnit.kt") + public void testCoercionToUnit() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/function/coercionToUnit.kt"); + } + @TestMetadata("constructorFromTopLevelNoArgs.kt") public void testConstructorFromTopLevelNoArgs() throws Exception { runTest("compiler/testData/codegen/box/callableReference/function/constructorFromTopLevelNoArgs.kt"); @@ -2278,6 +2288,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/callableReference/varargAndDefaults"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true); } + @TestMetadata("bothWithCoercionToUnit.kt") + public void testBothWithCoercionToUnit() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/varargAndDefaults/bothWithCoercionToUnit.kt"); + } + @TestMetadata("boundReferences.kt") public void testBoundReferences() throws Exception { runTest("compiler/testData/codegen/box/callableReference/varargAndDefaults/boundReferences.kt");