KT-64186 [LL] Correctly handle anonymous objects' headers in ContextCollector

This bug spilled into reference shortener, and then to
"redundant qualifier inspection" and code completion from there;
it caused KTIJ-26024 to reproduce again (but only for anonymous objects)

^KT-64186 Fixed
This commit is contained in:
Roman Golyshev
2023-12-07 23:42:51 +01:00
committed by Space Team
parent 2eb1e65bbf
commit 78f492394c
16 changed files with 231 additions and 1 deletions
@@ -844,12 +844,36 @@ public class FirIdeNormalAnalysisSourceModuleReferenceShortenerTestGenerated ext
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/superTypeConstructorArgument_nested.kt");
}
@Test
@TestMetadata("superTypeConstructorArgument_nested_objectLiteral.kt")
public void testSuperTypeConstructorArgument_nested_objectLiteral() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/superTypeConstructorArgument_nested_objectLiteral.kt");
}
@Test
@TestMetadata("superTypeConstructorArgument_objectLiteral.kt")
public void testSuperTypeConstructorArgument_objectLiteral() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/superTypeConstructorArgument_objectLiteral.kt");
}
@Test
@TestMetadata("superTypeConstructor_nested.kt")
public void testSuperTypeConstructor_nested() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/superTypeConstructor_nested.kt");
}
@Test
@TestMetadata("superTypeConstructor_nested_objectLiteral.kt")
public void testSuperTypeConstructor_nested_objectLiteral() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/superTypeConstructor_nested_objectLiteral.kt");
}
@Test
@TestMetadata("superTypeConstructor_objectLiteral.kt")
public void testSuperTypeConstructor_objectLiteral() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/superTypeConstructor_objectLiteral.kt");
}
@Test
@TestMetadata("superTypeDelegation.kt")
public void testSuperTypeDelegation() throws Exception {
@@ -844,12 +844,36 @@ public class FirStandaloneNormalAnalysisSourceModuleReferenceShortenerTestGenera
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/superTypeConstructorArgument_nested.kt");
}
@Test
@TestMetadata("superTypeConstructorArgument_nested_objectLiteral.kt")
public void testSuperTypeConstructorArgument_nested_objectLiteral() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/superTypeConstructorArgument_nested_objectLiteral.kt");
}
@Test
@TestMetadata("superTypeConstructorArgument_objectLiteral.kt")
public void testSuperTypeConstructorArgument_objectLiteral() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/superTypeConstructorArgument_objectLiteral.kt");
}
@Test
@TestMetadata("superTypeConstructor_nested.kt")
public void testSuperTypeConstructor_nested() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/superTypeConstructor_nested.kt");
}
@Test
@TestMetadata("superTypeConstructor_nested_objectLiteral.kt")
public void testSuperTypeConstructor_nested_objectLiteral() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/superTypeConstructor_nested_objectLiteral.kt");
}
@Test
@TestMetadata("superTypeConstructor_objectLiteral.kt")
public void testSuperTypeConstructor_objectLiteral() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/superTypeConstructor_objectLiteral.kt");
}
@Test
@TestMetadata("superTypeDelegation.kt")
public void testSuperTypeDelegation() throws Exception {
@@ -0,0 +1,10 @@
// FILE: main.kt
abstract class Outer {
abstract class Nested(a: Any) : Outer()
class OtherNested
val foo = object : Outer.Nested(<expr>Outer.OtherNested()</expr>) {}
}
@@ -0,0 +1,8 @@
Before shortening: Outer.OtherNested()
with DO_NOT_SHORTEN:
with SHORTEN_IF_ALREADY_IMPORTED:
[qualifier] Outer.OtherNested()
with SHORTEN_AND_IMPORT:
[qualifier] Outer.OtherNested()
with SHORTEN_AND_STAR_IMPORT:
[qualifier] Outer.OtherNested()
@@ -0,0 +1,9 @@
// FILE: main.kt
abstract class Outer {
abstract class Nested(a: Any) : Outer()
class OtherNested
}
val foo = object : Outer.Nested(<expr>Outer.OtherNested()</expr>) {}
@@ -0,0 +1,8 @@
Before shortening: Outer.OtherNested()
with DO_NOT_SHORTEN:
with SHORTEN_IF_ALREADY_IMPORTED:
[qualifier] Outer.OtherNested()
with SHORTEN_AND_IMPORT:
[qualifier] Outer.OtherNested()
with SHORTEN_AND_STAR_IMPORT:
[qualifier] Outer.OtherNested()
@@ -0,0 +1,8 @@
// FILE: main.kt
abstract class Outer {
abstract class Nested : Outer()
<expr>val foo = object : Outer.Nested() {}</expr>
}
@@ -0,0 +1,8 @@
Before shortening: val foo = object : Outer.Nested() {}
with DO_NOT_SHORTEN:
with SHORTEN_IF_ALREADY_IMPORTED:
[type] Outer.Nested
with SHORTEN_AND_IMPORT:
[type] Outer.Nested
with SHORTEN_AND_STAR_IMPORT:
[type] Outer.Nested
@@ -0,0 +1,7 @@
// FILE: main.kt
abstract class Outer {
abstract class Nested : Outer()
}
<expr>val foo = object : Outer.Nested() {}</expr>
@@ -0,0 +1,7 @@
Before shortening: val foo = object : Outer.Nested() {}
with DO_NOT_SHORTEN:
with SHORTEN_IF_ALREADY_IMPORTED:
with SHORTEN_AND_IMPORT:
[type] Outer.Nested
with SHORTEN_AND_STAR_IMPORT:
[type] Outer.Nested
@@ -398,6 +398,15 @@ private class ContextCollectorVisitor(
}
}
/**
* Same as [processClassHeader], but for anonymous objects.
*
* N.B. Anonymous classes cannot have its own explicit type parameters, so we do not process them.
*/
private fun Processor.processAnonymousObjectHeader(anonymousObject: FirAnonymousObject) {
processList(anonymousObject.superTypeRefs)
}
override fun visitConstructor(constructor: FirConstructor) = withProcessor(constructor) {
dumpContext(constructor, ContextKind.SELF)
@@ -624,6 +633,8 @@ private class ContextCollectorVisitor(
processSignatureAnnotations(anonymousObject)
onActiveBody {
processAnonymousObjectHeader(anonymousObject)
context.withAnonymousObject(anonymousObject, holder) {
dumpContext(anonymousObject, ContextKind.BODY)
@@ -632,7 +643,6 @@ private class ContextCollectorVisitor(
}
}
}
}
override fun visitBlock(block: FirBlock) = withProcessor(block) {
@@ -0,0 +1,9 @@
package test
open class Base(param: Nested) {
class Nested
}
val property: Base.Nested = Base.Nested()
val child = object : Base(<expr>property</expr>) {}
@@ -0,0 +1,43 @@
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
Scope: FirNestedClassifierScopeWithSubstitution
Classifiers:
FirRegularClassSymbol public final class Nested : R|kotlin/Any|
Static scope owner symbol: FirRegularClassSymbol public open class Base : R|kotlin/Any|
FILE: [ResolvedTo(IMPORTS)] superTypeCallArgumentsExpression_objectLiteral.kt
public open [ResolvedTo(STATUS)] class Base : R|kotlin/Any| {
public [ResolvedTo(STATUS)] constructor([ResolvedTo(STATUS)] param: R|test/Base.Nested|): R|test/Base| {
LAZY_super<R|kotlin/Any|>
}
public final [ResolvedTo(STATUS)] class Nested : R|kotlin/Any| {
public? [ResolvedTo(RAW_FIR)] constructor(): R|test/Base.Nested| {
LAZY_super<R|kotlin/Any|>
}
}
}
public final [ResolvedTo(CONTRACTS)] val property: R|test/Base.Nested| = Base#.Nested#()
public [ResolvedTo(CONTRACTS)] get(): R|test/Base.Nested|
public final [ResolvedTo(BODY_RESOLVE)] val child: R|test/Base| = object : R|test/Base| {
private [ResolvedTo(BODY_RESOLVE)] constructor(): R|test/<anonymous>| {
super<R|test/Base|>(R|test/property|)
}
}
public [ResolvedTo(BODY_RESOLVE)] get(): R|test/Base|
@@ -0,0 +1,7 @@
package test
open class Base {
class Nested
}
val child = object : <expr>Base</expr>() {}
@@ -0,0 +1,36 @@
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
FILE: [ResolvedTo(IMPORTS)] superTypeCallee_objectLiteral.kt
public open [ResolvedTo(STATUS)] class Base : R|kotlin/Any| {
public [ResolvedTo(STATUS)] constructor(): R|test/Base| {
LAZY_super<R|kotlin/Any|>
}
public? final? [ResolvedTo(RAW_FIR)] class Nested : R|kotlin/Any| {
public? [ResolvedTo(RAW_FIR)] constructor(): R|test/Base.Nested| {
LAZY_super<R|kotlin/Any|>
}
}
}
public final [ResolvedTo(BODY_RESOLVE)] val child: R|test/Base| = object : R|test/Base| {
private [ResolvedTo(BODY_RESOLVE)] constructor(): R|test/<anonymous>| {
super<R|test/Base|>()
}
}
public [ResolvedTo(BODY_RESOLVE)] get(): R|test/Base|
@@ -159,6 +159,12 @@ public class ContextCollectorSourceTestGenerated extends AbstractContextCollecto
runTest("analysis/low-level-api-fir/testData/contextCollector/classHeaderPositions/superTypeCallArgumentsExpression.kt");
}
@Test
@TestMetadata("superTypeCallArgumentsExpression_objectLiteral.kt")
public void testSuperTypeCallArgumentsExpression_objectLiteral() throws Exception {
runTest("analysis/low-level-api-fir/testData/contextCollector/classHeaderPositions/superTypeCallArgumentsExpression_objectLiteral.kt");
}
@Test
@TestMetadata("superTypeCallArgumentsTypeRef.kt")
public void testSuperTypeCallArgumentsTypeRef() throws Exception {
@@ -177,6 +183,12 @@ public class ContextCollectorSourceTestGenerated extends AbstractContextCollecto
runTest("analysis/low-level-api-fir/testData/contextCollector/classHeaderPositions/superTypeCalleeGenerics.kt");
}
@Test
@TestMetadata("superTypeCallee_objectLiteral.kt")
public void testSuperTypeCallee_objectLiteral() throws Exception {
runTest("analysis/low-level-api-fir/testData/contextCollector/classHeaderPositions/superTypeCallee_objectLiteral.kt");
}
@Test
@TestMetadata("superTypeDelegatedExpression.kt")
public void testSuperTypeDelegatedExpression() throws Exception {