From 2bdbbdd1a72c2a805f214f69be5f50203f6a93e9 Mon Sep 17 00:00:00 2001 From: Victor Petukhov Date: Wed, 22 Sep 2021 13:50:13 +0300 Subject: [PATCH] Commit delegation expression's trace with errors if we couldn't extract type info for it ^KT-44843 Fixed --- ...irOldFrontendDiagnosticsTestGenerated.java | 6 ++++ ...DiagnosticsWithLightTreeTestGenerated.java | 6 ++++ .../resolve/DelegatedPropertyResolver.kt | 6 +++- .../tests/delegatedProperty/recursiveType.kt | 4 +-- .../tests/delegation/kt44843.fir.kt | 25 +++++++++++++++ .../diagnostics/tests/delegation/kt44843.kt | 25 +++++++++++++++ .../diagnostics/tests/delegation/kt44843.txt | 32 +++++++++++++++++++ .../test/runners/DiagnosticTestGenerated.java | 6 ++++ 8 files changed, 107 insertions(+), 3 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/delegation/kt44843.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegation/kt44843.kt create mode 100644 compiler/testData/diagnostics/tests/delegation/kt44843.txt diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index 011c853c055..05674255b31 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -8355,6 +8355,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/delegation/kt40510.kt"); } + @Test + @TestMetadata("kt44843.kt") + public void testKt44843() throws Exception { + runTest("compiler/testData/diagnostics/tests/delegation/kt44843.kt"); + } + @Test @TestMetadata("kt8154.kt") public void testKt8154() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java index f19ed0d95e3..c90102b5616 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java @@ -8355,6 +8355,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/delegation/kt40510.kt"); } + @Test + @TestMetadata("kt44843.kt") + public void testKt44843() throws Exception { + runTest("compiler/testData/diagnostics/tests/delegation/kt44843.kt"); + } + @Test @TestMetadata("kt8154.kt") public void testKt8154() throws Exception { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.kt index 889f2786662..0d50ff12f3b 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.kt @@ -560,7 +560,11 @@ class DelegatedPropertyResolver( traceToResolveDelegatedProperty, false, delegateExpression, ContextDependency.DEPENDENT ) - var delegateType = delegateTypeInfo.type ?: return null + var delegateType = delegateTypeInfo.type ?: run { + traceToResolveDelegatedProperty.commit() + return null + } + var delegateDataFlow = delegateTypeInfo.dataFlowInfo val delegateTypeConstructor = delegateType.constructor diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/recursiveType.kt b/compiler/testData/diagnostics/tests/delegatedProperty/recursiveType.kt index 39286ef1ed3..07b3afb0747 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/recursiveType.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/recursiveType.kt @@ -3,12 +3,12 @@ import kotlin.reflect.KProperty -val a by a +val a by a val b by Delegate(b) val c by d -val d by c +val d by c class Delegate(i: Int) { operator fun getValue(t: Any?, p: KProperty<*>): Int { diff --git a/compiler/testData/diagnostics/tests/delegation/kt44843.fir.kt b/compiler/testData/diagnostics/tests/delegation/kt44843.fir.kt new file mode 100644 index 00000000000..47380f881d5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegation/kt44843.fir.kt @@ -0,0 +1,25 @@ +// WITH_RUNTIME + +// FILE: test.kt +val bar2 by bar2() + +// FILE: lt/neworld/compiler/Foo.kt +package lt.neworld.compiler + +class Foo { + val bar by bar() +} + +// FILE: lt/neworld/compiler/bar/Bar.kt +package lt.neworld.compiler.bar + +import kotlin.properties.ReadOnlyProperty +import kotlin.reflect.KProperty + +fun bar() = Bar() + +class Bar : ReadOnlyProperty { + override fun getValue(thisRef: T, property: KProperty<*>): V { + TODO("Not yet implemented") + } +} diff --git a/compiler/testData/diagnostics/tests/delegation/kt44843.kt b/compiler/testData/diagnostics/tests/delegation/kt44843.kt new file mode 100644 index 00000000000..8444ecf1281 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegation/kt44843.kt @@ -0,0 +1,25 @@ +// WITH_RUNTIME + +// FILE: test.kt +val bar2 by bar2() + +// FILE: lt/neworld/compiler/Foo.kt +package lt.neworld.compiler + +class Foo { + val bar by bar() +} + +// FILE: lt/neworld/compiler/bar/Bar.kt +package lt.neworld.compiler.bar + +import kotlin.properties.ReadOnlyProperty +import kotlin.reflect.KProperty + +fun bar() = Bar() + +class Bar : ReadOnlyProperty { + override fun getValue(thisRef: T, property: KProperty<*>): V { + TODO("Not yet implemented") + } +} diff --git a/compiler/testData/diagnostics/tests/delegation/kt44843.txt b/compiler/testData/diagnostics/tests/delegation/kt44843.txt new file mode 100644 index 00000000000..d86429e58ae --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegation/kt44843.txt @@ -0,0 +1,32 @@ +package + +public val bar2: [ERROR : ] + +package lt { + + package lt.neworld { + + package lt.neworld.compiler { + + public final class Foo { + public constructor Foo() + public final val bar: [ERROR : ] + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + package lt.neworld.compiler.bar { + public fun bar(): lt.neworld.compiler.bar.Bar + + public final class Bar : kotlin.properties.ReadOnlyProperty { + public constructor Bar() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ fun getValue(/*0*/ thisRef: T, /*1*/ property: kotlin.reflect.KProperty<*>): V + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + } + } + } +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index cbd6d51b95f..53cf2e186a5 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -8361,6 +8361,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/delegation/kt40510.kt"); } + @Test + @TestMetadata("kt44843.kt") + public void testKt44843() throws Exception { + runTest("compiler/testData/diagnostics/tests/delegation/kt44843.kt"); + } + @Test @TestMetadata("kt8154.kt") public void testKt8154() throws Exception {