KT-64080 [LL] Resolve super calls to BODY_RESOLVE for on-air resolve

^KT-64080 Fixed
This commit is contained in:
Roman Golyshev
2023-12-06 14:42:24 +01:00
parent 3c7dfc0e5b
commit f266a44356
21 changed files with 289 additions and 1 deletions
@@ -456,13 +456,31 @@ object LowLevelFirApiFacadeForResolveOnAir {
private fun bodyResolveRequired(container: KtDeclaration, elementToReplace: PsiElement): Boolean = when {
container == elementToReplace -> true
container is KtDeclarationWithBody -> container.bodyExpression.isAncestor(elementToReplace)
container is KtDeclarationWithBody -> {
val bodyExpression = container.bodyExpression
val secondaryConstructorSuperCallArgs = (container as? KtSecondaryConstructor)?.getDelegationCallOrNull()?.valueArgumentList
bodyExpression.isAncestor(elementToReplace) || secondaryConstructorSuperCallArgs.isAncestor(elementToReplace)
}
container is KtProperty -> container.delegateExpressionOrInitializer.isAncestor(elementToReplace)
container is KtParameter -> container.defaultValue.isAncestor(elementToReplace)
container is KtEnumEntry -> {
container.initializerList.isAncestor(elementToReplace) || container.body.isAncestor(elementToReplace)
}
container is KtClassOrObject -> {
container.superTypeListEntries.any { superTypeEntry ->
when (superTypeEntry) {
is KtSuperTypeCallEntry -> superTypeEntry.valueArgumentList.isAncestor(elementToReplace)
is KtDelegatedSuperTypeEntry -> superTypeEntry.delegateExpression.isAncestor(elementToReplace)
else -> false
}
}
}
container is KtScript || container is KtAnonymousInitializer -> true
else -> false
}
@@ -0,0 +1,19 @@
Tower Data Context:
Element 0
Scope: FirDefaultStarImportingScope
Element 1
Scope: FirExplicitStarImportingScope
Element 2
Scope: FirDefaultSimpleImportingScope
Element 3
Scope: FirDefaultSimpleImportingScope
Element 4
Scope: FirPackageMemberScope
Element 5
Scope: FirExplicitSimpleImportingScope
Element 6
Implicit receiver:
FirRegularClassSymbol public final class MyClass : R|kotlin/Any|
Type: test.MyClass
Element 7
Scope: FirLocalScope
@@ -0,0 +1,6 @@
KT element: KtNameReferenceExpression
FIR element: FirPropertyAccessExpressionImpl
FIR source kind: KtRealSourceElementKind
FIR element rendered:
R|test/property|
@@ -0,0 +1,7 @@
package test
val property = 10
class MyClass(i: Int) {
constructor(): this(prop<caret>erty)
}
@@ -0,0 +1,19 @@
Tower Data Context:
Element 0
Scope: FirDefaultStarImportingScope
Element 1
Scope: FirExplicitStarImportingScope
Element 2
Scope: FirDefaultSimpleImportingScope
Element 3
Scope: FirDefaultSimpleImportingScope
Element 4
Scope: FirPackageMemberScope
Element 5
Scope: FirExplicitSimpleImportingScope
Element 6
Implicit receiver:
FirRegularClassSymbol public final class Child : R|test/Base|
Type: test.Child
Element 7
Scope: FirLocalScope
@@ -0,0 +1,6 @@
KT element: KtNameReferenceExpression
FIR element: FirPropertyAccessExpressionImpl
FIR source kind: KtRealSourceElementKind
FIR element rendered:
R|test/property|
@@ -0,0 +1,7 @@
package test
open class Base(action: Int)
val property = 10
class Child : Base(prop<caret>erty)
@@ -0,0 +1,19 @@
Tower Data Context:
Element 0
Scope: FirDefaultStarImportingScope
Element 1
Scope: FirExplicitStarImportingScope
Element 2
Scope: FirDefaultSimpleImportingScope
Element 3
Scope: FirDefaultSimpleImportingScope
Element 4
Scope: FirPackageMemberScope
Element 5
Scope: FirExplicitSimpleImportingScope
Element 6
Implicit receiver:
FirRegularClassSymbol public final class Child : R|test/Base|
Type: test.Child
Element 7
Scope: FirLocalScope
@@ -0,0 +1,6 @@
KT element: KtNameReferenceExpression
FIR element: FirPropertyAccessExpressionImpl
FIR source kind: KtRealSourceElementKind
FIR element rendered:
R|test/property|
@@ -0,0 +1,9 @@
package test
open class Base(i: Int)
val property = 10
class Child : Base {
constructor(): super(prop<caret>erty)
}
@@ -0,0 +1,19 @@
Tower Data Context:
Element 0
Scope: FirDefaultStarImportingScope
Element 1
Scope: FirExplicitStarImportingScope
Element 2
Scope: FirDefaultSimpleImportingScope
Element 3
Scope: FirDefaultSimpleImportingScope
Element 4
Scope: FirPackageMemberScope
Element 5
Scope: FirExplicitSimpleImportingScope
Element 6
Implicit receiver:
FirRegularClassSymbol public final class MyClass : R|test/MyInterface|
Type: test.MyClass
Element 7
Scope: FirLocalScope
@@ -0,0 +1,6 @@
KT element: KtNameReferenceExpression
FIR element: FirPropertyAccessExpressionImpl
FIR source kind: KtRealSourceElementKind
FIR element rendered:
R|test/property|
@@ -0,0 +1,7 @@
package test
interface MyInterface
val property: MyInterface = object : MyInterface {}
class MyClass: MyInterface by prop<caret>erty
@@ -0,0 +1,27 @@
Tower Data Context:
Element 0
Scope: FirDefaultStarImportingScope
Element 1
Scope: FirExplicitStarImportingScope
Element 2
Scope: FirDefaultSimpleImportingScope
Element 3
Scope: FirDefaultSimpleImportingScope
Element 4
Scope: FirPackageMemberScope
Element 5
Scope: FirExplicitSimpleImportingScope
Element 6
Implicit receiver:
FirRegularClassSymbol public final companion object Companion : R|test/MyInterface|
Type: test.MyClass.Companion
Element 7
Scope: FirNestedClassifierScopeImpl
Classifiers:
FirRegularClassSymbol public final companion object Companion : R|test/MyInterface|
Element 8
Implicit receiver:
FirRegularClassSymbol public final class MyClass : R|test/MyInterface|
Type: test.MyClass
Element 9
Scope: FirLocalScope
@@ -0,0 +1,6 @@
KT element: KtNameReferenceExpression
FIR element: FirResolvedQualifierImpl
FIR source kind: KtRealSourceElementKind
FIR element rendered:
Q|test/MyClass.Companion|
@@ -0,0 +1,7 @@
package test
interface MyInterface
class MyClass: MyInterface by Comp<caret>anion {
companion object : MyInterface
}
@@ -0,0 +1,17 @@
Tower Data Context:
Element 0
Scope: FirDefaultStarImportingScope
Element 1
Scope: FirExplicitStarImportingScope
Element 2
Scope: FirDefaultSimpleImportingScope
Element 3
Scope: FirDefaultSimpleImportingScope
Element 4
Scope: FirPackageMemberScope
Element 5
Scope: FirExplicitSimpleImportingScope
Element 6
Implicit receiver:
FirRegularClassSymbol public final class MyClass : R|test/MyInterface|
Type: test.MyClass
@@ -0,0 +1,6 @@
KT element: KtNameReferenceExpression
FIR element: FirPropertyAccessExpressionImpl
FIR source kind: KtRealSourceElementKind
FIR element rendered:
R|<local>/param|
@@ -0,0 +1,5 @@
package test
interface MyInterface
class MyClass(param: MyInterface): MyInterface by par<caret>am
@@ -53,4 +53,40 @@ public class SourceDependentCopyContextTestGenerated extends AbstractSourceDepen
public void testFunction() throws Exception {
runTest("analysis/low-level-api-fir/testData/dependentCopy/function.kt");
}
@Test
@TestMetadata("superCallArgument_delegatedConstructor.kt")
public void testSuperCallArgument_delegatedConstructor() throws Exception {
runTest("analysis/low-level-api-fir/testData/dependentCopy/superCallArgument_delegatedConstructor.kt");
}
@Test
@TestMetadata("superCallArgument_primaryConstructor.kt")
public void testSuperCallArgument_primaryConstructor() throws Exception {
runTest("analysis/low-level-api-fir/testData/dependentCopy/superCallArgument_primaryConstructor.kt");
}
@Test
@TestMetadata("superCallArgument_secondaryConstructor.kt")
public void testSuperCallArgument_secondaryConstructor() throws Exception {
runTest("analysis/low-level-api-fir/testData/dependentCopy/superCallArgument_secondaryConstructor.kt");
}
@Test
@TestMetadata("superTypeDelegation.kt")
public void testSuperTypeDelegation() throws Exception {
runTest("analysis/low-level-api-fir/testData/dependentCopy/superTypeDelegation.kt");
}
@Test
@TestMetadata("superTypeDelegation_toCompanion.kt")
public void testSuperTypeDelegation_toCompanion() throws Exception {
runTest("analysis/low-level-api-fir/testData/dependentCopy/superTypeDelegation_toCompanion.kt");
}
@Test
@TestMetadata("superTypeDelegation_toPrimaryConstructorParam.kt")
public void testSuperTypeDelegation_toPrimaryConstructorParam() throws Exception {
runTest("analysis/low-level-api-fir/testData/dependentCopy/superTypeDelegation_toPrimaryConstructorParam.kt");
}
}
@@ -53,4 +53,40 @@ public class SourceDependentCopyFirTestGenerated extends AbstractSourceDependent
public void testFunction() throws Exception {
runTest("analysis/low-level-api-fir/testData/dependentCopy/function.kt");
}
@Test
@TestMetadata("superCallArgument_delegatedConstructor.kt")
public void testSuperCallArgument_delegatedConstructor() throws Exception {
runTest("analysis/low-level-api-fir/testData/dependentCopy/superCallArgument_delegatedConstructor.kt");
}
@Test
@TestMetadata("superCallArgument_primaryConstructor.kt")
public void testSuperCallArgument_primaryConstructor() throws Exception {
runTest("analysis/low-level-api-fir/testData/dependentCopy/superCallArgument_primaryConstructor.kt");
}
@Test
@TestMetadata("superCallArgument_secondaryConstructor.kt")
public void testSuperCallArgument_secondaryConstructor() throws Exception {
runTest("analysis/low-level-api-fir/testData/dependentCopy/superCallArgument_secondaryConstructor.kt");
}
@Test
@TestMetadata("superTypeDelegation.kt")
public void testSuperTypeDelegation() throws Exception {
runTest("analysis/low-level-api-fir/testData/dependentCopy/superTypeDelegation.kt");
}
@Test
@TestMetadata("superTypeDelegation_toCompanion.kt")
public void testSuperTypeDelegation_toCompanion() throws Exception {
runTest("analysis/low-level-api-fir/testData/dependentCopy/superTypeDelegation_toCompanion.kt");
}
@Test
@TestMetadata("superTypeDelegation_toPrimaryConstructorParam.kt")
public void testSuperTypeDelegation_toPrimaryConstructorParam() throws Exception {
runTest("analysis/low-level-api-fir/testData/dependentCopy/superTypeDelegation_toPrimaryConstructorParam.kt");
}
}