From 457fb09e3ade61b4936b82023f85be772883cee5 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Fri, 10 Apr 2020 18:29:14 +0300 Subject: [PATCH] [FIR] Use tower to resolve delegated constructors, set dispatch receiver --- .../testData/resolve/objectInnerClass.txt | 6 +-- .../problems/objectDerivedFromInnerClass.kt | 4 ++ .../problems/objectDerivedFromInnerClass.txt | 23 +++++++++++ .../testData/resolve/typeParameterVsNested.kt | 2 +- .../resolve/visibility/exposedSupertype.kt | 8 ++-- .../j+k/outerInnerClasses.txt | 2 +- .../fir/FirDiagnosticsTestGenerated.java | 5 +++ ...DiagnosticsWithLightTreeTestGenerated.java | 5 +++ .../generators/ClassMemberGenerator.kt | 5 +++ .../jetbrains/kotlin/fir/FirCallResolver.kt | 40 ++++++++++--------- .../kotlin/fir/resolve/calls/CallKind.kt | 1 + .../resolve/calls/ConstructorProcessing.kt | 23 ++++++++++- .../fir/resolve/calls/TypeArgumentMapping.kt | 2 +- .../resolve/calls/tower/FirTowerResolver.kt | 16 ++++++++ .../calls/tower/FirTowerResolverSession.kt | 25 ++++++++++++ .../resolve/calls/tower/TowerLevelHandler.kt | 9 +++++ .../fir/resolve/calls/tower/TowerLevels.kt | 39 +++++++++++++++--- .../FirExpressionsResolveTransformer.kt | 9 ++++- .../FirDelegatedConstructorCall.kt | 3 ++ .../FirDelegatedConstructorCallBuilder.kt | 4 ++ .../impl/FirDelegatedConstructorCallImpl.kt | 7 ++++ .../org/jetbrains/kotlin/fir/FirRenderer.kt | 5 +++ .../fir/tree/generator/BuilderConfigurator.kt | 2 + .../fir/tree/generator/NodeConfigurator.kt | 1 + .../box/classes/inheritedInnerClass.kt | 1 - .../codegen/box/classes/inner/kt6708.kt | 1 - .../box/classes/propertyInInitializer.kt | 1 - .../captureInSuperConstructorCall/kt14148.kt | 1 - .../codegen/box/innerNested/innerJavaClass.kt | 1 - .../box/innerNested/passingOuterRef.kt | 1 - .../deepInnerHierarchy.kt | 1 - ...innerExtendsInnerViaSecondaryConstuctor.kt | 1 - ...innerExtendsInnerWithProperOuterCapture.kt | 1 - .../superConstructorCall/kt11833_1.kt | 1 - .../superConstructorCall/kt11833_2.kt | 1 - .../localClassOuterDiffersFromInnerOuter.kt | 1 - .../superConstructorCall/localExtendsInner.kt | 1 - .../objectExtendsInner.kt | 1 - .../objectExtendsInnerDefaultArgument.kt | 1 - .../objectOuterDiffersFromInnerOuter.kt | 1 - ...calExtendsInnerAndReferencesOuterMember.kt | 1 - .../subclassingExtensionReceiverClass.kt | 1 - ...ectExtendsInnerAndReferencesOuterMember.kt | 1 - ...erClassTypeAliasConstructorInSupertypes.kt | 1 - .../inference/knownTypeParameters.fir.kt | 30 -------------- .../tests/inference/knownTypeParameters.kt | 1 + .../tests/inference/kt32415.fir.kt | 9 ----- .../diagnostics/tests/inference/kt32415.kt | 1 + .../inner/classesInClassObjectHeader.fir.kt | 2 +- .../inner/innerErrorForClassObjects.fir.kt | 4 +- .../tests/inner/innerErrorForObjects.fir.kt | 4 +- .../diagnostics/tests/inner/modality.fir.kt | 2 +- .../nestedExtendsInner.fir.kt | 2 +- .../ir/irText/classes/innerClass.fir.txt | 1 + ...nnerClassWithDelegatingConstructor.fir.txt | 1 + .../classes/objectLiteralExpressions.fir.txt | 2 + .../parameters/constructor.fir.txt | 1 + .../ir/irText/expressions/kt16905.fir.txt | 2 + .../multipleThisReferences.fir.txt | 1 + .../thisOfGenericOuterClass.fir.txt | 3 +- 60 files changed, 226 insertions(+), 106 deletions(-) create mode 100644 compiler/fir/analysis-tests/testData/resolve/problems/objectDerivedFromInnerClass.kt create mode 100644 compiler/fir/analysis-tests/testData/resolve/problems/objectDerivedFromInnerClass.txt delete mode 100644 compiler/testData/diagnostics/tests/inference/knownTypeParameters.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/inference/kt32415.fir.kt diff --git a/compiler/fir/analysis-tests/testData/resolve/objectInnerClass.txt b/compiler/fir/analysis-tests/testData/resolve/objectInnerClass.txt index 557e1ab8051..1a136fe2e1c 100644 --- a/compiler/fir/analysis-tests/testData/resolve/objectInnerClass.txt +++ b/compiler/fir/analysis-tests/testData/resolve/objectInnerClass.txt @@ -6,7 +6,7 @@ FILE: objectInnerClass.kt local final inner class Child : R|.Base| { public[local] constructor(property: R|B|): R|.Child| { - super.Base|>(R|/property|) + this@R|/anonymous|.super.Base|>(R|/property|) } public[local] final fun R|.Base|.zoo(): R|kotlin/Unit| { @@ -69,7 +69,7 @@ FILE: objectInnerClass.kt public final val x: R|anonymous| = object : R|Case2.Base| { private constructor(): R|anonymous| { - super(R|/B.B|()) + this@R|/Case2|.super(R|/B.B|()) } public[local] final fun R|Case2.Base|.zoo(): R|kotlin/Unit| { @@ -131,7 +131,7 @@ FILE: objectInnerClass.kt local final inner class Child : R|Case3..Base| { public[local] constructor(property: R|B|): R|Case3..Child| { - super.Base|>(R|/property|) + this@R|/anonymous|.super.Base|>(R|/property|) } public[local] final fun R|Case3..Base|.zoo(): R|kotlin/Unit| { diff --git a/compiler/fir/analysis-tests/testData/resolve/problems/objectDerivedFromInnerClass.kt b/compiler/fir/analysis-tests/testData/resolve/problems/objectDerivedFromInnerClass.kt new file mode 100644 index 00000000000..b44d753dd3d --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/problems/objectDerivedFromInnerClass.kt @@ -0,0 +1,4 @@ +class Outer { inner class Inner } +fun test() { + val x = object : Outer.Inner() { } +} \ No newline at end of file diff --git a/compiler/fir/analysis-tests/testData/resolve/problems/objectDerivedFromInnerClass.txt b/compiler/fir/analysis-tests/testData/resolve/problems/objectDerivedFromInnerClass.txt new file mode 100644 index 00000000000..e3213380d90 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/problems/objectDerivedFromInnerClass.txt @@ -0,0 +1,23 @@ +FILE: objectDerivedFromInnerClass.kt + public final class Outer : R|kotlin/Any| { + public constructor(): R|Outer| { + super() + } + + public final inner class Inner : R|kotlin/Any| { + public constructor(): R|Outer.Inner| { + super() + } + + } + + } + public final fun test(): R|kotlin/Unit| { + lval x: R|anonymous| = object : R|Outer.Inner| { + private constructor(): R|anonymous| { + super() + } + + } + + } diff --git a/compiler/fir/analysis-tests/testData/resolve/typeParameterVsNested.kt b/compiler/fir/analysis-tests/testData/resolve/typeParameterVsNested.kt index 25c88871657..d9e6671eed0 100644 --- a/compiler/fir/analysis-tests/testData/resolve/typeParameterVsNested.kt +++ b/compiler/fir/analysis-tests/testData/resolve/typeParameterVsNested.kt @@ -13,7 +13,7 @@ abstract class My { abstract val z: test.My.T - class Some : T() + class Some : T() } abstract class Your : T \ No newline at end of file diff --git a/compiler/fir/analysis-tests/testData/resolve/visibility/exposedSupertype.kt b/compiler/fir/analysis-tests/testData/resolve/visibility/exposedSupertype.kt index 3f66bd385d7..eb440294fcc 100644 --- a/compiler/fir/analysis-tests/testData/resolve/visibility/exposedSupertype.kt +++ b/compiler/fir/analysis-tests/testData/resolve/visibility/exposedSupertype.kt @@ -38,9 +38,9 @@ interface E { } -class Test2 : A.APublicI, B.BInner { +class Test2 : A.APublicI, B.BInner { -} +} class Test3 : C.CPublicI, C { @@ -50,9 +50,9 @@ class Test4 : E, A.AProtectedI { } -class Test5 : C.CPublicI, B.BInner { +class Test5 : C.CPublicI, B.BInner { -} +} class Test6 : E, C.CPublic { diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/outerInnerClasses.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/outerInnerClasses.txt index 9d60095acb0..0317b209b38 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/outerInnerClasses.txt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/outerInnerClasses.txt @@ -31,7 +31,7 @@ FILE: K2.kt public final inner class K3 : R|J1.J2| { public constructor(): R|K2.K3| { - super() + this@R|/K2|.super() } public final fun main(): R|kotlin/Unit| { diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java index a0bc0af39e2..26fdb2382da 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java @@ -1664,6 +1664,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest { runTest("compiler/fir/analysis-tests/testData/resolve/problems/multipleJavaClassesInOneFile.kt"); } + @TestMetadata("objectDerivedFromInnerClass.kt") + public void testObjectDerivedFromInnerClass() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/problems/objectDerivedFromInnerClass.kt"); + } + @TestMetadata("safeCallInvoke.kt") public void testSafeCallInvoke() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/problems/safeCallInvoke.kt"); diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java index c1600d4525f..c40bb7fb609 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java @@ -1664,6 +1664,11 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos runTest("compiler/fir/analysis-tests/testData/resolve/problems/multipleJavaClassesInOneFile.kt"); } + @TestMetadata("objectDerivedFromInnerClass.kt") + public void testObjectDerivedFromInnerClass() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/problems/objectDerivedFromInnerClass.kt"); + } + @TestMetadata("safeCallInvoke.kt") public void testSafeCallInvoke() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/problems/safeCallInvoke.kt"); diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/ClassMemberGenerator.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/ClassMemberGenerator.kt index 3cbc34820ac..06633331beb 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/ClassMemberGenerator.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/ClassMemberGenerator.kt @@ -12,6 +12,7 @@ import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyGetter import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertySetter import org.jetbrains.kotlin.fir.expressions.FirDelegatedConstructorCall import org.jetbrains.kotlin.fir.expressions.FirExpression +import org.jetbrains.kotlin.fir.expressions.impl.FirNoReceiverExpression import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference import org.jetbrains.kotlin.fir.symbols.impl.FirConstructorSymbol import org.jetbrains.kotlin.fir.types.* @@ -247,6 +248,7 @@ internal class ClassMemberGenerator( startOffset, endOffset, constructedIrType, "Cannot find delegated constructor call" ) } + val firDispatchReceiver = dispatchReceiver return convertWithOffsets { startOffset, endOffset -> val irConstructorSymbol = declarationStorage.getIrFunctionSymbol(constructorSymbol) as IrConstructorSymbol if (constructorSymbol.fir.isFromEnumClass || constructorSymbol.fir.returnTypeRef.isEnum) { @@ -268,6 +270,9 @@ internal class ClassMemberGenerator( irConstructorSymbol ) }.let { + if (firDispatchReceiver !is FirNoReceiverExpression) { + it.dispatchReceiver = visitor.convertToIrExpression(firDispatchReceiver) + } with(callGenerator) { it.applyCallArguments(this@toIrDelegatingConstructorCall) } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirCallResolver.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirCallResolver.kt index 09f48768786..1ced7a74fdc 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirCallResolver.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirCallResolver.kt @@ -6,6 +6,7 @@ package org.jetbrains.kotlin.fir import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration +import org.jetbrains.kotlin.fir.declarations.isInner import org.jetbrains.kotlin.fir.expressions.* import org.jetbrains.kotlin.fir.expressions.builder.buildExpressionStub import org.jetbrains.kotlin.fir.expressions.builder.buildResolvedReifiedParameterReference @@ -20,7 +21,6 @@ import org.jetbrains.kotlin.fir.references.impl.FirSimpleNamedReference import org.jetbrains.kotlin.fir.resolve.* import org.jetbrains.kotlin.fir.resolve.calls.* import org.jetbrains.kotlin.fir.resolve.calls.tower.FirTowerResolver -import org.jetbrains.kotlin.fir.resolve.calls.tower.TowerGroup import org.jetbrains.kotlin.fir.resolve.calls.tower.TowerResolveManager import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeAmbiguityError import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeInapplicableCandidateError @@ -32,14 +32,12 @@ import org.jetbrains.kotlin.fir.resolve.transformers.StoreReceiver import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirExpressionsResolveTransformer import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.resultType import org.jetbrains.kotlin.fir.resolve.transformers.phasedFir -import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope import org.jetbrains.kotlin.fir.symbols.impl.* import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder import org.jetbrains.kotlin.resolve.calls.results.TypeSpecificityComparator -import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind class FirCallResolver( private val components: BodyResolveComponents, @@ -269,14 +267,13 @@ class FirCallResolver( fun resolveDelegatingConstructorCall( delegatedConstructorCall: FirDelegatedConstructorCall, - symbol: FirClassSymbol<*>, + constructorClassSymbol: FirClassSymbol<*>, typeArguments: List, ): FirDelegatedConstructorCall? { - val scope = symbol.fir.unsubstitutedScope(session, scopeSession) - val className = symbol.classId.shortClassName + val name = Name.special("") val callInfo = CallInfo( CallKind.DelegatingConstructorCall, - className, + name, explicitReceiver = null, delegatedConstructorCall.argumentList, isSafeCall = false, @@ -286,22 +283,19 @@ class FirCallResolver( file, implicitReceiverStack, ) - val candidateFactory = CandidateFactory(this, callInfo) - val candidates = mutableListOf() + towerResolver.reset() + val result = towerResolver.runResolverForDelegatingConstructor( + implicitReceiverStack.receiversAsReversed(), + callInfo, + constructorClassSymbol, + ) - scope.processDeclaredConstructors { - val candidate = candidateFactory.createCandidate(it, ExplicitReceiverKind.NO_EXPLICIT_RECEIVER) - candidate.typeArgumentMapping = TypeArgumentMapping.Mapped(typeArguments) - candidates += candidate - } - return callResolver.selectDelegatingConstructorCall(delegatedConstructorCall, className, candidates) + return callResolver.selectDelegatingConstructorCall(delegatedConstructorCall, name, result) } private fun selectDelegatingConstructorCall( - call: FirDelegatedConstructorCall, name: Name, candidates: Collection, + call: FirDelegatedConstructorCall, name: Name, result: CandidateCollector, ): FirDelegatedConstructorCall { - val result = CandidateCollector(this, resolutionStageRunner) - candidates.forEach { result.consumeCandidate(TowerGroup.Start, it) } val bestCandidates = result.bestCandidates() val reducedCandidates = if (result.currentApplicability < CandidateApplicability.SYNTHETIC_RESOLVED) { bestCandidates.toSet() @@ -316,7 +310,15 @@ class FirCallResolver( result.currentApplicability, ) - return call.transformCalleeReference(StoreNameReference, nameReference) + return call.transformCalleeReference(StoreNameReference, nameReference).apply { + val singleCandidate = reducedCandidates.singleOrNull() + if (singleCandidate != null) { + val symbol = singleCandidate.symbol + if (symbol is FirConstructorSymbol && symbol.fir.isInner) { + transformDispatchReceiver(StoreReceiver, singleCandidate.dispatchReceiverExpression()) + } + } + } } private fun createCallableReferencesInfoForLHS( diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CallKind.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CallKind.kt index aba3d8abe0e..41357ccf21b 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CallKind.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CallKind.kt @@ -40,6 +40,7 @@ enum class CallKind(vararg resolutionSequence: ResolutionStage) { CheckVisibility, MapArguments, CheckExplicitReceiverConsistency, + MapTypeArguments, CreateFreshTypeVariableSubstitutorStage, CheckReceivers.Dispatch, CheckReceivers.Extension, diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConstructorProcessing.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConstructorProcessing.kt index b86746255d9..bfaba6277a8 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConstructorProcessing.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConstructorProcessing.kt @@ -28,10 +28,11 @@ import org.jetbrains.kotlin.utils.addToStdlib.safeAs private operator fun Pair?.component1() = this?.first private operator fun Pair<*, T>?.component2() = this?.second -internal fun FirScope.processFunctionsAndConstructorsByName( +internal fun FirScope.processConstructorsByName( name: Name, session: FirSession, bodyResolveComponents: BodyResolveComponents, + noSyntheticConstructors: Boolean, noInnerConstructors: Boolean = false, processor: (FirCallableSymbol<*>) -> Unit ) { @@ -41,7 +42,6 @@ internal fun FirScope.processFunctionsAndConstructorsByName( val (matchedClassifierSymbol, substitutor) = classifierInfo val matchedClassSymbol = matchedClassifierSymbol as? FirClassLikeSymbol<*> - processConstructors( matchedClassSymbol, substitutor, @@ -51,12 +51,31 @@ internal fun FirScope.processFunctionsAndConstructorsByName( noInnerConstructors ) + if (noSyntheticConstructors) { + return + } + processSyntheticConstructors( matchedClassSymbol, processor, bodyResolveComponents ) } +} + +internal fun FirScope.processFunctionsAndConstructorsByName( + name: Name, + session: FirSession, + bodyResolveComponents: BodyResolveComponents, + noInnerConstructors: Boolean = false, + processor: (FirCallableSymbol<*>) -> Unit +) { + processConstructorsByName( + name, session, bodyResolveComponents, + noSyntheticConstructors = false, + noInnerConstructors = noInnerConstructors, + processor = processor + ) processFunctionsByName(name) { processor(it) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/TypeArgumentMapping.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/TypeArgumentMapping.kt index 1bc9346b37d..7a25d2eced7 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/TypeArgumentMapping.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/TypeArgumentMapping.kt @@ -36,7 +36,7 @@ internal object MapTypeArguments : ResolutionStage() { val owner = candidate.symbol.fir as FirTypeParameterRefsOwner - if (typeArguments.size == owner.typeParameters.size) { + if (typeArguments.size == owner.typeParameters.size || callInfo.callKind == CallKind.DelegatingConstructorCall) { candidate.typeArgumentMapping = TypeArgumentMapping.Mapped(typeArguments) } else { sink.yieldApplicability(CandidateApplicability.INAPPLICABLE) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirTowerResolver.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirTowerResolver.kt index da6f4427b35..6145a82100f 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirTowerResolver.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirTowerResolver.kt @@ -7,6 +7,8 @@ package org.jetbrains.kotlin.fir.resolve.calls.tower import org.jetbrains.kotlin.fir.resolve.BodyResolveComponents import org.jetbrains.kotlin.fir.resolve.calls.* +import org.jetbrains.kotlin.fir.scopes.FirScope +import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol class FirTowerResolver( private val components: BodyResolveComponents, @@ -30,6 +32,20 @@ class FirTowerResolver( return collector } + fun runResolverForDelegatingConstructor( + implicitReceiverValues: List>, + info: CallInfo, + constructorClassSymbol: FirClassSymbol<*>, + ): CandidateCollector { + val candidateFactoriesAndCollectors = buildCandidateFactoriesAndCollectors(info, collector) + + val towerResolverSession = FirTowerResolverSession(components, implicitReceiverValues, manager, candidateFactoriesAndCollectors) + towerResolverSession.runResolutionForDelegatingConstructor(info, constructorClassSymbol) + + manager.runTasks() + return collector + } + private fun buildCandidateFactoriesAndCollectors( info: CallInfo, collector: CandidateCollector diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirTowerResolverSession.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirTowerResolverSession.kt index fc996f612f8..5c8a17105a3 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirTowerResolverSession.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirTowerResolverSession.kt @@ -26,7 +26,9 @@ import org.jetbrains.kotlin.fir.scopes.ProcessorAction import org.jetbrains.kotlin.fir.scopes.impl.FirCompositeScope import org.jetbrains.kotlin.fir.scopes.impl.FirLocalScope import org.jetbrains.kotlin.fir.scopes.impl.FirStaticScope +import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol +import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.fir.types.impl.FirImplicitBuiltinTypeRef @@ -65,6 +67,10 @@ class FirTowerResolverSession internal constructor( else components.typeParametersScopes.asReversed() + components.fileImportsScope.asReversed() + fun runResolutionForDelegatingConstructor(info: CallInfo, constructorClassSymbol: FirClassSymbol<*>) { + manager.enqueueResolverTask { runResolverForDelegatingConstructorCall(info, constructorClassSymbol) } + } + fun runResolution(info: CallInfo) { when (val receiver = info.explicitReceiver) { is FirResolvedQualifier -> manager.enqueueResolverTask { runResolverForQualifierReceiver(info, receiver) } @@ -198,6 +204,25 @@ class FirTowerResolverSession internal constructor( } } + private suspend fun runResolverForDelegatingConstructorCall(info: CallInfo, constructorClassSymbol: FirClassSymbol<*>) { + val scope = constructorClassSymbol.fir.unsubstitutedScope(session, components.scopeSession) + // Search for non-inner constructors only + processLevel( + scope.toScopeTowerLevel(), + info, TowerGroup.Implicit(0) + ) + // Search for inner constructors only + if (constructorClassSymbol is FirRegularClassSymbol) { + // 1 because we search for inner constructor in outer class + implicitReceiversUsableAsValues.getOrNull(1)?.let { (implicitReceiverValue) -> + processLevel( + implicitReceiverValue.toMemberScopeTowerLevel(), + info.copy(name = constructorClassSymbol.fir.name), TowerGroup.Implicit(1) + ) + } + } + } + private suspend fun runResolverForNoReceiver( info: CallInfo ) { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/TowerLevelHandler.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/TowerLevelHandler.kt index b757d847415..fd474556a57 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/TowerLevelHandler.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/TowerLevelHandler.kt @@ -122,6 +122,9 @@ internal class TowerLevelHandler { towerLevel.processFunctionsAndProperties(info.name, processor) } } + CallKind.DelegatingConstructorCall -> { + towerLevel.processConstructors(info.name, processor) + } else -> { throw AssertionError("Unsupported call kind in tower resolver: ${info.callKind}") } @@ -150,6 +153,12 @@ internal class TowerLevelHandler { processProperties(name, processor) } + private fun TowerScopeLevel.processConstructors( + name: Name, processor: TowerScopeLevel.TowerScopeLevelProcessor> + ) { + processElementsByNameAndStoreResult(TowerScopeLevel.Token.Constructors, name, processor) + } + private fun TowerScopeLevel.processObjectsAsVariables( name: Name, processor: TowerScopeLevel.TowerScopeLevelProcessor> ) { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/TowerLevels.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/TowerLevels.kt index c2ab41122a7..6f2a2925a05 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/TowerLevels.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/TowerLevels.kt @@ -37,8 +37,8 @@ interface TowerScopeLevel { sealed class Token> { object Properties : Token>() - object Functions : Token>() + object Constructors : Token() object Objects : Token>() } @@ -82,6 +82,7 @@ class MemberScopeTowerLevel( ) : SessionBasedTowerLevel(session) { private fun > processMembers( output: TowerScopeLevel.TowerScopeLevelProcessor, + forInnerConstructors: Boolean = false, processScopeMembers: FirScope.(processor: (T) -> Unit) -> Unit ): ProcessorAction { var empty = true @@ -92,7 +93,11 @@ class MemberScopeTowerLevel( (implicitExtensionInvokeMode || candidate.hasConsistentExtensionReceiver(extensionReceiver)) ) { val fir = candidate.fir - if ((fir as? FirCallableMemberDeclaration<*>)?.isStatic == true || (fir as? FirConstructor)?.isInner == false) { + if (forInnerConstructors) { + if (candidate !is FirConstructorSymbol || !candidate.fir.isInner) { + return@processScopeMembers + } + } else if ((fir as? FirCallableMemberDeclaration<*>)?.isStatic == true || (fir as? FirConstructor)?.isInner == false) { return@processScopeMembers } val dispatchReceiverValue = NotNullableReceiverValue(dispatchReceiver) @@ -114,10 +119,12 @@ class MemberScopeTowerLevel( } } - val withSynthetic = FirSyntheticPropertiesScope(session, scope) - withSynthetic.processScopeMembers { symbol -> - empty = false - output.consumeCandidate(symbol, NotNullableReceiverValue(dispatchReceiver), extensionReceiver as? ImplicitReceiverValue<*>) + if (!forInnerConstructors) { + val withSynthetic = FirSyntheticPropertiesScope(session, scope) + withSynthetic.processScopeMembers { symbol -> + empty = false + output.consumeCandidate(symbol, NotNullableReceiverValue(dispatchReceiver), extensionReceiver as? ImplicitReceiverValue<*>) + } } return if (empty) ProcessorAction.NONE else ProcessorAction.NEXT } @@ -157,6 +164,17 @@ class MemberScopeTowerLevel( consumer(it as T) } } + TowerScopeLevel.Token.Constructors -> processMembers(processor, forInnerConstructors = true) { consumer -> + this.processConstructorsByName( + name, session, bodyResolveComponents, + noSyntheticConstructors = true, + noInnerConstructors = false, + processor = { + @Suppress("UNCHECKED_CAST") + consumer(it as T) + } + ) + } } } @@ -261,6 +279,15 @@ class ScopeTowerLevel( implicitExtensionReceiverValue = null ) } + TowerScopeLevel.Token.Constructors -> scope.processDeclaredConstructors { candidate -> + // NB: here we cannot resolve inner constructors, because they should have dispatch receiver + if (!candidate.fir.isInner) { + processor.consumeCandidate( + candidate as T, dispatchReceiverValue(scope, candidate), + implicitExtensionReceiverValue = null + ) + } + } } return if (empty) ProcessorAction.NONE else ProcessorAction.NEXT } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt index 63b83593784..fb88af6019e 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt @@ -644,7 +644,8 @@ class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransformer) : context.implicitReceiverStack.add(name, lastDispatchReceiver) } val typeArguments: List - val symbol: FirClassSymbol<*> = when (val reference = delegatedConstructorCall.calleeReference) { + val reference = delegatedConstructorCall.calleeReference + val symbol: FirClassSymbol<*> = when (reference) { is FirThisReference -> { typeArguments = emptyList() if (reference.boundSymbol == null) { @@ -674,7 +675,11 @@ class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransformer) : } val resolvedCall = callResolver.resolveDelegatingConstructorCall(delegatedConstructorCall, symbol, typeArguments) ?: return delegatedConstructorCall.compose() - + if (reference is FirThisReference && reference.boundSymbol == null) { + resolvedCall.dispatchReceiver.typeRef.coneTypeSafe()?.lookupTag?.toSymbol(session)?.let { + reference.replaceBoundSymbol(it) + } + } val completionResult = callCompleter.completeCall(resolvedCall, noExpectedType) result = completionResult.result diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/FirDelegatedConstructorCall.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/FirDelegatedConstructorCall.kt index ce098637464..ad9317b48bd 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/FirDelegatedConstructorCall.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/FirDelegatedConstructorCall.kt @@ -22,6 +22,7 @@ abstract class FirDelegatedConstructorCall : FirPureAbstractElement(), FirResolv abstract override val annotations: List abstract override val argumentList: FirArgumentList abstract val constructedTypeRef: FirTypeRef + abstract val dispatchReceiver: FirExpression abstract val isThis: Boolean abstract val isSuper: Boolean @@ -36,4 +37,6 @@ abstract class FirDelegatedConstructorCall : FirPureAbstractElement(), FirResolv abstract override fun transformCalleeReference(transformer: FirTransformer, data: D): FirDelegatedConstructorCall abstract override fun transformAnnotations(transformer: FirTransformer, data: D): FirDelegatedConstructorCall + + abstract fun transformDispatchReceiver(transformer: FirTransformer, data: D): FirDelegatedConstructorCall } diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/builder/FirDelegatedConstructorCallBuilder.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/builder/FirDelegatedConstructorCallBuilder.kt index 323bd09f401..62fd7eabeb7 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/builder/FirDelegatedConstructorCallBuilder.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/builder/FirDelegatedConstructorCallBuilder.kt @@ -13,8 +13,10 @@ import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall import org.jetbrains.kotlin.fir.expressions.FirArgumentList import org.jetbrains.kotlin.fir.expressions.FirDelegatedConstructorCall import org.jetbrains.kotlin.fir.expressions.FirEmptyArgumentList +import org.jetbrains.kotlin.fir.expressions.FirExpression import org.jetbrains.kotlin.fir.expressions.builder.FirCallBuilder import org.jetbrains.kotlin.fir.expressions.impl.FirDelegatedConstructorCallImpl +import org.jetbrains.kotlin.fir.expressions.impl.FirNoReceiverExpression import org.jetbrains.kotlin.fir.references.FirReference import org.jetbrains.kotlin.fir.references.impl.FirExplicitSuperReference import org.jetbrains.kotlin.fir.references.impl.FirExplicitThisReference @@ -32,6 +34,7 @@ class FirDelegatedConstructorCallBuilder : FirCallBuilder, FirAnnotationContaine override val annotations: MutableList = mutableListOf() override var argumentList: FirArgumentList = FirEmptyArgumentList lateinit var constructedTypeRef: FirTypeRef + var dispatchReceiver: FirExpression = FirNoReceiverExpression var isThis: Boolean by kotlin.properties.Delegates.notNull() override fun build(): FirDelegatedConstructorCall { @@ -40,6 +43,7 @@ class FirDelegatedConstructorCallBuilder : FirCallBuilder, FirAnnotationContaine annotations, argumentList, constructedTypeRef, + dispatchReceiver, isThis, ) } diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/impl/FirDelegatedConstructorCallImpl.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/impl/FirDelegatedConstructorCallImpl.kt index 1f6ec77e59e..d6bfd91dee3 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/impl/FirDelegatedConstructorCallImpl.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/impl/FirDelegatedConstructorCallImpl.kt @@ -9,6 +9,7 @@ import org.jetbrains.kotlin.fir.FirSourceElement import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall import org.jetbrains.kotlin.fir.expressions.FirArgumentList import org.jetbrains.kotlin.fir.expressions.FirDelegatedConstructorCall +import org.jetbrains.kotlin.fir.expressions.FirExpression import org.jetbrains.kotlin.fir.references.FirReference import org.jetbrains.kotlin.fir.references.impl.FirExplicitSuperReference import org.jetbrains.kotlin.fir.references.impl.FirExplicitThisReference @@ -25,6 +26,7 @@ internal class FirDelegatedConstructorCallImpl( override val annotations: MutableList, override var argumentList: FirArgumentList, override var constructedTypeRef: FirTypeRef, + override var dispatchReceiver: FirExpression, override val isThis: Boolean, ) : FirDelegatedConstructorCall() { override var calleeReference: FirReference = if (isThis) FirExplicitThisReference(source, null) else FirExplicitSuperReference(source, null, constructedTypeRef) @@ -55,6 +57,11 @@ internal class FirDelegatedConstructorCallImpl( return this } + override fun transformDispatchReceiver(transformer: FirTransformer, data: D): FirDelegatedConstructorCallImpl { + dispatchReceiver = dispatchReceiver.transformSingle(transformer, data) + return this + } + override fun replaceCalleeReference(newCalleeReference: FirReference) { calleeReference = newCalleeReference } diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirRenderer.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirRenderer.kt index 6bf915f9d37..cfb5de13e9f 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirRenderer.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirRenderer.kt @@ -763,6 +763,11 @@ class FirRenderer(builder: StringBuilder, private val mode: RenderMode = RenderM } override fun visitDelegatedConstructorCall(delegatedConstructorCall: FirDelegatedConstructorCall) { + val dispatchReceiver = delegatedConstructorCall.dispatchReceiver + if (dispatchReceiver !is FirNoReceiverExpression) { + dispatchReceiver.accept(this) + print(".") + } if (delegatedConstructorCall.isSuper) { print("super<") } else if (delegatedConstructorCall.isThis) { diff --git a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/BuilderConfigurator.kt b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/BuilderConfigurator.kt index d9b50127725..f2dfc650eba 100644 --- a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/BuilderConfigurator.kt +++ b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/BuilderConfigurator.kt @@ -152,6 +152,8 @@ object BuilderConfigurator : AbstractBuilderConfigurator(FirTree default("argumentList") { value = "FirEmptyArgumentList" } + default("dispatchReceiver", "FirNoReceiverExpression") + useTypes(noReceiverExpressionType) useTypes(emptyArgumentListType) } diff --git a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt index 477cdab0bce..7f3674dc652 100644 --- a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt +++ b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt @@ -348,6 +348,7 @@ object NodeConfigurator : AbstractFieldConfigurator(FirTreeBuild delegatedConstructorCall.configure { +field("constructedTypeRef", typeRef, withReplace = true) + +field("dispatchReceiver", expression).withTransform() generateBooleanFields("this", "super") } diff --git a/compiler/testData/codegen/box/classes/inheritedInnerClass.kt b/compiler/testData/codegen/box/classes/inheritedInnerClass.kt index 26719d2cfc6..82bd91e93cd 100644 --- a/compiler/testData/codegen/box/classes/inheritedInnerClass.kt +++ b/compiler/testData/codegen/box/classes/inheritedInnerClass.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR class Outer() { open inner class InnerBase() { } diff --git a/compiler/testData/codegen/box/classes/inner/kt6708.kt b/compiler/testData/codegen/box/classes/inner/kt6708.kt index 096b72f03b6..be556a42996 100644 --- a/compiler/testData/codegen/box/classes/inner/kt6708.kt +++ b/compiler/testData/codegen/box/classes/inner/kt6708.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR open class A() { open inner class InnerA } diff --git a/compiler/testData/codegen/box/classes/propertyInInitializer.kt b/compiler/testData/codegen/box/classes/propertyInInitializer.kt index af752d883ec..bd8aa833063 100644 --- a/compiler/testData/codegen/box/classes/propertyInInitializer.kt +++ b/compiler/testData/codegen/box/classes/propertyInInitializer.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR class Outer() { val s = "xyzzy" diff --git a/compiler/testData/codegen/box/closures/captureInSuperConstructorCall/kt14148.kt b/compiler/testData/codegen/box/closures/captureInSuperConstructorCall/kt14148.kt index 2d33470c4d1..ca3f5a95df5 100644 --- a/compiler/testData/codegen/box/closures/captureInSuperConstructorCall/kt14148.kt +++ b/compiler/testData/codegen/box/closures/captureInSuperConstructorCall/kt14148.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR interface Test { fun test(): String } diff --git a/compiler/testData/codegen/box/innerNested/innerJavaClass.kt b/compiler/testData/codegen/box/innerNested/innerJavaClass.kt index a7e9119122d..da291521d05 100644 --- a/compiler/testData/codegen/box/innerNested/innerJavaClass.kt +++ b/compiler/testData/codegen/box/innerNested/innerJavaClass.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM // FILE: JavaClass.java diff --git a/compiler/testData/codegen/box/innerNested/passingOuterRef.kt b/compiler/testData/codegen/box/innerNested/passingOuterRef.kt index 0d6dc96ebe4..b0c474ab11b 100644 --- a/compiler/testData/codegen/box/innerNested/passingOuterRef.kt +++ b/compiler/testData/codegen/box/innerNested/passingOuterRef.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR open class A1(y: String) { val x = "A1.x,$y" } diff --git a/compiler/testData/codegen/box/innerNested/superConstructorCall/deepInnerHierarchy.kt b/compiler/testData/codegen/box/innerNested/superConstructorCall/deepInnerHierarchy.kt index 43e437746db..08efa14a7ff 100644 --- a/compiler/testData/codegen/box/innerNested/superConstructorCall/deepInnerHierarchy.kt +++ b/compiler/testData/codegen/box/innerNested/superConstructorCall/deepInnerHierarchy.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR open class A(val s: String) { open inner class B(s: String): A(s) diff --git a/compiler/testData/codegen/box/innerNested/superConstructorCall/innerExtendsInnerViaSecondaryConstuctor.kt b/compiler/testData/codegen/box/innerNested/superConstructorCall/innerExtendsInnerViaSecondaryConstuctor.kt index 92549b985df..971d1a07831 100644 --- a/compiler/testData/codegen/box/innerNested/superConstructorCall/innerExtendsInnerViaSecondaryConstuctor.kt +++ b/compiler/testData/codegen/box/innerNested/superConstructorCall/innerExtendsInnerViaSecondaryConstuctor.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR open class Father(val param: String) { abstract inner class InClass { fun work(): String { diff --git a/compiler/testData/codegen/box/innerNested/superConstructorCall/innerExtendsInnerWithProperOuterCapture.kt b/compiler/testData/codegen/box/innerNested/superConstructorCall/innerExtendsInnerWithProperOuterCapture.kt index dd27137f3a1..117f4bf0471 100644 --- a/compiler/testData/codegen/box/innerNested/superConstructorCall/innerExtendsInnerWithProperOuterCapture.kt +++ b/compiler/testData/codegen/box/innerNested/superConstructorCall/innerExtendsInnerWithProperOuterCapture.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR open class Father(val param: String) { abstract inner class InClass { fun work(): String { diff --git a/compiler/testData/codegen/box/innerNested/superConstructorCall/kt11833_1.kt b/compiler/testData/codegen/box/innerNested/superConstructorCall/kt11833_1.kt index 81f10d665a9..fe17fb4d085 100644 --- a/compiler/testData/codegen/box/innerNested/superConstructorCall/kt11833_1.kt +++ b/compiler/testData/codegen/box/innerNested/superConstructorCall/kt11833_1.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR abstract class Father { abstract inner class InClass { abstract fun work(): String diff --git a/compiler/testData/codegen/box/innerNested/superConstructorCall/kt11833_2.kt b/compiler/testData/codegen/box/innerNested/superConstructorCall/kt11833_2.kt index 041a71de1c6..4753541d860 100644 --- a/compiler/testData/codegen/box/innerNested/superConstructorCall/kt11833_2.kt +++ b/compiler/testData/codegen/box/innerNested/superConstructorCall/kt11833_2.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR abstract class Father { abstract inner class InClass { abstract fun work(): String diff --git a/compiler/testData/codegen/box/innerNested/superConstructorCall/localClassOuterDiffersFromInnerOuter.kt b/compiler/testData/codegen/box/innerNested/superConstructorCall/localClassOuterDiffersFromInnerOuter.kt index 54684aae70e..cf1db10e27c 100644 --- a/compiler/testData/codegen/box/innerNested/superConstructorCall/localClassOuterDiffersFromInnerOuter.kt +++ b/compiler/testData/codegen/box/innerNested/superConstructorCall/localClassOuterDiffersFromInnerOuter.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR class A { fun bar(): Any { return { diff --git a/compiler/testData/codegen/box/innerNested/superConstructorCall/localExtendsInner.kt b/compiler/testData/codegen/box/innerNested/superConstructorCall/localExtendsInner.kt index a65a06d0606..bd2fe48d847 100644 --- a/compiler/testData/codegen/box/innerNested/superConstructorCall/localExtendsInner.kt +++ b/compiler/testData/codegen/box/innerNested/superConstructorCall/localExtendsInner.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR open class Father(val param: String) { abstract inner class InClass { fun work(): String { diff --git a/compiler/testData/codegen/box/innerNested/superConstructorCall/objectExtendsInner.kt b/compiler/testData/codegen/box/innerNested/superConstructorCall/objectExtendsInner.kt index ecf8bc95497..f02f1d4edc1 100644 --- a/compiler/testData/codegen/box/innerNested/superConstructorCall/objectExtendsInner.kt +++ b/compiler/testData/codegen/box/innerNested/superConstructorCall/objectExtendsInner.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR class A { open inner class Inner(val result: String) diff --git a/compiler/testData/codegen/box/innerNested/superConstructorCall/objectExtendsInnerDefaultArgument.kt b/compiler/testData/codegen/box/innerNested/superConstructorCall/objectExtendsInnerDefaultArgument.kt index 5e8fdbc6d99..c94d6ab49ca 100644 --- a/compiler/testData/codegen/box/innerNested/superConstructorCall/objectExtendsInnerDefaultArgument.kt +++ b/compiler/testData/codegen/box/innerNested/superConstructorCall/objectExtendsInnerDefaultArgument.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR class A { open inner class Inner(val result: String = "OK", val int: Int) diff --git a/compiler/testData/codegen/box/innerNested/superConstructorCall/objectOuterDiffersFromInnerOuter.kt b/compiler/testData/codegen/box/innerNested/superConstructorCall/objectOuterDiffersFromInnerOuter.kt index 9657cc10f2a..e6fe2b05cf9 100644 --- a/compiler/testData/codegen/box/innerNested/superConstructorCall/objectOuterDiffersFromInnerOuter.kt +++ b/compiler/testData/codegen/box/innerNested/superConstructorCall/objectOuterDiffersFromInnerOuter.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR class A { fun bar(): Any { return { diff --git a/compiler/testData/codegen/box/localClasses/localExtendsInnerAndReferencesOuterMember.kt b/compiler/testData/codegen/box/localClasses/localExtendsInnerAndReferencesOuterMember.kt index a8eb8710ef7..f5520406363 100644 --- a/compiler/testData/codegen/box/localClasses/localExtendsInnerAndReferencesOuterMember.kt +++ b/compiler/testData/codegen/box/localClasses/localExtendsInnerAndReferencesOuterMember.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR class A { fun box(): String { class Local : Inner() { diff --git a/compiler/testData/codegen/box/localClasses/subclassingExtensionReceiverClass.kt b/compiler/testData/codegen/box/localClasses/subclassingExtensionReceiverClass.kt index 806000c6dc9..3e6dafc1749 100644 --- a/compiler/testData/codegen/box/localClasses/subclassingExtensionReceiverClass.kt +++ b/compiler/testData/codegen/box/localClasses/subclassingExtensionReceiverClass.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // IGNORE_BACKEND: JVM class A(val x: String) { diff --git a/compiler/testData/codegen/box/objects/objectExtendsInnerAndReferencesOuterMember.kt b/compiler/testData/codegen/box/objects/objectExtendsInnerAndReferencesOuterMember.kt index 46f921793cc..def3f9f7616 100644 --- a/compiler/testData/codegen/box/objects/objectExtendsInnerAndReferencesOuterMember.kt +++ b/compiler/testData/codegen/box/objects/objectExtendsInnerAndReferencesOuterMember.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR class A { val x: Any get() { return object : Inner() { diff --git a/compiler/testData/codegen/box/typealias/innerClassTypeAliasConstructorInSupertypes.kt b/compiler/testData/codegen/box/typealias/innerClassTypeAliasConstructorInSupertypes.kt index ce7d8776baf..69638e0c6e3 100644 --- a/compiler/testData/codegen/box/typealias/innerClassTypeAliasConstructorInSupertypes.kt +++ b/compiler/testData/codegen/box/typealias/innerClassTypeAliasConstructorInSupertypes.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR class Outer(val x: String) { abstract inner class InnerBase diff --git a/compiler/testData/diagnostics/tests/inference/knownTypeParameters.fir.kt b/compiler/testData/diagnostics/tests/inference/knownTypeParameters.fir.kt deleted file mode 100644 index dcefaaae47b..00000000000 --- a/compiler/testData/diagnostics/tests/inference/knownTypeParameters.fir.kt +++ /dev/null @@ -1,30 +0,0 @@ -// !LANGUAGE: +NewInference - -open class A { - open inner class A1(val a1: T1) - open inner class A2(val a2: T2) - - open fun f1(arg: T1) = arg - open fun f2(arg: T2) = arg -} - -open class B : A() { - open inner class B1(b1: T) : A1(b1) - open inner class B2(b2: Int) : A2(b2) - - fun variableToKnownParameter(p: T): Int = - p as? Int ?: 0 - - inner class B3(b3: T) : A2(variableToKnownParameter(b3)) - - override fun f1(arg: T) = arg - override fun f2(arg: Int) = arg -} - -class C : B() { - inner class C1(c1: String): B1(c1) - inner class C2 : B2(15) - - override fun f1(arg: String) = arg - override fun f2(arg: Int) = arg -} diff --git a/compiler/testData/diagnostics/tests/inference/knownTypeParameters.kt b/compiler/testData/diagnostics/tests/inference/knownTypeParameters.kt index d719187d3fa..7fb8f4d7ac1 100644 --- a/compiler/testData/diagnostics/tests/inference/knownTypeParameters.kt +++ b/compiler/testData/diagnostics/tests/inference/knownTypeParameters.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !LANGUAGE: +NewInference open class A { diff --git a/compiler/testData/diagnostics/tests/inference/kt32415.fir.kt b/compiler/testData/diagnostics/tests/inference/kt32415.fir.kt deleted file mode 100644 index 8aa20cb4c2a..00000000000 --- a/compiler/testData/diagnostics/tests/inference/kt32415.fir.kt +++ /dev/null @@ -1,9 +0,0 @@ -// !LANGUAGE: +NewInference - -abstract class TestType { - open inner class Inner(val item: V) -} - -class Derived: TestType() { - inner class DerivedInner(item: Long): Inner(item) -} diff --git a/compiler/testData/diagnostics/tests/inference/kt32415.kt b/compiler/testData/diagnostics/tests/inference/kt32415.kt index 3b56457ee7d..8aee99fda2d 100644 --- a/compiler/testData/diagnostics/tests/inference/kt32415.kt +++ b/compiler/testData/diagnostics/tests/inference/kt32415.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !LANGUAGE: +NewInference abstract class TestType { diff --git a/compiler/testData/diagnostics/tests/inner/classesInClassObjectHeader.fir.kt b/compiler/testData/diagnostics/tests/inner/classesInClassObjectHeader.fir.kt index b1e7bc807dd..1076a1809f3 100644 --- a/compiler/testData/diagnostics/tests/inner/classesInClassObjectHeader.fir.kt +++ b/compiler/testData/diagnostics/tests/inner/classesInClassObjectHeader.fir.kt @@ -1,6 +1,6 @@ class Test { @`InnerAnnotation` @InnerAnnotation - companion object : StaticClass(), InnerClass() { + companion object : StaticClass(), InnerClass() { } diff --git a/compiler/testData/diagnostics/tests/inner/innerErrorForClassObjects.fir.kt b/compiler/testData/diagnostics/tests/inner/innerErrorForClassObjects.fir.kt index f91ff272ef0..1de2d58247f 100644 --- a/compiler/testData/diagnostics/tests/inner/innerErrorForClassObjects.fir.kt +++ b/compiler/testData/diagnostics/tests/inner/innerErrorForClassObjects.fir.kt @@ -5,8 +5,8 @@ class TestSome

{ } class Test { - companion object : InnerClass() { - val a = object: InnerClass() { + companion object : InnerClass() { + val a = object: InnerClass() { } fun more(): InnerClass { diff --git a/compiler/testData/diagnostics/tests/inner/innerErrorForObjects.fir.kt b/compiler/testData/diagnostics/tests/inner/innerErrorForObjects.fir.kt index 0e447b286f5..60341d7a6ec 100644 --- a/compiler/testData/diagnostics/tests/inner/innerErrorForObjects.fir.kt +++ b/compiler/testData/diagnostics/tests/inner/innerErrorForObjects.fir.kt @@ -5,8 +5,8 @@ class TestSome

{ } class Test { - object Some : InnerClass() { - val a = object: InnerClass() { + object Some : InnerClass() { + val a = object: InnerClass() { } fun more(): InnerClass { diff --git a/compiler/testData/diagnostics/tests/inner/modality.fir.kt b/compiler/testData/diagnostics/tests/inner/modality.fir.kt index 461687e2b8c..720c5f95c83 100644 --- a/compiler/testData/diagnostics/tests/inner/modality.fir.kt +++ b/compiler/testData/diagnostics/tests/inner/modality.fir.kt @@ -7,7 +7,7 @@ class Outer { class Nested1 : OpenNested() class Nested2 : FinalNested() - class Nested3 : OpenInner() + class Nested3 : OpenInner() class Nested4 : FinalInner() inner class Inner1 : OpenNested() diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/nestedExtendsInner.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/nestedExtendsInner.fir.kt index a9321da314d..c0ca6c46513 100644 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/nestedExtendsInner.fir.kt +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/nestedExtendsInner.fir.kt @@ -2,6 +2,6 @@ class A { open inner class Inner class Nested : Inner { - constructor() + constructor() } } diff --git a/compiler/testData/ir/irText/classes/innerClass.fir.txt b/compiler/testData/ir/irText/classes/innerClass.fir.txt index 4a840e1669b..6f730652ab5 100644 --- a/compiler/testData/ir/irText/classes/innerClass.fir.txt +++ b/compiler/testData/ir/irText/classes/innerClass.fir.txt @@ -31,6 +31,7 @@ FILE fqName: fileName:/innerClass.kt $outer: VALUE_PARAMETER name: type:.Outer BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in .Outer.TestInnerClass' + $this: GET_VAR ': .Outer declared in .Outer' type=.Outer origin=null INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:DerivedInnerClass modality:FINAL visibility:public [inner] superTypes:[.Outer.TestInnerClass]' FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] overridden: diff --git a/compiler/testData/ir/irText/classes/innerClassWithDelegatingConstructor.fir.txt b/compiler/testData/ir/irText/classes/innerClassWithDelegatingConstructor.fir.txt index 834f8892b15..951dd86b52b 100644 --- a/compiler/testData/ir/irText/classes/innerClassWithDelegatingConstructor.fir.txt +++ b/compiler/testData/ir/irText/classes/innerClassWithDelegatingConstructor.fir.txt @@ -28,6 +28,7 @@ FILE fqName: fileName:/innerClassWithDelegatingConstructor.kt $outer: VALUE_PARAMETER name: type:.Outer BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'public constructor (x: kotlin.Int) [primary] declared in .Outer.Inner' + $this: GET_VAR ': .Outer declared in .Outer' type=.Outer origin=null x: CONST Int type=kotlin.Int value=0 FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] overridden: diff --git a/compiler/testData/ir/irText/classes/objectLiteralExpressions.fir.txt b/compiler/testData/ir/irText/classes/objectLiteralExpressions.fir.txt index 391c8911b82..93db5694e71 100644 --- a/compiler/testData/ir/irText/classes/objectLiteralExpressions.fir.txt +++ b/compiler/testData/ir/irText/classes/objectLiteralExpressions.fir.txt @@ -121,6 +121,7 @@ FILE fqName: fileName:/objectLiteralExpressions.kt CONSTRUCTOR visibility:private <> () returnType:.Outer.test3. [primary] BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in .Outer.Inner' + $this: GET_VAR ': .Outer declared in .Outer.test3' type=.Outer origin=null INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name: modality:FINAL visibility:local superTypes:[.Outer.Inner]' FUN name:foo visibility:public modality:FINAL <> ($this:.Outer.test3.) returnType:kotlin.Unit overridden: @@ -166,6 +167,7 @@ FILE fqName: fileName:/objectLiteralExpressions.kt CONSTRUCTOR visibility:private <> () returnType:.test4. [primary] BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in .Outer.Inner' + $this: GET_VAR ': .Outer declared in .test4' type=.Outer origin=null INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name: modality:FINAL visibility:local superTypes:[.Outer.Inner]' FUN name:foo visibility:public modality:FINAL <> ($this:.test4.) returnType:kotlin.Unit overridden: diff --git a/compiler/testData/ir/irText/declarations/parameters/constructor.fir.txt b/compiler/testData/ir/irText/declarations/parameters/constructor.fir.txt index 0dca618643b..029b2533349 100644 --- a/compiler/testData/ir/irText/declarations/parameters/constructor.fir.txt +++ b/compiler/testData/ir/irText/declarations/parameters/constructor.fir.txt @@ -90,6 +90,7 @@ FILE fqName: fileName:/constructor.kt BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'public constructor (z: Z of .Test2.TestInner) [primary] declared in .Test2.TestInner' : + $this: GET_VAR ': .Test2 declared in .Test2' type=.Test2 origin=null z: GET_VAR 'z: Z of .Test2.TestInner declared in .Test2.TestInner.' type=Z of .Test2.TestInner origin=null FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] overridden: diff --git a/compiler/testData/ir/irText/expressions/kt16905.fir.txt b/compiler/testData/ir/irText/expressions/kt16905.fir.txt index 75f7cf2ee6a..38b871d7e4c 100644 --- a/compiler/testData/ir/irText/expressions/kt16905.fir.txt +++ b/compiler/testData/ir/irText/expressions/kt16905.fir.txt @@ -31,6 +31,7 @@ FILE fqName: fileName:/kt16905.kt $outer: VALUE_PARAMETER name: type:.Outer BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in .Outer.Inner' + $this: GET_VAR ': .Outer declared in .Outer' type=.Outer origin=null INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:InnerDerived0 modality:FINAL visibility:public [inner] superTypes:[.Outer.Inner]' FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] overridden: @@ -51,6 +52,7 @@ FILE fqName: fileName:/kt16905.kt $outer: VALUE_PARAMETER name: type:.Outer BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in .Outer.Inner' + $this: GET_VAR ': .Outer declared in .Outer' type=.Outer origin=null INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:InnerDerived1 modality:FINAL visibility:public [inner] superTypes:[.Outer.Inner]' FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] overridden: diff --git a/compiler/testData/ir/irText/expressions/multipleThisReferences.fir.txt b/compiler/testData/ir/irText/expressions/multipleThisReferences.fir.txt index 5ab00c2bace..7d36f7d63c0 100644 --- a/compiler/testData/ir/irText/expressions/multipleThisReferences.fir.txt +++ b/compiler/testData/ir/irText/expressions/multipleThisReferences.fir.txt @@ -79,6 +79,7 @@ FILE fqName: fileName:/multipleThisReferences.kt CONSTRUCTOR visibility:private <> () returnType:.Host.test. [primary] BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'public constructor (x: kotlin.Int) [primary] declared in .Outer.Inner' + $this: GET_VAR ': .Outer declared in .Host.test' type=.Outer origin=null x: CONST Int type=kotlin.Int value=42 INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name: modality:FINAL visibility:local superTypes:[.Outer.Inner]' PROPERTY name:xx visibility:public modality:FINAL [val] diff --git a/compiler/testData/ir/irText/expressions/thisOfGenericOuterClass.fir.txt b/compiler/testData/ir/irText/expressions/thisOfGenericOuterClass.fir.txt index 11f81cb2058..38b46607be0 100644 --- a/compiler/testData/ir/irText/expressions/thisOfGenericOuterClass.fir.txt +++ b/compiler/testData/ir/irText/expressions/thisOfGenericOuterClass.fir.txt @@ -72,7 +72,8 @@ FILE fqName: fileName:/thisOfGenericOuterClass.kt $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.test. CONSTRUCTOR visibility:private <> () returnType:.test. [primary] BLOCK_BODY - DELEGATING_CONSTRUCTOR_CALL 'public constructor (y: kotlin.Int) [primary] declared in .Outer.Inner' + DELEGATING_CONSTRUCTOR_CALL 'public constructor (y: kotlin.Int) declared in .Outer.Inner' + $this: GET_VAR ': .Outer declared in .test' type=.Outer origin=null y: CONST Int type=kotlin.Int value=42 INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name: modality:FINAL visibility:local superTypes:[.Outer.Inner]' PROPERTY name:xx visibility:public modality:FINAL [val]