From 401023a89301f80580fa732ae98efeaa05dc093a Mon Sep 17 00:00:00 2001 From: "anastasiia.spaseeva" Date: Fri, 28 Feb 2020 12:47:05 +0300 Subject: [PATCH] [FIR] Add test for object inner class KT-37120 --- .../testData/resolve/objectInnerClass.kt | 149 ++++++++++++ .../testData/resolve/objectInnerClass.txt | 213 ++++++++++++++++++ .../fir/FirDiagnosticsTestGenerated.java | 5 + ...DiagnosticsWithLightTreeTestGenerated.java | 5 + 4 files changed, 372 insertions(+) create mode 100644 compiler/fir/resolve/testData/resolve/objectInnerClass.kt create mode 100644 compiler/fir/resolve/testData/resolve/objectInnerClass.txt diff --git a/compiler/fir/resolve/testData/resolve/objectInnerClass.kt b/compiler/fir/resolve/testData/resolve/objectInnerClass.kt new file mode 100644 index 00000000000..197f0bc559d --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/objectInnerClass.kt @@ -0,0 +1,149 @@ +// !CHECK_TYPE +/* + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-37120 + */ + +val case1 = object : A { + inner class Child(property: B) : Base(property) { + fun Base.zoo() { + val x = property //UNRESOLVED_REFERENCE + } + + fun foo() { + baseFun() //UNRESOLVED_REFERENCE + val x = property //UNRESOLVED_REFERENCE + zoo() //UNRESOLVED_REFERENCE + hoo() + } + } + fun Child.voo() { + val x = property //UNRESOLVED_REFERENCE + } + + fun Base.hoo() { + val x = property //UNRESOLVED_REFERENCE + } + + open inner class Base(/*protected*/ val property: B) { + fun baseFun() {} + } + + fun caseForBase() { + val base = Base(B()) + /*member of Base*/ + base.baseFun() //UNRESOLVED_REFERENCE + base.property //UNRESOLVED_REFERENCE + /*extensions*/ + base.hoo() + } + + fun caseForChild() { + val child = Child(B()) + /*member of Base*/ + child.baseFun() //UNRESOLVED_REFERENCE + child.property //UNRESOLVED_REFERENCE + /*member of Child*/ + child.foo() //UNRESOLVED_REFERENCE + /*extensions*/ + child.hoo() + child.voo() + } +} + + +class Case2() { + val x = object : Base(B()) { + fun Base.zoo() { + val x = property + + } + + fun foo() { + baseFun() + val x = property + zoo() + hoo() + } + } + + + fun Base.hoo() { + val x = property + } + + open inner class Base(/*protected*/ val property: B) { + fun baseFun() {} + } + + fun caseForBase() { + val base = Base(B()) + /*member of Base*/ + base.baseFun() + base.property + /*extensions*/ + base.hoo() + } + + fun caseForChild() { + val child = x + /*member of Base*/ + child.baseFun() + child.property + /*extensions*/ + child.hoo() + } +} + + +class Case3() { + val x = object : A { + inner class Child(property: B) : Base(property) { + fun Base.zoo() { + val x = property //UNRESOLVED_REFERENCE + } + + fun foo() { + baseFun() //UNRESOLVED_REFERENCE + val x = property //UNRESOLVED_REFERENCE + zoo() + hoo() + } + } + + fun Child.voo() { + val x = property //UNRESOLVED_REFERENCE + } + fun Base.hoo() { + val x = property //UNRESOLVED_REFERENCE + } + + open inner class Base(/*protected*/ val property: B) { + fun baseFun() {} + } + + fun caseForBase() { + val base = Base(B()) + /*member of Base*/ + base.baseFun() //UNRESOLVED_REFERENCE + base.property //UNRESOLVED_REFERENCE + /*extensions*/ + base.hoo() + } + + fun caseForChild() { + val child = Child(B()) + /*member of Base*/ + child.baseFun() //UNRESOLVED_REFERENCE + child.property //UNRESOLVED_REFERENCE + /*member of Child*/ + child.foo() //UNRESOLVED_REFERENCE + /*extensions*/ + child.hoo() + child.voo() + } + } +} + +interface A {} +class B() {} \ No newline at end of file diff --git a/compiler/fir/resolve/testData/resolve/objectInnerClass.txt b/compiler/fir/resolve/testData/resolve/objectInnerClass.txt new file mode 100644 index 00000000000..87f73fb8070 --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/objectInnerClass.txt @@ -0,0 +1,213 @@ +FILE: objectInnerClass.kt + public final val case1: R|anonymous| = object : R|A| { + private constructor(): R|kotlin/Any| { + super() + } + + local final inner class Child : R|ERROR CLASS: Symbol not found, for `Base`| { + public constructor(property: R|B|): R|.Child| { + super(R|/property|) + } + + public final fun R|ERROR CLASS: Symbol not found, for `Base`|.zoo(): R|kotlin/Unit| { + lval x: = # + } + + public final fun foo(): R|kotlin/Unit| { + #() + lval x: = # + #() + (this@R|/anonymous|, this@R|/.Child|).R|/anonymous.hoo|() + } + + } + + public final fun R|ERROR CLASS: Symbol not found, for `Child`|.voo(): R|kotlin/Unit| { + lval x: = # + } + + public final fun R|ERROR CLASS: Symbol not found, for `Base`|.hoo(): R|kotlin/Unit| { + lval x: = # + } + + local open inner class Base : R|kotlin/Any| { + public constructor(property: R|B|): R|.Base| { + super() + } + + public final val property: R|B| = R|/property| + public get(): R|B| + + public final fun baseFun(): R|kotlin/Unit| { + } + + } + + public final fun caseForBase(): R|kotlin/Unit| { + lval base: R|.Base| = this@R|/anonymous|.R|/.Base.Base|(R|/B.B|()) + R|/base|.#() + R|/base|.# + (this@R|/anonymous|, R|/base|).R|/anonymous.hoo|() + } + + public final fun caseForChild(): R|kotlin/Unit| { + lval child: R|.Child| = this@R|/anonymous|.R|/.Child.Child|(R|/B.B|()) + R|/child|.#() + R|/child|.# + R|/child|.#() + (this@R|/anonymous|, R|/child|).R|/anonymous.hoo|() + (this@R|/anonymous|, R|/child|).R|/anonymous.voo|() + } + + } + + public get(): R|anonymous| + public final class Case2 : R|kotlin/Any| { + public constructor(): R|Case2| { + super() + } + + public final val x: R|anonymous| = object : R|Case2.Base| { + private constructor(): R|Case2.Base| { + super(R|/B.B|()) + } + + public final fun R|Case2.Base|.zoo(): R|kotlin/Unit| { + lval x: R|B| = this@R|/anonymous.zoo|.R|/Case2.Base.property| + } + + public final fun foo(): R|kotlin/Unit| { + this@R|/anonymous|.R|/Case2.Base.baseFun|() + lval x: R|B| = this@R|/anonymous|.R|/Case2.Base.property| + this@R|/anonymous|.R|/anonymous.zoo|() + (this@R|/Case2|, this@R|/anonymous|).R|/Case2.hoo|() + } + + } + + public get(): R|anonymous| + + public final fun R|Case2.Base|.hoo(): R|kotlin/Unit| { + lval x: R|B| = this@R|/Case2.hoo|.R|/Case2.Base.property| + } + + public open inner class Base : R|kotlin/Any| { + public constructor(property: R|B|): R|Case2.Base| { + super() + } + + public final val property: R|B| = R|/property| + public get(): R|B| + + public final fun baseFun(): R|kotlin/Unit| { + } + + } + + public final fun caseForBase(): R|kotlin/Unit| { + lval base: R|Case2.Base| = this@R|/Case2|.R|/Case2.Base.Base|(R|/B.B|()) + R|/base|.R|/Case2.Base.baseFun|() + R|/base|.R|/Case2.Base.property| + (this@R|/Case2|, R|/base|).R|/Case2.hoo|() + } + + public final fun caseForChild(): R|kotlin/Unit| { + lval child: R|anonymous| = this@R|/Case2|.R|/Case2.x| + R|/child|.R|/Case2.Base.baseFun|() + R|/child|.R|/Case2.Base.property| + (this@R|/Case2|, R|/child|).R|/Case2.hoo|() + } + + } + public final class Case3 : R|kotlin/Any| { + public constructor(): R|Case3| { + super() + } + + public final val x: R|anonymous| = object : R|A| { + private constructor(): R|kotlin/Any| { + super() + } + + local final inner class Child : R|ERROR CLASS: Symbol not found, for `Base`| { + public constructor(property: R|B|): R|Case3..Child| { + super(R|/property|) + } + + public final fun R|ERROR CLASS: Symbol not found, for `Base`|.zoo(): R|kotlin/Unit| { + lval x: = # + } + + public final fun foo(): R|kotlin/Unit| { + #() + lval x: = # + this@R|/Case3..Child|.R|/Case3..Child.zoo|() + (this@R|/anonymous|, this@R|/Case3..Child|).R|/anonymous.hoo|() + } + + } + + public final fun R|ERROR CLASS: Symbol not found, for `Child`|.voo(): R|kotlin/Unit| { + lval x: = # + } + + public final fun R|ERROR CLASS: Symbol not found, for `Base`|.hoo(): R|kotlin/Unit| { + lval x: = # + } + + local open inner class Base : R|kotlin/Any| { + public constructor(property: R|B|): R|Case3..Base| { + super() + } + + public final val property: R|B| = R|/property| + public get(): R|B| + + public final fun baseFun(): R|kotlin/Unit| { + } + + } + + public final fun caseForBase(): R|kotlin/Unit| { + lval base: R|Case3..Base| = R|/Case3..Base.Base|(R|/B.B|()) + R|/base|.#() + R|/base|.# + R|/base|.R|/anonymous.hoo|() + } + + public final fun caseForChild(): R|kotlin/Unit| { + lval child: R|Case3..Child| = R|/Case3..Child.Child|(R|/B.B|()) + R|/child|.#() + R|/child|.# + R|/child|.#() + R|/child|.R|/anonymous.hoo|() + R|/child|.R|/anonymous.voo|() + } + + } + + public get(): R|anonymous| + + } + public abstract interface A : R|kotlin/Any| { + } + public final class B : R|kotlin/Any| { + public constructor(): R|B| { + super() + } + + } +FILE: CHECK_TYPE.kt + public final fun checkSubtype(t: R|T|): R|T| { + ^checkSubtype R|/t| + } + public final class Inv : R|kotlin/Any| { + public constructor(): R|tests/_checkType/Inv| { + super() + } + + } + public final fun R|tests/_checkType/Inv|._(): R|kotlin/Unit| { + } + public final infix fun R|T|.checkType(f: R|tests/_checkType/Inv.() -> kotlin/Unit|): R|kotlin/Unit| { + } diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java index b0f92678e93..6a43dcc6f48 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java @@ -268,6 +268,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest { runTest("compiler/fir/resolve/testData/resolve/NestedSuperType.kt"); } + @TestMetadata("objectInnerClass.kt") + public void testObjectInnerClass() throws Exception { + runTest("compiler/fir/resolve/testData/resolve/objectInnerClass.kt"); + } + @TestMetadata("problems2.kt") public void testProblems2() throws Exception { runTest("compiler/fir/resolve/testData/resolve/problems2.kt"); diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java index 8ab85b7f9f8..84b1d670b61 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java @@ -268,6 +268,11 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos runTest("compiler/fir/resolve/testData/resolve/NestedSuperType.kt"); } + @TestMetadata("objectInnerClass.kt") + public void testObjectInnerClass() throws Exception { + runTest("compiler/fir/resolve/testData/resolve/objectInnerClass.kt"); + } + @TestMetadata("problems2.kt") public void testProblems2() throws Exception { runTest("compiler/fir/resolve/testData/resolve/problems2.kt");