KT-7452 Code completion does not honor smart casts for 'this'
#KT-7452 Fixed
This commit is contained in:
+7
-5
@@ -111,16 +111,18 @@ public class ReferenceVariantsHelper(
|
||||
return descriptors
|
||||
}
|
||||
else {
|
||||
val dataFlowInfo = context.getDataFlowInfo(expression)
|
||||
|
||||
val descriptorsSet = HashSet<DeclarationDescriptor>()
|
||||
|
||||
// process instance members that can be called via implicit receiver's instances
|
||||
val receivers = resolutionScope.getImplicitReceiversWithInstance()
|
||||
for (receiver in receivers) {
|
||||
descriptorsSet.addMembersFromReceiver(receiver.getType(), CallType.NORMAL, kindFilter, nameFilter)
|
||||
}
|
||||
|
||||
val dataFlowInfo = context.getDataFlowInfo(expression)
|
||||
val receiverValues = receivers.map { it.getValue() }
|
||||
for (receiverValue in receiverValues) {
|
||||
for (variant in SmartCastUtils.getSmartCastVariantsWithLessSpecificExcluded(receiverValue, context, containingDeclaration, dataFlowInfo)) {
|
||||
descriptorsSet.addMembersFromReceiver(variant, CallType.NORMAL, kindFilter, nameFilter)
|
||||
}
|
||||
}
|
||||
|
||||
// process extensions and non-instance members
|
||||
for (descriptor in resolutionScope.getDescriptorsFiltered(kindFilter, nameFilter)) {
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
class C {
|
||||
fun bar(){}
|
||||
}
|
||||
|
||||
open class X {
|
||||
fun Any.foo() {
|
||||
if (this is C && this@X is Y) {
|
||||
<caret>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Y : X() {
|
||||
fun y()
|
||||
}
|
||||
|
||||
fun C.extFun(){}
|
||||
|
||||
// EXIST: bar
|
||||
// EXIST: y
|
||||
// EXIST: extFun
|
||||
+6
@@ -931,6 +931,12 @@ public class JSBasicCompletionTestGenerated extends AbstractJSBasicCompletionTes
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("SmartCastThis.kt")
|
||||
public void testSmartCastThis() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/SmartCastThis.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("StandardJetArrayFirst.kt")
|
||||
public void testStandardJetArrayFirst() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/StandardJetArrayFirst.kt");
|
||||
|
||||
+6
@@ -931,6 +931,12 @@ public class JvmBasicCompletionTestGenerated extends AbstractJvmBasicCompletionT
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("SmartCastThis.kt")
|
||||
public void testSmartCastThis() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/SmartCastThis.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("StandardJetArrayFirst.kt")
|
||||
public void testStandardJetArrayFirst() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/StandardJetArrayFirst.kt");
|
||||
|
||||
Reference in New Issue
Block a user