[FIR] Add excessive delegated constructors to FIR tree
^KTIJ-25453 fixed Merge-request: KT-MR-10379 Merged-by: Egor Kulikov <Egor.Kulikov@jetbrains.com>
This commit is contained in:
+6
@@ -1991,6 +1991,12 @@ public class Fe10IdeNormalAnalysisSourceModuleReferenceResolveTestGenerated exte
|
||||
runTest("analysis/analysis-api/testData/referenceResolve/withErrors/ClassNameBeforeDot.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("ClassWithMultipleSuperTypeCalls.kt")
|
||||
public void testClassWithMultipleSuperTypeCalls() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/referenceResolve/withErrors/ClassWithMultipleSuperTypeCalls.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("CollectionLiteralLeft.kt")
|
||||
public void testCollectionLiteralLeft() throws Exception {
|
||||
|
||||
+6
@@ -1991,6 +1991,12 @@ public class FirIdeDependentAnalysisSourceModuleReferenceResolveTestGenerated ex
|
||||
runTest("analysis/analysis-api/testData/referenceResolve/withErrors/ClassNameBeforeDot.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("ClassWithMultipleSuperTypeCalls.kt")
|
||||
public void testClassWithMultipleSuperTypeCalls() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/referenceResolve/withErrors/ClassWithMultipleSuperTypeCalls.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("CollectionLiteralLeft.kt")
|
||||
public void testCollectionLiteralLeft() throws Exception {
|
||||
|
||||
+6
@@ -1991,6 +1991,12 @@ public class FirIdeNormalAnalysisSourceModuleReferenceResolveTestGenerated exten
|
||||
runTest("analysis/analysis-api/testData/referenceResolve/withErrors/ClassNameBeforeDot.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("ClassWithMultipleSuperTypeCalls.kt")
|
||||
public void testClassWithMultipleSuperTypeCalls() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/referenceResolve/withErrors/ClassWithMultipleSuperTypeCalls.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("CollectionLiteralLeft.kt")
|
||||
public void testCollectionLiteralLeft() throws Exception {
|
||||
|
||||
+6
@@ -1991,6 +1991,12 @@ public class FirStandaloneNormalAnalysisSourceModuleReferenceResolveTestGenerate
|
||||
runTest("analysis/analysis-api/testData/referenceResolve/withErrors/ClassNameBeforeDot.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("ClassWithMultipleSuperTypeCalls.kt")
|
||||
public void testClassWithMultipleSuperTypeCalls() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/referenceResolve/withErrors/ClassWithMultipleSuperTypeCalls.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("CollectionLiteralLeft.kt")
|
||||
public void testCollectionLiteralLeft() throws Exception {
|
||||
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
open class A()
|
||||
open class B(): A()
|
||||
class C(): <caret>A(), B()
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
Resolved to:
|
||||
0: (in A) constructor()
|
||||
+14
-2
@@ -189,8 +189,20 @@ private fun calculateLazyBodyForAnonymousInitializer(designation: FirDesignation
|
||||
}
|
||||
}
|
||||
|
||||
private fun needCalculatingLazyBodyForConstructor(firConstructor: FirConstructor): Boolean =
|
||||
needCalculatingLazyBodyForFunction(firConstructor) || firConstructor.delegatedConstructor is FirLazyDelegatedConstructorCall
|
||||
private fun needCalculatingLazyBodyForConstructor(firConstructor: FirConstructor): Boolean {
|
||||
if (needCalculatingLazyBodyForFunction(firConstructor) || firConstructor.delegatedConstructor is FirLazyDelegatedConstructorCall) {
|
||||
return true
|
||||
}
|
||||
val deleatedConstructor = firConstructor.delegatedConstructor
|
||||
if (deleatedConstructor is FirMultiDelegatedConstructorCall) {
|
||||
for (delegated in deleatedConstructor.delegatedConstructorCalls) {
|
||||
if (delegated is FirLazyDelegatedConstructorCall) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
private fun calculateLazyBodiesForField(designation: FirDesignation) {
|
||||
val field = designation.target as FirField
|
||||
|
||||
+26
-6
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.fir.declarations.builder.FirPropertyAccessorBuilder
|
||||
import org.jetbrains.kotlin.fir.declarations.builder.FirPropertyBuilder
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isInner
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
|
||||
import org.jetbrains.kotlin.fir.expressions.FirMultiDelegatedConstructorCall
|
||||
import org.jetbrains.kotlin.fir.references.FirSuperReference
|
||||
import org.jetbrains.kotlin.fir.scopes.FirScopeProvider
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
|
||||
@@ -32,7 +33,6 @@ import org.jetbrains.kotlin.name.NameUtils
|
||||
import org.jetbrains.kotlin.psi
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.hasExpectModifier
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.lastIsInstanceOrNull
|
||||
|
||||
internal class RawFirNonLocalDeclarationBuilder private constructor(
|
||||
session: FirSession,
|
||||
@@ -222,8 +222,9 @@ internal class RawFirNonLocalDeclarationBuilder private constructor(
|
||||
withPsiEntry("constructor", constructor, baseSession.llFirModuleData.ktModule)
|
||||
}
|
||||
val selfType = classOrObject.toDelegatedSelfType(typeParameters, containingClass.symbol)
|
||||
val superTypeCallEntry = classOrObject.superTypeListEntries.lastIsInstanceOrNull<KtSuperTypeCallEntry>()
|
||||
return ConstructorConversionParams(superTypeCallEntry, selfType, typeParameters)
|
||||
val allSuperTypeCallEntries = classOrObject.superTypeListEntries.filterIsInstance<KtSuperTypeCallEntry>()
|
||||
val superTypeCallEntry = allSuperTypeCallEntries.lastOrNull()
|
||||
return ConstructorConversionParams(superTypeCallEntry, selfType, typeParameters, allSuperTypeCallEntries)
|
||||
}
|
||||
|
||||
override fun visitSecondaryConstructor(constructor: KtSecondaryConstructor, data: FirElement?): FirElement {
|
||||
@@ -244,18 +245,36 @@ internal class RawFirNonLocalDeclarationBuilder private constructor(
|
||||
fun processPrimaryConstructor(classOrObject: KtClassOrObject, constructor: KtPrimaryConstructor?): FirElement {
|
||||
val params = extractContructorConversionParams(classOrObject, constructor)
|
||||
val firConstructor = originalDeclaration as FirConstructor
|
||||
val calleeReference = firConstructor.delegatedConstructor?.calleeReference as FirSuperReference?
|
||||
val allSuperTypeCallEntries = if (params.allSuperTypeCallEntries.size <= 1) {
|
||||
params.allSuperTypeCallEntries.map { it to firConstructor.delegatedConstructor!!.constructedTypeRef }
|
||||
} else {
|
||||
params.allSuperTypeCallEntries.zip((firConstructor.delegatedConstructor as FirMultiDelegatedConstructorCall).delegatedConstructorCalls.map { it.constructedTypeRef })
|
||||
}
|
||||
val newConstructor = constructor.toFirConstructor(
|
||||
params.superTypeCallEntry,
|
||||
firConstructor.delegatedConstructor?.constructedTypeRef,
|
||||
params.selfType,
|
||||
classOrObject,
|
||||
params.typeParameters,
|
||||
allSuperTypeCallEntries,
|
||||
firConstructor.delegatedConstructor == null,
|
||||
copyConstructedTypeRefWithImplicitSource = false,
|
||||
)
|
||||
if (calleeReference != null) {
|
||||
(newConstructor.delegatedConstructor?.calleeReference as? FirSuperReference)?.replaceSuperTypeRef(calleeReference.superTypeRef)
|
||||
val delegatedConstructor = firConstructor.delegatedConstructor
|
||||
if (delegatedConstructor is FirMultiDelegatedConstructorCall) {
|
||||
for ((oldExcessiveDelegate, newExcessiveDelegate) in delegatedConstructor.delegatedConstructorCalls
|
||||
.zip((newConstructor.delegatedConstructor as FirMultiDelegatedConstructorCall).delegatedConstructorCalls)) {
|
||||
val calleeReferenceForExessiveDelegate = oldExcessiveDelegate.calleeReference
|
||||
if (calleeReferenceForExessiveDelegate is FirSuperReference) {
|
||||
(newExcessiveDelegate.calleeReference as? FirSuperReference)
|
||||
?.replaceSuperTypeRef(calleeReferenceForExessiveDelegate.superTypeRef)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
val calleeReference = delegatedConstructor?.calleeReference
|
||||
if (calleeReference is FirSuperReference) {
|
||||
(newConstructor.delegatedConstructor?.calleeReference as? FirSuperReference)?.replaceSuperTypeRef(calleeReference.superTypeRef)
|
||||
}
|
||||
}
|
||||
return newConstructor
|
||||
}
|
||||
@@ -351,6 +370,7 @@ internal class RawFirNonLocalDeclarationBuilder private constructor(
|
||||
val superTypeCallEntry: KtSuperTypeCallEntry?,
|
||||
val selfType: FirTypeRef,
|
||||
val typeParameters: List<FirTypeParameterRef>,
|
||||
val allSuperTypeCallEntries: List<KtSuperTypeCallEntry>,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+6
@@ -6037,6 +6037,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
||||
public void testTwoSecondaryConstructors() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/constructorConsistency/twoSecondaryConstructors.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("twoSuperTypeCalls.kt")
|
||||
public void testTwoSuperTypeCalls() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/constructorConsistency/twoSuperTypeCalls.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
+6
@@ -6037,6 +6037,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
||||
public void testTwoSecondaryConstructors() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/constructorConsistency/twoSecondaryConstructors.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("twoSuperTypeCalls.kt")
|
||||
public void testTwoSuperTypeCalls() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/constructorConsistency/twoSuperTypeCalls.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
Reference in New Issue
Block a user