KT-8442 related: correct handling of erroneous destructuring references, fixes EA-90434

This commit is contained in:
Mikhail Glukhikh
2016-10-24 18:04:25 +03:00
parent e7e56ab85c
commit e53940f4af
4 changed files with 16 additions and 1 deletions
@@ -47,7 +47,8 @@ class KtDestructuringDeclarationReference(element: KtDestructuringDeclarationEnt
override val resolvesByNames: Collection<Name>
get() {
val componentIndex = (element.parent as KtDestructuringDeclaration).entries.indexOf(element) + 1
val destructuringParent = element.parent as? KtDestructuringDeclaration ?: return emptyList()
val componentIndex = destructuringParent.entries.indexOf(element) + 1
return listOf(Name.identifier("component$componentIndex"))
}
}
@@ -0,0 +1,5 @@
// "Optimize imports" "true"
<caret>import kotlin.collections.*
val (a, b, c) = Triple(1, 2, 3)
@@ -0,0 +1,3 @@
// "Optimize imports" "true"
val (a, b, c) = Triple(1, 2, 3)
@@ -6575,6 +6575,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/optimizeImports"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), true);
}
@TestMetadata("destructuringAtTop.kt")
public void testDestructuringAtTop() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/optimizeImports/destructuringAtTop.kt");
doTest(fileName);
}
@TestMetadata("fileRuntime.kt")
public void testFileRuntime() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/optimizeImports/fileRuntime.kt");