FIR IDE: align resolution behavior of super with FE1.0

That is, for a labeled `super`, the keyword should resolve to the super
type and the label should be resolved to the current type.
This commit is contained in:
Tianyu Geng
2021-09-22 13:30:01 -07:00
committed by Space
parent 0d966ec65a
commit d3c91ee9be
6 changed files with 38 additions and 0 deletions
@@ -289,6 +289,12 @@ internal object FirReferenceResolveHelper {
session: FirSession,
symbolBuilder: KtSymbolByFirBuilder
): Collection<KtSymbol> {
// If the cursor position is on the label of `super`, we want to resolve to the current class. FIR represents `super` as
// accessing the `super` property on `this`, hence this weird looking if condition. In addition, the current class type is available
// from the dispatch receiver `this`.
if (expression is KtLabelReferenceExpression && fir is FirPropertyAccessExpression && fir.calleeReference is FirSuperReference) {
return listOfNotNull((fir.dispatchReceiver.typeRef as? FirResolvedTypeRef)?.toTargetSymbol(session, symbolBuilder))
}
val calleeReference =
if (fir is FirFunctionCall &&
fir.isImplicitFunctionCall() &&
@@ -474,6 +474,18 @@ public class FirReferenceResolveTestGenerated extends AbstractFirReferenceResolv
runTest("analysis/analysis-api/testData/referenceResolve/SeveralOverrides.kt");
}
@Test
@TestMetadata("superWithLabel_caretAtLabel.kt")
public void testSuperWithLabel_caretAtLabel() throws Exception {
runTest("analysis/analysis-api/testData/referenceResolve/superWithLabel_caretAtLabel.kt");
}
@Test
@TestMetadata("superWithLabel_caretAtSuper.kt")
public void testSuperWithLabel_caretAtSuper() throws Exception {
runTest("analysis/analysis-api/testData/referenceResolve/superWithLabel_caretAtSuper.kt");
}
@Test
@TestMetadata("SyntheticProperty.kt")
public void testSyntheticProperty() throws Exception {
@@ -0,0 +1,8 @@
interface A {
fun a() {}
}
class Foo : A {
fun foo() {
super@F<caret>oo.a()
}
}
@@ -0,0 +1,2 @@
Resolved to:
0: (in ROOT) class Foo : A
@@ -0,0 +1,8 @@
interface A {
fun a() {}
}
class Foo : A {
fun foo() {
s<caret>uper@Foo.a()
}
}
@@ -0,0 +1,2 @@
Resolved to:
0: (in ROOT) interface A