diff --git a/analysis/low-level-api-fir/testdata/lazyResolve/expectClass.kt b/analysis/low-level-api-fir/testdata/lazyResolve/expectClass.kt new file mode 100644 index 00000000000..b32d3d4563d --- /dev/null +++ b/analysis/low-level-api-fir/testdata/lazyResolve/expectClass.kt @@ -0,0 +1 @@ +expect class Foo diff --git a/analysis/low-level-api-fir/testdata/lazyResolve/expectClass.txt b/analysis/low-level-api-fir/testdata/lazyResolve/expectClass.txt new file mode 100644 index 00000000000..e0ab4f4640d --- /dev/null +++ b/analysis/low-level-api-fir/testdata/lazyResolve/expectClass.txt @@ -0,0 +1,69 @@ +RAW_FIR: +FILE: [ResolvedTo(RAW_FIR)] expectClass.kt + public? final? expect [ResolvedTo(RAW_FIR)] class Foo : R|kotlin/Any| { + } + +IMPORTS: +FILE: [ResolvedTo(IMPORTS)] expectClass.kt + public? final? expect [ResolvedTo(RAW_FIR)] class Foo : R|kotlin/Any| { + } + +COMPILER_REQUIRED_ANNOTATIONS: +FILE: [ResolvedTo(IMPORTS)] expectClass.kt + public? final? expect [ResolvedTo(COMPILER_REQUIRED_ANNOTATIONS)] class Foo : R|kotlin/Any| { + } + +COMPANION_GENERATION: +FILE: [ResolvedTo(IMPORTS)] expectClass.kt + public? final? expect [ResolvedTo(COMPANION_GENERATION)] class Foo : R|kotlin/Any| { + } + +SUPER_TYPES: +FILE: [ResolvedTo(IMPORTS)] expectClass.kt + public? final? expect [ResolvedTo(SUPER_TYPES)] class Foo : R|kotlin/Any| { + } + +TYPES: +FILE: [ResolvedTo(IMPORTS)] expectClass.kt + public? final? expect [ResolvedTo(TYPES)] class Foo : R|kotlin/Any| { + } + +STATUS: +FILE: [ResolvedTo(IMPORTS)] expectClass.kt + public final expect [ResolvedTo(STATUS)] class Foo : R|kotlin/Any| { + } + +EXPECT_ACTUAL_MATCHING: +FILE: [ResolvedTo(IMPORTS)] expectClass.kt + public final expect [ResolvedTo(EXPECT_ACTUAL_MATCHING)] class Foo : R|kotlin/Any| { + } + +ARGUMENTS_OF_ANNOTATIONS: +FILE: [ResolvedTo(IMPORTS)] expectClass.kt + public final expect [ResolvedTo(ARGUMENTS_OF_ANNOTATIONS)] class Foo : R|kotlin/Any| { + } + +CONTRACTS: +FILE: [ResolvedTo(IMPORTS)] expectClass.kt + public final expect [ResolvedTo(CONTRACTS)] class Foo : R|kotlin/Any| { + } + +IMPLICIT_TYPES_BODY_RESOLVE: +FILE: [ResolvedTo(IMPORTS)] expectClass.kt + public final expect [ResolvedTo(IMPLICIT_TYPES_BODY_RESOLVE)] class Foo : R|kotlin/Any| { + } + +ANNOTATIONS_ARGUMENTS_MAPPING: +FILE: [ResolvedTo(IMPORTS)] expectClass.kt + public final expect [ResolvedTo(ANNOTATIONS_ARGUMENTS_MAPPING)] class Foo : R|kotlin/Any| { + } + +BODY_RESOLVE: +FILE: [ResolvedTo(IMPORTS)] expectClass.kt + public final expect [ResolvedTo(BODY_RESOLVE)] class Foo : R|kotlin/Any| { + } + +FILE RAW TO BODY: +FILE: [ResolvedTo(BODY_RESOLVE)] expectClass.kt + public final expect [ResolvedTo(BODY_RESOLVE)] class Foo : R|kotlin/Any| { + } diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/FirOutOfContentRootLazyBodiesCalculatorTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/FirOutOfContentRootLazyBodiesCalculatorTestGenerated.java index c7dad842be6..4f4613e2a76 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/FirOutOfContentRootLazyBodiesCalculatorTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/FirOutOfContentRootLazyBodiesCalculatorTestGenerated.java @@ -147,6 +147,12 @@ public class FirOutOfContentRootLazyBodiesCalculatorTestGenerated extends Abstra runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectActual.kt"); } + @Test + @TestMetadata("expectClassesAndFunctions.kt") + public void testExpectClassesAndFunctions() throws Exception { + runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectClassesAndFunctions.kt"); + } + @Test @TestMetadata("external.kt") public void testExternal() throws Exception { diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/FirOutOfContentRootLazyDeclarationResolveTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/FirOutOfContentRootLazyDeclarationResolveTestGenerated.java index fe12e598fce..8f9dd0e20e5 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/FirOutOfContentRootLazyDeclarationResolveTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/FirOutOfContentRootLazyDeclarationResolveTestGenerated.java @@ -234,6 +234,12 @@ public class FirOutOfContentRootLazyDeclarationResolveTestGenerated extends Abst runTest("analysis/low-level-api-fir/testdata/lazyResolve/enumValues.kt"); } + @Test + @TestMetadata("expectClass.kt") + public void testExpectClass() throws Exception { + runTest("analysis/low-level-api-fir/testdata/lazyResolve/expectClass.kt"); + } + @Test @TestMetadata("fakeOverride.kt") public void testFakeOverride() throws Exception { diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/FirSourceLazyBodiesCalculatorTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/FirSourceLazyBodiesCalculatorTestGenerated.java index c8bad488433..da5b358f227 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/FirSourceLazyBodiesCalculatorTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/FirSourceLazyBodiesCalculatorTestGenerated.java @@ -147,6 +147,12 @@ public class FirSourceLazyBodiesCalculatorTestGenerated extends AbstractFirSourc runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectActual.kt"); } + @Test + @TestMetadata("expectClassesAndFunctions.kt") + public void testExpectClassesAndFunctions() throws Exception { + runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectClassesAndFunctions.kt"); + } + @Test @TestMetadata("external.kt") public void testExternal() throws Exception { diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/FirSourceLazyDeclarationResolveTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/FirSourceLazyDeclarationResolveTestGenerated.java index aca7e7d8603..f733e27087c 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/FirSourceLazyDeclarationResolveTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/FirSourceLazyDeclarationResolveTestGenerated.java @@ -234,6 +234,12 @@ public class FirSourceLazyDeclarationResolveTestGenerated extends AbstractFirSou runTest("analysis/low-level-api-fir/testdata/lazyResolve/enumValues.kt"); } + @Test + @TestMetadata("expectClass.kt") + public void testExpectClass() throws Exception { + runTest("analysis/low-level-api-fir/testdata/lazyResolve/expectClass.kt"); + } + @Test @TestMetadata("fakeOverride.kt") public void testFakeOverride() throws Exception { diff --git a/compiler/fir/raw-fir/light-tree2fir/tests-gen/org/jetbrains/kotlin/fir/lightTree/LightTree2FirConverterTestCaseGenerated.java b/compiler/fir/raw-fir/light-tree2fir/tests-gen/org/jetbrains/kotlin/fir/lightTree/LightTree2FirConverterTestCaseGenerated.java index 70bff2bd223..f7da6c05bba 100644 --- a/compiler/fir/raw-fir/light-tree2fir/tests-gen/org/jetbrains/kotlin/fir/lightTree/LightTree2FirConverterTestCaseGenerated.java +++ b/compiler/fir/raw-fir/light-tree2fir/tests-gen/org/jetbrains/kotlin/fir/lightTree/LightTree2FirConverterTestCaseGenerated.java @@ -136,6 +136,11 @@ public class LightTree2FirConverterTestCaseGenerated extends AbstractLightTree2F runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectActual.kt"); } + @TestMetadata("expectClassesAndFunctions.kt") + public void testExpectClassesAndFunctions() throws Exception { + runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectClassesAndFunctions.kt"); + } + @TestMetadata("external.kt") public void testExternal() throws Exception { runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/external.kt"); 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 949308f1466..de554b2f404 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 @@ -49,6 +49,7 @@ import org.jetbrains.kotlin.types.expressions.OperatorConventions import org.jetbrains.kotlin.util.OperatorNameConventions import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull import org.jetbrains.kotlin.utils.addToStdlib.runIf +import org.jetbrains.kotlin.utils.addToStdlib.runUnless import org.jetbrains.kotlin.utils.addToStdlib.shouldNotBeCalled import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment import org.jetbrains.kotlin.utils.exceptions.requireWithAttachment @@ -1033,34 +1034,34 @@ open class PsiRawFirBuilder( ?: owner.toKtPsiSourceElement(KtFakeSourceElementKind.ImplicitConstructor) fun buildDelegatedCall(superTypeCallEntry: KtSuperTypeCallEntry?, delegatedTypeRef: FirTypeRef): FirDelegatedConstructorCall? { val constructorCall = superTypeCallEntry?.toFirSourceElement() - return if (containingClassIsExpectClass) null else { - val constructedTypeRef = if (copyConstructedTypeRefWithImplicitSource) { - delegatedTypeRef.copyWithNewSourceKind(KtFakeSourceElementKind.ImplicitTypeRef) - } else { - delegatedTypeRef - } - buildOrLazyDelegatedConstructorCall(isThis = false, constructedTypeRef) { - buildDelegatedConstructorCall { - source = constructorCall ?: constructorSource.fakeElement(KtFakeSourceElementKind.DelegatingConstructorCall) - this.constructedTypeRef = constructedTypeRef - isThis = false - calleeReference = buildExplicitSuperReference { - source = - superTypeCallEntry?.calleeExpression?.toFirSourceElement(KtFakeSourceElementKind.DelegatingConstructorCall) - ?: this@buildDelegatedConstructorCall.source?.fakeElement(KtFakeSourceElementKind.DelegatingConstructorCall) - superTypeRef = this@buildDelegatedConstructorCall.constructedTypeRef - } - superTypeCallEntry?.extractArgumentsTo(this) + val constructedTypeRef = if (copyConstructedTypeRefWithImplicitSource) { + delegatedTypeRef.copyWithNewSourceKind(KtFakeSourceElementKind.ImplicitTypeRef) + } else { + delegatedTypeRef + } + return buildOrLazyDelegatedConstructorCall(isThis = false, constructedTypeRef) { + buildDelegatedConstructorCall { + source = constructorCall ?: constructorSource.fakeElement(KtFakeSourceElementKind.DelegatingConstructorCall) + this.constructedTypeRef = constructedTypeRef + isThis = false + calleeReference = buildExplicitSuperReference { + source = + superTypeCallEntry?.calleeExpression?.toFirSourceElement(KtFakeSourceElementKind.DelegatingConstructorCall) + ?: this@buildDelegatedConstructorCall.source?.fakeElement(KtFakeSourceElementKind.DelegatingConstructorCall) + superTypeRef = this@buildDelegatedConstructorCall.constructedTypeRef } + superTypeCallEntry?.extractArgumentsTo(this) } } } - val firDelegatedCall = if (allSuperTypeCallEntries.size <= 1 ) { - buildDelegatedCall(superTypeCallEntry, delegatedSuperTypeRef!!) - } else { - buildMultiDelegatedConstructorCall { - allSuperTypeCallEntries.mapTo(delegatedConstructorCalls) { (superTypeCallEntry, delegatedTypeRef) -> - buildDelegatedCall(superTypeCallEntry, delegatedTypeRef)!! + val firDelegatedCall = runUnless(containingClassIsExpectClass) { + if (allSuperTypeCallEntries.size <= 1) { + buildDelegatedCall(superTypeCallEntry, delegatedSuperTypeRef!!) + } else { + buildMultiDelegatedConstructorCall { + allSuperTypeCallEntries.mapTo(delegatedConstructorCalls) { (superTypeCallEntry, delegatedTypeRef) -> + buildDelegatedCall(superTypeCallEntry, delegatedTypeRef)!! + } } } } diff --git a/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectClassesAndFunctions.kt b/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectClassesAndFunctions.kt new file mode 100644 index 00000000000..efb177207e1 --- /dev/null +++ b/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectClassesAndFunctions.kt @@ -0,0 +1,13 @@ +expect class A + +open class B + +open class C + +expect class D: B() + +expect class E: B(), C() + +expect fun f() + +expect annotation class G \ No newline at end of file diff --git a/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectClassesAndFunctions.lazyBodies.txt b/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectClassesAndFunctions.lazyBodies.txt new file mode 100644 index 00000000000..a584fb30051 --- /dev/null +++ b/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectClassesAndFunctions.lazyBodies.txt @@ -0,0 +1,26 @@ +FILE: expectClassesAndFunctions.kt + public? final? expect class A : R|kotlin/Any| { + } + public? open class B : R|kotlin/Any| { + public? constructor(): R|B| { + LAZY_super + } + + } + public? open class C : R|kotlin/Any| { + public? constructor(): R|C| { + LAZY_super + } + + } + public? final? expect class D : B { + public? expect error_constructor(): R|D| + + } + public? final? expect class E : B, C { + public? expect error_constructor(): R|E| + + } + public? final? expect fun f(): R|kotlin/Unit| + public? final? expect annotation class G : R|kotlin/Annotation| { + } diff --git a/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectClassesAndFunctions.txt b/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectClassesAndFunctions.txt new file mode 100644 index 00000000000..56370148d5e --- /dev/null +++ b/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectClassesAndFunctions.txt @@ -0,0 +1,26 @@ +FILE: expectClassesAndFunctions.kt + public? final? expect class A : R|kotlin/Any| { + } + public? open class B : R|kotlin/Any| { + public? [ContainingClassKey=B] constructor(): R|B| { + super() + } + + } + public? open class C : R|kotlin/Any| { + public? [ContainingClassKey=C] constructor(): R|C| { + super() + } + + } + public? final? expect class D : B { + public? expect [ContainingClassKey=D] error_constructor(): R|D| + + } + public? final? expect class E : B, C { + public? expect [ContainingClassKey=E] error_constructor(): R|E| + + } + public? final? expect fun f(): R|kotlin/Unit| + public? final? expect annotation class G : R|kotlin/Annotation| { + } diff --git a/compiler/fir/raw-fir/psi2fir/tests-gen/org/jetbrains/kotlin/fir/builder/RawFirBuilderLazyBodiesTestCaseGenerated.java b/compiler/fir/raw-fir/psi2fir/tests-gen/org/jetbrains/kotlin/fir/builder/RawFirBuilderLazyBodiesTestCaseGenerated.java index d92706b8508..39731294f5e 100644 --- a/compiler/fir/raw-fir/psi2fir/tests-gen/org/jetbrains/kotlin/fir/builder/RawFirBuilderLazyBodiesTestCaseGenerated.java +++ b/compiler/fir/raw-fir/psi2fir/tests-gen/org/jetbrains/kotlin/fir/builder/RawFirBuilderLazyBodiesTestCaseGenerated.java @@ -136,6 +136,11 @@ public class RawFirBuilderLazyBodiesTestCaseGenerated extends AbstractRawFirBuil runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectActual.kt"); } + @TestMetadata("expectClassesAndFunctions.kt") + public void testExpectClassesAndFunctions() throws Exception { + runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectClassesAndFunctions.kt"); + } + @TestMetadata("external.kt") public void testExternal() throws Exception { runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/external.kt"); diff --git a/compiler/fir/raw-fir/psi2fir/tests-gen/org/jetbrains/kotlin/fir/builder/RawFirBuilderTestCaseGenerated.java b/compiler/fir/raw-fir/psi2fir/tests-gen/org/jetbrains/kotlin/fir/builder/RawFirBuilderTestCaseGenerated.java index 6b0031ee979..a8fc1a39603 100644 --- a/compiler/fir/raw-fir/psi2fir/tests-gen/org/jetbrains/kotlin/fir/builder/RawFirBuilderTestCaseGenerated.java +++ b/compiler/fir/raw-fir/psi2fir/tests-gen/org/jetbrains/kotlin/fir/builder/RawFirBuilderTestCaseGenerated.java @@ -136,6 +136,11 @@ public class RawFirBuilderTestCaseGenerated extends AbstractRawFirBuilderTestCas runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectActual.kt"); } + @TestMetadata("expectClassesAndFunctions.kt") + public void testExpectClassesAndFunctions() throws Exception { + runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectClassesAndFunctions.kt"); + } + @TestMetadata("external.kt") public void testExternal() throws Exception { runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/external.kt"); diff --git a/compiler/visualizer/tests-gen/org/jetbrains/kotlin/visualizer/fir/FirVisualizerForRawFirDataGenerated.java b/compiler/visualizer/tests-gen/org/jetbrains/kotlin/visualizer/fir/FirVisualizerForRawFirDataGenerated.java index b205bd5c655..223c82a227a 100644 --- a/compiler/visualizer/tests-gen/org/jetbrains/kotlin/visualizer/fir/FirVisualizerForRawFirDataGenerated.java +++ b/compiler/visualizer/tests-gen/org/jetbrains/kotlin/visualizer/fir/FirVisualizerForRawFirDataGenerated.java @@ -147,6 +147,12 @@ public class FirVisualizerForRawFirDataGenerated extends AbstractFirVisualizerTe runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectActual.kt"); } + @Test + @TestMetadata("expectClassesAndFunctions.kt") + public void testExpectClassesAndFunctions() throws Exception { + runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectClassesAndFunctions.kt"); + } + @Test @TestMetadata("external.kt") public void testExternal() throws Exception { diff --git a/compiler/visualizer/tests-gen/org/jetbrains/kotlin/visualizer/psi/PsiVisualizerForRawFirDataGenerated.java b/compiler/visualizer/tests-gen/org/jetbrains/kotlin/visualizer/psi/PsiVisualizerForRawFirDataGenerated.java index 5012ff1136d..008bec2f42a 100644 --- a/compiler/visualizer/tests-gen/org/jetbrains/kotlin/visualizer/psi/PsiVisualizerForRawFirDataGenerated.java +++ b/compiler/visualizer/tests-gen/org/jetbrains/kotlin/visualizer/psi/PsiVisualizerForRawFirDataGenerated.java @@ -147,6 +147,12 @@ public class PsiVisualizerForRawFirDataGenerated extends AbstractPsiVisualizerTe runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectActual.kt"); } + @Test + @TestMetadata("expectClassesAndFunctions.kt") + public void testExpectClassesAndFunctions() throws Exception { + runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectClassesAndFunctions.kt"); + } + @Test @TestMetadata("external.kt") public void testExternal() throws Exception {