From e3f1f18ca3e765abe60c8123a897c475afd1db5c Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Fri, 28 Feb 2020 15:43:37 +0300 Subject: [PATCH] [FIR] Add empty member scope for type variables --- .../jetbrains/kotlin/fir/resolve/ScopeUtils.kt | 2 +- .../delegates/extensionGenericGetValue.kt | 8 ++++++++ .../delegates/extensionGenericGetValue.txt | 17 +++++++++++++++++ ...tensionGetValueWithTypeVariableAsReceiver.kt | 8 ++++++++ ...ensionGetValueWithTypeVariableAsReceiver.txt | 17 +++++++++++++++++ .../kotlin/fir/FirDiagnosticsTestGenerated.java | 10 ++++++++++ ...irDiagnosticsWithLightTreeTestGenerated.java | 10 ++++++++++ 7 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 compiler/fir/resolve/testData/resolve/delegates/extensionGenericGetValue.kt create mode 100644 compiler/fir/resolve/testData/resolve/delegates/extensionGenericGetValue.txt create mode 100644 compiler/fir/resolve/testData/resolve/delegates/extensionGetValueWithTypeVariableAsReceiver.kt create mode 100644 compiler/fir/resolve/testData/resolve/delegates/extensionGetValueWithTypeVariableAsReceiver.txt diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ScopeUtils.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ScopeUtils.kt index 212fc990520..8fd14717924 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ScopeUtils.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ScopeUtils.kt @@ -64,7 +64,7 @@ fun ConeKotlinType.scope(useSiteSession: FirSession, scopeSession: ScopeSession) FirIntegerLiteralTypeScope(useSiteSession) } as FirScope } - else -> error("Failed type $this") + else -> null } } diff --git a/compiler/fir/resolve/testData/resolve/delegates/extensionGenericGetValue.kt b/compiler/fir/resolve/testData/resolve/delegates/extensionGenericGetValue.kt new file mode 100644 index 00000000000..f2a8127487f --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/delegates/extensionGenericGetValue.kt @@ -0,0 +1,8 @@ +inline fun runLogged(action: () -> L): L { + return action() +} + +operator fun V.getValue(receiver: Any?, p: Any): V = + runLogged { this } + +val testK by runLogged { "K" } \ No newline at end of file diff --git a/compiler/fir/resolve/testData/resolve/delegates/extensionGenericGetValue.txt b/compiler/fir/resolve/testData/resolve/delegates/extensionGenericGetValue.txt new file mode 100644 index 00000000000..bbc7fc040cc --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/delegates/extensionGenericGetValue.txt @@ -0,0 +1,17 @@ +FILE: extensionGenericGetValue.kt + public final inline fun runLogged(action: R|() -> L|): R|L| { + ^runLogged R|/action|.R|FakeOverride|() + } + public final operator fun R|V|.getValue(receiver: R|kotlin/Any?|, p: R|kotlin/Any|): R|V| { + ^getValue R|/runLogged|( = runLogged@fun (): R|V| { + ^ this@R|/getValue| + } + ) + } + public final val testK: R|kotlin/String|by R|/runLogged|( = runLogged@fun (): R|kotlin/String| { + ^ String(K) + } + ) + public get(): R|kotlin/String| { + ^ D|/testK|.R|/getValue|(Null(null), ::R|/testK|) + } diff --git a/compiler/fir/resolve/testData/resolve/delegates/extensionGetValueWithTypeVariableAsReceiver.kt b/compiler/fir/resolve/testData/resolve/delegates/extensionGetValueWithTypeVariableAsReceiver.kt new file mode 100644 index 00000000000..e23ee0e8868 --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/delegates/extensionGetValueWithTypeVariableAsReceiver.kt @@ -0,0 +1,8 @@ +inline fun runLogged(action: () -> L): L { + return action() +} + +operator fun String.getValue(receiver: Any?, p: Any): String = + runLogged { this } + +val testK by runLogged { "K" } \ No newline at end of file diff --git a/compiler/fir/resolve/testData/resolve/delegates/extensionGetValueWithTypeVariableAsReceiver.txt b/compiler/fir/resolve/testData/resolve/delegates/extensionGetValueWithTypeVariableAsReceiver.txt new file mode 100644 index 00000000000..658adcd678f --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/delegates/extensionGetValueWithTypeVariableAsReceiver.txt @@ -0,0 +1,17 @@ +FILE: extensionGetValueWithTypeVariableAsReceiver.kt + public final inline fun runLogged(action: R|() -> L|): R|L| { + ^runLogged R|/action|.R|FakeOverride|() + } + public final operator fun R|kotlin/String|.getValue(receiver: R|kotlin/Any?|, p: R|kotlin/Any|): R|kotlin/String| { + ^getValue R|/runLogged|( = runLogged@fun (): R|kotlin/String| { + ^ this@R|/getValue| + } + ) + } + public final val testK: R|kotlin/String|by R|/runLogged|( = runLogged@fun (): R|kotlin/String| { + ^ String(K) + } + ) + public get(): R|kotlin/String| { + ^ D|/testK|.R|/getValue|(Null(null), ::R|/testK|) + } 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 a319725ac62..e46cdacbf0f 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java @@ -594,6 +594,16 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest { runTest("compiler/fir/resolve/testData/resolve/delegates/delegateWithLambda.kt"); } + @TestMetadata("extensionGenericGetValue.kt") + public void testExtensionGenericGetValue() throws Exception { + runTest("compiler/fir/resolve/testData/resolve/delegates/extensionGenericGetValue.kt"); + } + + @TestMetadata("extensionGetValueWithTypeVariableAsReceiver.kt") + public void testExtensionGetValueWithTypeVariableAsReceiver() throws Exception { + runTest("compiler/fir/resolve/testData/resolve/delegates/extensionGetValueWithTypeVariableAsReceiver.kt"); + } + @TestMetadata("provideDelegate.kt") public void testProvideDelegate() throws Exception { runTest("compiler/fir/resolve/testData/resolve/delegates/provideDelegate.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 0830e575163..ff97fc7f3de 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java @@ -594,6 +594,16 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos runTest("compiler/fir/resolve/testData/resolve/delegates/delegateWithLambda.kt"); } + @TestMetadata("extensionGenericGetValue.kt") + public void testExtensionGenericGetValue() throws Exception { + runTest("compiler/fir/resolve/testData/resolve/delegates/extensionGenericGetValue.kt"); + } + + @TestMetadata("extensionGetValueWithTypeVariableAsReceiver.kt") + public void testExtensionGetValueWithTypeVariableAsReceiver() throws Exception { + runTest("compiler/fir/resolve/testData/resolve/delegates/extensionGetValueWithTypeVariableAsReceiver.kt"); + } + @TestMetadata("provideDelegate.kt") public void testProvideDelegate() throws Exception { runTest("compiler/fir/resolve/testData/resolve/delegates/provideDelegate.kt");