From e8e9f6706961629f96bd78391ccf5788a8785b31 Mon Sep 17 00:00:00 2001 From: Andrey Zinovyev Date: Sun, 18 Apr 2021 16:53:01 +0300 Subject: [PATCH] [FIR][LightTree] Enum and property source fixes Also set dispatchReceiverType for properties from value params --- .../converter/DeclarationsConverter.kt | 32 +++++++++++++++---- .../fir/lightTree/fir/ValueParameter.kt | 9 +++++- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt index b0f9e722674..02093387a55 100644 --- a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt +++ b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt @@ -485,7 +485,14 @@ class DeclarationsConverter( //parse properties properties += primaryConstructorWrapper.valueParameters .filter { it.hasValOrVar() } - .map { it.toFirProperty(baseSession, callableIdForName(it.firValueParameter.name), classWrapper.hasExpect()) } + .map { + it.toFirProperty( + baseSession, + callableIdForName(it.firValueParameter.name), + classWrapper.hasExpect(), + currentDispatchReceiverType() + ) + } addDeclarations(properties) } @@ -676,7 +683,8 @@ class DeclarationsConverter( null, enumEntry.toFirSourceElement(), enumClassWrapper, - superTypeCallEntry?.toFirSourceElement() + superTypeCallEntry?.toFirSourceElement(), + isEnumEntry = true )?.let { declarations += it.firConstructor } classBodyNode?.also { // Use ANONYMOUS_OBJECT_NAME for the owner class id of enum entry declarations @@ -735,6 +743,7 @@ class DeclarationsConverter( selfTypeSource: FirSourceElement?, classWrapper: ClassWrapper, delegatedConstructorSource: FirLightSourceElement?, + isEnumEntry: Boolean = false ): PrimaryConstructor? { if (primaryConstructor == null && !classWrapper.isEnumEntry() && classWrapper.hasSecondaryConstructor) return null if (classWrapper.isInterface()) return null @@ -754,12 +763,16 @@ class DeclarationsConverter( constructedTypeRef = classWrapper.delegatedSuperTypeRef.copyWithNewSourceKind(FirFakeSourceElementKind.ImplicitTypeRef) isThis = false calleeReference = buildExplicitSuperReference { - //[dirty] if there is not explicit constructor call source, don't take delegatedSuperTypeRef.source - source = if (delegatedConstructorSource != null) { + //[dirty] in case of enum classWrapper.delegatedSuperTypeRef.source is whole enum source + source = if (!isEnumEntry) { classWrapper.delegatedSuperTypeRef.source?.fakeElement(FirFakeSourceElementKind.DelegatingConstructorCall) ?: this@buildDelegatedConstructorCall.source?.fakeElement(FirFakeSourceElementKind.DelegatingConstructorCall) } else { - this@buildDelegatedConstructorCall.source + delegatedConstructorSource + ?.lighterASTNode + ?.getChildNodeByType(CONSTRUCTOR_CALLEE) + ?.toFirSourceElement(FirFakeSourceElementKind.DelegatingConstructorCall) + ?: this@buildDelegatedConstructorCall.source } superTypeRef = this@buildDelegatedConstructorCall.constructedTypeRef @@ -1007,12 +1020,17 @@ class DeclarationsConverter( this.isVar = isVar initializer = propertyInitializer + //probably can do this for delegateExpression itself + val delegateSource = delegateExpression?.let { + (it.getExpressionInParentheses() ?: it).toFirSourceElement() + } + if (isLocal) { this.isLocal = true symbol = FirPropertySymbol(propertyName) val delegateBuilder = delegateExpression?.let { FirWrappedDelegateExpressionBuilder().apply { - source = it.toFirSourceElement() + source = delegateSource expression = expressionConverter.getAsFirExpression(it, "Incorrect delegate expression") } } @@ -1042,7 +1060,7 @@ class DeclarationsConverter( val delegateBuilder = delegateExpression?.let { FirWrappedDelegateExpressionBuilder().apply { - source = it.toFirSourceElement() + source = delegateSource expression = expressionConverter.getAsFirExpression(it, "Should have delegate") } } diff --git a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/fir/ValueParameter.kt b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/fir/ValueParameter.kt index 6929a44f261..4cfb58104ec 100644 --- a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/fir/ValueParameter.kt +++ b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/fir/ValueParameter.kt @@ -18,6 +18,7 @@ import org.jetbrains.kotlin.fir.lightTree.fir.modifier.Modifier import org.jetbrains.kotlin.fir.references.builder.buildPropertyFromParameterResolvedNamedReference import org.jetbrains.kotlin.name.CallableId import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol +import org.jetbrains.kotlin.fir.types.ConeClassLikeType import org.jetbrains.kotlin.fir.types.FirImplicitTypeRef import org.jetbrains.kotlin.fir.types.builder.buildErrorTypeRef @@ -32,7 +33,12 @@ class ValueParameter( return isVal || isVar } - fun toFirProperty(session: FirSession, callableId: CallableId, isExpect: Boolean): FirProperty { + fun toFirProperty( + session: FirSession, + callableId: CallableId, + isExpect: Boolean, + currentDispatchReceiver: ConeClassLikeType? + ): FirProperty { val name = this.firValueParameter.name var type = this.firValueParameter.returnTypeRef if (type is FirImplicitTypeRef) { @@ -58,6 +64,7 @@ class ValueParameter( } isVar = this@ValueParameter.isVar symbol = FirPropertySymbol(callableId) + dispatchReceiverType = currentDispatchReceiver isLocal = false status = FirDeclarationStatusImpl(modifiers.getVisibility(), modifiers.getModality()).apply { this.isExpect = isExpect