From e18fb20d5a67b53d424e1101518f9f528347ff0c Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Thu, 31 Mar 2016 22:31:02 +0300 Subject: [PATCH] Completion after "by" for top-level properties --- .../smart/propertyDelegate/TopLevelVal.kt | 16 ++++++++++++++++ .../test/JvmSmartCompletionTestGenerated.java | 6 ++++++ .../jetbrains/kotlin/idea/core/ExpectedInfos.kt | 3 ++- 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 idea/idea-completion/testData/smart/propertyDelegate/TopLevelVal.kt diff --git a/idea/idea-completion/testData/smart/propertyDelegate/TopLevelVal.kt b/idea/idea-completion/testData/smart/propertyDelegate/TopLevelVal.kt new file mode 100644 index 00000000000..3c4d11d6657 --- /dev/null +++ b/idea/idea-completion/testData/smart/propertyDelegate/TopLevelVal.kt @@ -0,0 +1,16 @@ +import kotlin.reflect.KProperty + +class X +class Y +class Z + +operator fun X.getValue(thisRef: Nothing?, property: KProperty<*>): String = "" +operator fun Y.getValue(thisRef: Any?, property: KProperty<*>): String = "" +operator fun Z.getValue(thisRef: Any, property: KProperty<*>): String = "" + +val property by + +// EXIST: lazy +// EXIST: X +// EXIST: Y +// ABSENT: Z diff --git a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/JvmSmartCompletionTestGenerated.java b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/JvmSmartCompletionTestGenerated.java index 368f04e4efe..f8130b8c253 100644 --- a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/JvmSmartCompletionTestGenerated.java +++ b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/JvmSmartCompletionTestGenerated.java @@ -1540,6 +1540,12 @@ public class JvmSmartCompletionTestGenerated extends AbstractJvmSmartCompletionT doTest(fileName); } + @TestMetadata("TopLevelVal.kt") + public void testTopLevelVal() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/smart/propertyDelegate/TopLevelVal.kt"); + doTest(fileName); + } + @TestMetadata("ValInClass.kt") public void testValInClass() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/smart/propertyDelegate/ValInClass.kt"); diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/ExpectedInfos.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/ExpectedInfos.kt index 40b19e7e780..74ff8812173 100644 --- a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/ExpectedInfos.kt +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/ExpectedInfos.kt @@ -33,6 +33,7 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.allArgumentsMapped import org.jetbrains.kotlin.resolve.calls.callUtil.getCall import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall import org.jetbrains.kotlin.resolve.calls.util.DelegatingCall +import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns import org.jetbrains.kotlin.resolve.descriptorUtil.hasDefaultValue import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.TypeSubstitutor @@ -611,7 +612,7 @@ class ExpectedInfos( val scope = expressionWithType.getResolutionScope(bindingContext, resolutionFacade) val propertyOwnerType = property.fuzzyExtensionReceiverType() ?: property.dispatchReceiverParameter?.type?.let { FuzzyType(it, emptyList()) } - ?: return null + ?: FuzzyType(property.builtIns.nullableNothingType, emptyList()) val explicitPropertyType = property.fuzzyReturnType()?.check { propertyDeclaration.typeReference != null } val typesWithGetDetector = TypesWithGetValueDetector(scope, indicesHelper, propertyOwnerType, explicitPropertyType)