[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:
committed by
Space Team
parent
9a598026c8
commit
4b8b7aaa54
+4
-1
@@ -1161,7 +1161,7 @@ class LightTreeRawFirDeclarationBuilder(
|
|||||||
private fun convertConstructorDelegationCall(
|
private fun convertConstructorDelegationCall(
|
||||||
constructorDelegationCall: LighterASTNode,
|
constructorDelegationCall: LighterASTNode,
|
||||||
classWrapper: ClassWrapper
|
classWrapper: ClassWrapper
|
||||||
): FirDelegatedConstructorCall {
|
): FirDelegatedConstructorCall? {
|
||||||
var thisKeywordPresent = false
|
var thisKeywordPresent = false
|
||||||
val firValueArguments = mutableListOf<FirExpression>()
|
val firValueArguments = mutableListOf<FirExpression>()
|
||||||
constructorDelegationCall.forEachChildren {
|
constructorDelegationCall.forEachChildren {
|
||||||
@@ -1172,6 +1172,9 @@ class LightTreeRawFirDeclarationBuilder(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val isImplicit = constructorDelegationCall.textLength == 0
|
val isImplicit = constructorDelegationCall.textLength == 0
|
||||||
|
if (isImplicit && classWrapper.modifiers.hasExternal()) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
val isThis = thisKeywordPresent //|| (isImplicit && classWrapper.hasPrimaryConstructor)
|
val isThis = thisKeywordPresent //|| (isImplicit && classWrapper.hasPrimaryConstructor)
|
||||||
val delegatedType =
|
val delegatedType =
|
||||||
when {
|
when {
|
||||||
|
|||||||
+1
-1
@@ -16,7 +16,7 @@ import org.jetbrains.kotlin.fir.lightTree.fir.modifier.Modifier
|
|||||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||||
|
|
||||||
class ClassWrapper(
|
class ClassWrapper(
|
||||||
private val modifiers: Modifier,
|
val modifiers: Modifier,
|
||||||
private val classKind: ClassKind,
|
private val classKind: ClassKind,
|
||||||
val classBuilder: FirClassBuilder,
|
val classBuilder: FirClassBuilder,
|
||||||
val hasSecondaryConstructor: Boolean,
|
val hasSecondaryConstructor: Boolean,
|
||||||
|
|||||||
+9
-5
@@ -1988,11 +1988,15 @@ open class PsiRawFirBuilder(
|
|||||||
}
|
}
|
||||||
dispatchReceiverType = owner.obtainDispatchReceiverForConstructor()
|
dispatchReceiverType = owner.obtainDispatchReceiverForConstructor()
|
||||||
contextReceivers.addAll(convertContextReceivers(owner.contextReceivers))
|
contextReceivers.addAll(convertContextReceivers(owner.contextReceivers))
|
||||||
delegatedConstructor = buildOrLazyDelegatedConstructorCall(
|
val delegationCall = getDelegationCall()
|
||||||
isThis = isDelegatedCallToThis(),
|
val hasExplicitDelegationCall = delegationCall.textLength > 0
|
||||||
constructedTypeRef = delegatedTypeRef,
|
if (!owner.hasModifier(EXTERNAL_KEYWORD) || hasExplicitDelegationCall) {
|
||||||
) {
|
delegatedConstructor = buildOrLazyDelegatedConstructorCall(
|
||||||
getDelegationCall().convert(delegatedTypeRef)
|
isThis = isDelegatedCallToThis(),
|
||||||
|
constructedTypeRef = delegatedTypeRef,
|
||||||
|
) {
|
||||||
|
delegationCall.convert(delegatedTypeRef)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this@PsiRawFirBuilder.context.firFunctionTargets += target
|
this@PsiRawFirBuilder.context.firFunctionTargets += target
|
||||||
extractAnnotationsTo(this)
|
extractAnnotationsTo(this)
|
||||||
|
|||||||
+1
@@ -286,6 +286,7 @@ class RawFirBuilderTotalKotlinTestCase : AbstractRawFirBuilderTestCase() {
|
|||||||
it.getStrictParentOfType<KtImportDirective>() != null ||
|
it.getStrictParentOfType<KtImportDirective>() != null ||
|
||||||
(it is KtPropertyAccessor && !it.hasBody()) ||
|
(it is KtPropertyAccessor && !it.hasBody()) ||
|
||||||
it is KtDestructuringDeclarationEntry && it.text == "_" ||
|
it is KtDestructuringDeclarationEntry && it.text == "_" ||
|
||||||
|
it is KtConstructorDelegationCall && it.text == "" ||
|
||||||
it is KtIfExpression && it.parent is KtContainerNodeForControlStructureBody && it.parent.parent is KtIfExpression ||
|
it is KtIfExpression && it.parent is KtContainerNodeForControlStructureBody && it.parent.parent is KtIfExpression ||
|
||||||
it is KtContextReceiverList ||
|
it is KtContextReceiverList ||
|
||||||
it is KtContextReceiver && it.parent is KtContextReceiverList && it.parent?.parent is KtFunctionType ||
|
it is KtContextReceiver && it.parent is KtContextReceiverList && it.parent?.parent is KtFunctionType ||
|
||||||
|
|||||||
Reference in New Issue
Block a user