FIR: Add tests for invoke

This commit is contained in:
Simon Ogorodnik
2019-03-05 20:34:29 +03:00
parent c58c1a6c4e
commit 3be1d0f946
9 changed files with 167 additions and 0 deletions
@@ -0,0 +1,13 @@
fun x() {
}
class Foo {
val x: Foo = Foo()
operator fun invoke(): Foo { return this }
fun bar() = x() // Should resolve to invoke
}
@@ -0,0 +1,18 @@
FILE: explicitReceiver.kt
public final function x(): R|kotlin/Unit| {
}
public final class Foo {
public constructor(): super<R|kotlin/Any|>()
public final property x(val): R|Foo| = <Unresolved name: Foo>#()
public get(): R|Foo|
public final operator function invoke(): R|Foo| {
return@@@invoke this#
}
public final function bar(): R|Foo| {
return@@@bar R|/Foo.x|.R|/Foo.invoke|()
}
}
@@ -0,0 +1,19 @@
class Bar {
operator fun invoke(): Foo { return this }
}
fun x() {
}
class Foo {
operator fun Bar.invoke(): Foo { return this }
val x: Bar = Bar()
fun bar() = x() // Should resolve to invoke
}
@@ -0,0 +1,26 @@
FILE: explicitReceiver2.kt
public final class Bar {
public constructor(): super<R|kotlin/Any|>()
public final operator function invoke(): R|Foo| {
return@@@invoke this#
}
}
public final function x(): R|kotlin/Unit| {
}
public final class Foo {
public constructor(): super<R|kotlin/Any|>()
public final operator function invoke R|Bar|.(): R|Foo| {
return@@@invoke this#
}
public final property x(val): R|Bar| = <Unresolved name: Bar>#()
public get(): R|Bar|
public final function bar(): R|Foo| {
return@@@bar R|/Foo.x|.R|/Bar.invoke|()
}
}
@@ -0,0 +1,11 @@
fun x() {}
class Foo {
operator fun Int.invoke(): Foo = this@Foo
val x = 0
fun foo() = x()
}
@@ -0,0 +1,18 @@
FILE: extension.kt
public final function x(): R|kotlin/Unit| {
}
public final class Foo {
public constructor(): super<R|kotlin/Any|>()
public final operator function invoke R|kotlin/Int|.(): R|Foo| {
return@@@invoke this@Foo
}
public final property x(val): R|kotlin/Int| = Int(0)
public get(): <implicit>
public final function foo(): R|Foo| {
return@@@foo R|/Foo.x|.R|/Foo.invoke|()
}
}
@@ -0,0 +1,12 @@
fun x() {}
operator fun Int.invoke(): Foo = this@Foo
class Foo {
val x = 0
fun foo() = x()
}
@@ -0,0 +1,17 @@
FILE: farInvokeExtension.kt
public final function x(): R|kotlin/Unit| {
}
public final operator function invoke R|kotlin/Int|.(): R|Foo| {
return@@@invoke this@Foo
}
public final class Foo {
public constructor(): super<R|kotlin/Any|>()
public final property x(val): R|kotlin/Int| = Int(0)
public get(): <implicit>
public final function foo(): R|kotlin/Unit| {
return@@@foo R|/x|()
}
}
@@ -168,6 +168,39 @@ public class FirResolveTestCaseGenerated extends AbstractFirResolveTestCase {
public void testWhen() throws Exception {
runTest("compiler/fir/resolve/testData/resolve/expresssions/when.kt");
}
@TestMetadata("compiler/fir/resolve/testData/resolve/expresssions/invoke")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Invoke extends AbstractFirResolveTestCase {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath);
}
public void testAllFilesPresentInInvoke() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/fir/resolve/testData/resolve/expresssions/invoke"), Pattern.compile("^([^.]+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("explicitReceiver.kt")
public void testExplicitReceiver() throws Exception {
runTest("compiler/fir/resolve/testData/resolve/expresssions/invoke/explicitReceiver.kt");
}
@TestMetadata("explicitReceiver2.kt")
public void testExplicitReceiver2() throws Exception {
runTest("compiler/fir/resolve/testData/resolve/expresssions/invoke/explicitReceiver2.kt");
}
@TestMetadata("extension.kt")
public void testExtension() throws Exception {
runTest("compiler/fir/resolve/testData/resolve/expresssions/invoke/extension.kt");
}
@TestMetadata("farInvokeExtension.kt")
public void testFarInvokeExtension() throws Exception {
runTest("compiler/fir/resolve/testData/resolve/expresssions/invoke/farInvokeExtension.kt");
}
}
}
@TestMetadata("compiler/fir/resolve/testData/resolve/fromBuilder")