From 4adacfa5a219bde7c74dc1bd536e33f325624448 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Tue, 29 Oct 2019 11:17:22 +0300 Subject: [PATCH] Add a pair of new tests for FIR local classes / objects --- .../resolve/expresssions/localScopes.kt | 28 ++++++++++ .../resolve/expresssions/localScopes.txt | 51 +++++++++++++++++++ .../resolve/stdlib/anonymousInDelegate.kt | 10 ++++ .../fir/FirResolveTestCaseGenerated.java | 5 ++ ...FirResolveTestCaseWithStdlibGenerated.java | 5 ++ 5 files changed, 99 insertions(+) create mode 100644 compiler/fir/resolve/testData/resolve/expresssions/localScopes.kt create mode 100644 compiler/fir/resolve/testData/resolve/expresssions/localScopes.txt create mode 100644 compiler/fir/resolve/testData/resolve/stdlib/anonymousInDelegate.kt diff --git a/compiler/fir/resolve/testData/resolve/expresssions/localScopes.kt b/compiler/fir/resolve/testData/resolve/expresssions/localScopes.kt new file mode 100644 index 00000000000..568c3628cc5 --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/expresssions/localScopes.kt @@ -0,0 +1,28 @@ +open class Bar { + fun foo() {} +} + +fun test() { + open class BaseLocal : Bar() { + fun baz() {} + } + + val base = BaseLocal() + base.baz() + base.foo() + + val anonymous = object : Bar() { + fun baz() {} + } + anonymous.baz() + anonymous.foo() + + class DerivedLocal : BaseLocal() { + fun gau() {} + } + + val derived = DerivedLocal() + derived.gau() + derived.baz() + derived.foo() +} \ No newline at end of file diff --git a/compiler/fir/resolve/testData/resolve/expresssions/localScopes.txt b/compiler/fir/resolve/testData/resolve/expresssions/localScopes.txt new file mode 100644 index 00000000000..368ed9ada9c --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/expresssions/localScopes.txt @@ -0,0 +1,51 @@ +FILE: localScopes.kt + public open class Bar : R|kotlin/Any| { + public constructor(): R|Bar| { + super() + } + + public final fun foo(): R|kotlin/Unit| { + } + + } + public final fun test(): R|kotlin/Unit| { + local open class BaseLocal : R|Bar| { + public constructor(): R|BaseLocal| { + super() + } + + public final fun baz(): R|kotlin/Unit| { + } + + } + + lval base: R|BaseLocal| = R|/BaseLocal.BaseLocal|() + R|/base|.R|/BaseLocal.baz|() + R|/base|.R|/Bar.foo|() + lval anonymous: R|anonymous| = object : R|Bar| { + private constructor(): R|Bar| { + super() + } + + public final fun baz(): R|kotlin/Unit| { + } + + } + + R|/anonymous|.R|/baz|() + R|/anonymous|.R|/Bar.foo|() + local final class DerivedLocal : R|class error: Symbol not found, for `BaseLocal`| { + public constructor(): R|DerivedLocal| { + super() + } + + public final fun gau(): R|kotlin/Unit| { + } + + } + + lval derived: R|DerivedLocal| = R|/DerivedLocal.DerivedLocal|() + R|/derived|.R|/DerivedLocal.gau|() + R|/derived|.#() + R|/derived|.#() + } diff --git a/compiler/fir/resolve/testData/resolve/stdlib/anonymousInDelegate.kt b/compiler/fir/resolve/testData/resolve/stdlib/anonymousInDelegate.kt new file mode 100644 index 00000000000..9386294e290 --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/stdlib/anonymousInDelegate.kt @@ -0,0 +1,10 @@ +interface Foo { + fun bar(): Int +} + +val x by lazy { + val foo = object : Foo { + override fun bar(): Int = 42 + } + foo.bar() +} \ No newline at end of file diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirResolveTestCaseGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirResolveTestCaseGenerated.java index 21376452f7d..d2990c3b600 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirResolveTestCaseGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirResolveTestCaseGenerated.java @@ -341,6 +341,11 @@ public class FirResolveTestCaseGenerated extends AbstractFirResolveTestCase { runTest("compiler/fir/resolve/testData/resolve/expresssions/localImplicitBodies.kt"); } + @TestMetadata("localScopes.kt") + public void testLocalScopes() throws Exception { + runTest("compiler/fir/resolve/testData/resolve/expresssions/localScopes.kt"); + } + @TestMetadata("memberExtension.kt") public void testMemberExtension() throws Exception { runTest("compiler/fir/resolve/testData/resolve/expresssions/memberExtension.kt"); diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirResolveTestCaseWithStdlibGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirResolveTestCaseWithStdlibGenerated.java index 21564201ced..c0dc0516c04 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirResolveTestCaseWithStdlibGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirResolveTestCaseWithStdlibGenerated.java @@ -28,6 +28,11 @@ public class FirResolveTestCaseWithStdlibGenerated extends AbstractFirResolveTes KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/fir/resolve/testData/resolve/stdlib"), Pattern.compile("^([^.]+)\\.kt$"), true, "contracts"); } + @TestMetadata("anonymousInDelegate.kt") + public void testAnonymousInDelegate() throws Exception { + runTest("compiler/fir/resolve/testData/resolve/stdlib/anonymousInDelegate.kt"); + } + @TestMetadata("arrayFirstOrNull.kt") public void testArrayFirstOrNull() throws Exception { runTest("compiler/fir/resolve/testData/resolve/stdlib/arrayFirstOrNull.kt");