diff --git a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/LightTreeRawFirDeclarationBuilder.kt b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/LightTreeRawFirDeclarationBuilder.kt index 664a50e4478..437f6d8bf7e 100644 --- a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/LightTreeRawFirDeclarationBuilder.kt +++ b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/LightTreeRawFirDeclarationBuilder.kt @@ -1161,7 +1161,7 @@ class LightTreeRawFirDeclarationBuilder( private fun convertConstructorDelegationCall( constructorDelegationCall: LighterASTNode, classWrapper: ClassWrapper - ): FirDelegatedConstructorCall { + ): FirDelegatedConstructorCall? { var thisKeywordPresent = false val firValueArguments = mutableListOf() 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 { diff --git a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/fir/ClassWrapper.kt b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/fir/ClassWrapper.kt index 06f32ddebb6..596f1a5b0fd 100644 --- a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/fir/ClassWrapper.kt +++ b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/fir/ClassWrapper.kt @@ -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, diff --git a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/PsiRawFirBuilder.kt b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/PsiRawFirBuilder.kt index 2abdcc0c02e..bb249911cb1 100644 --- a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/PsiRawFirBuilder.kt +++ b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/PsiRawFirBuilder.kt @@ -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) diff --git a/compiler/fir/raw-fir/psi2fir/tests/org/jetbrains/kotlin/fir/builder/RawFirBuilderTotalKotlinTestCase.kt b/compiler/fir/raw-fir/psi2fir/tests/org/jetbrains/kotlin/fir/builder/RawFirBuilderTotalKotlinTestCase.kt index b12eb91afac..da8d28b3b2f 100644 --- a/compiler/fir/raw-fir/psi2fir/tests/org/jetbrains/kotlin/fir/builder/RawFirBuilderTotalKotlinTestCase.kt +++ b/compiler/fir/raw-fir/psi2fir/tests/org/jetbrains/kotlin/fir/builder/RawFirBuilderTotalKotlinTestCase.kt @@ -286,6 +286,7 @@ class RawFirBuilderTotalKotlinTestCase : AbstractRawFirBuilderTestCase() { it.getStrictParentOfType() != 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 ||