Add tests on coercion to Unit for callable references

#KT-11723
This commit is contained in:
Alexander Udalov
2017-08-23 17:21:10 +03:00
parent 9babd90999
commit 0c8b231fde
8 changed files with 128 additions and 0 deletions
@@ -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"
}
@@ -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"
}
@@ -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"
}
@@ -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");
@@ -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");
@@ -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");
@@ -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");
@@ -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");