[FIR JS] Don't create secondary constructor calls for externals

The change in PSI consistency test is needed, because
we may sometimes observe empty
`KtConstructorDelegationCall`s, and we don't want
to build delegation calls for constructors of `external`
classes with such calls.

^KT-64548 Fixed
This commit is contained in:
Nikolay Lunyak
2024-01-08 18:14:43 +02:00
committed by Space Team
parent 9a598026c8
commit 4b8b7aaa54
4 changed files with 15 additions and 7 deletions
@@ -1161,7 +1161,7 @@ class LightTreeRawFirDeclarationBuilder(
private fun convertConstructorDelegationCall(
constructorDelegationCall: LighterASTNode,
classWrapper: ClassWrapper
): FirDelegatedConstructorCall {
): FirDelegatedConstructorCall? {
var thisKeywordPresent = false
val firValueArguments = mutableListOf<FirExpression>()
constructorDelegationCall.forEachChildren {
@@ -1172,6 +1172,9 @@ class LightTreeRawFirDeclarationBuilder(
}
val isImplicit = constructorDelegationCall.textLength == 0
if (isImplicit && classWrapper.modifiers.hasExternal()) {
return null
}
val isThis = thisKeywordPresent //|| (isImplicit && classWrapper.hasPrimaryConstructor)
val delegatedType =
when {
@@ -16,7 +16,7 @@ import org.jetbrains.kotlin.fir.lightTree.fir.modifier.Modifier
import org.jetbrains.kotlin.fir.types.FirTypeRef
class ClassWrapper(
private val modifiers: Modifier,
val modifiers: Modifier,
private val classKind: ClassKind,
val classBuilder: FirClassBuilder,
val hasSecondaryConstructor: Boolean,
@@ -1988,11 +1988,15 @@ open class PsiRawFirBuilder(
}
dispatchReceiverType = owner.obtainDispatchReceiverForConstructor()
contextReceivers.addAll(convertContextReceivers(owner.contextReceivers))
delegatedConstructor = buildOrLazyDelegatedConstructorCall(
isThis = isDelegatedCallToThis(),
constructedTypeRef = delegatedTypeRef,
) {
getDelegationCall().convert(delegatedTypeRef)
val delegationCall = getDelegationCall()
val hasExplicitDelegationCall = delegationCall.textLength > 0
if (!owner.hasModifier(EXTERNAL_KEYWORD) || hasExplicitDelegationCall) {
delegatedConstructor = buildOrLazyDelegatedConstructorCall(
isThis = isDelegatedCallToThis(),
constructedTypeRef = delegatedTypeRef,
) {
delegationCall.convert(delegatedTypeRef)
}
}
this@PsiRawFirBuilder.context.firFunctionTargets += target
extractAnnotationsTo(this)
@@ -286,6 +286,7 @@ class RawFirBuilderTotalKotlinTestCase : AbstractRawFirBuilderTestCase() {
it.getStrictParentOfType<KtImportDirective>() != null ||
(it is KtPropertyAccessor && !it.hasBody()) ||
it is KtDestructuringDeclarationEntry && it.text == "_" ||
it is KtConstructorDelegationCall && it.text == "" ||
it is KtIfExpression && it.parent is KtContainerNodeForControlStructureBody && it.parent.parent is KtIfExpression ||
it is KtContextReceiverList ||
it is KtContextReceiver && it.parent is KtContextReceiverList && it.parent?.parent is KtFunctionType ||