diff --git a/compiler/fir/lightTree/src/org/jetbrains/kotlin/fir/lightTree/Converter.kt b/compiler/fir/lightTree/src/org/jetbrains/kotlin/fir/lightTree/Converter.kt index cb239081b2c..d0df6527e06 100644 --- a/compiler/fir/lightTree/src/org/jetbrains/kotlin/fir/lightTree/Converter.kt +++ b/compiler/fir/lightTree/src/org/jetbrains/kotlin/fir/lightTree/Converter.kt @@ -64,6 +64,7 @@ class Converter( private val implicitUnitType = FirImplicitUnitTypeRef(session, null) private val implicitAnyType = FirImplicitAnyTypeRef(session, null) private val implicitEnumType = FirImplicitEnumTypeRef(session, null) + private val implicitAnnotationType = FirImplicitAnnotationTypeRef(session, null) private val implicitType = FirImplicitTypeRefImpl(session, null) private fun LighterASTNode?.getChildrenAsArray(): Array { @@ -244,15 +245,21 @@ class Converter( } } - classKind = when { - modifiers.classModifier == ClassModifier.ENUM -> ClassKind.ENUM_CLASS - modifiers.classModifier == ClassModifier.ANNOTATION -> ClassKind.ANNOTATION_CLASS + classKind = when (modifiers.classModifier) { + ClassModifier.ENUM -> ClassKind.ENUM_CLASS + ClassModifier.ANNOTATION -> ClassKind.ANNOTATION_CLASS else -> classKind } val hasSecondaryConstructor = classBody.hasSecondaryConstructor(classBody.getChildrenAsArray()) val className = identifier.nameAsSafeName(if (modifiers.classModifier == ClassModifier.COMPANION) "Companion" else "") + + val defaultDelegatedSuperTypeRef = when (classKind) { + ClassKind.ENUM_CLASS -> implicitEnumType + ClassKind.ANNOTATION_CLASS -> implicitAnnotationType + else -> implicitAnyType + } val delegatedSelfTypeRef = className.toDelegatedSelfType(session) - delegatedSuperTypeRef = delegatedSuperTypeRef ?: if (classKind == ClassKind.ENUM_CLASS) implicitEnumType else implicitAnyType + delegatedSuperTypeRef = delegatedSuperTypeRef ?: defaultDelegatedSuperTypeRef return ClassNameUtil.withChildClassName(className) { val firClass = FirClassImpl( @@ -403,6 +410,7 @@ class Converter( /** * @see org.jetbrains.kotlin.parsing.KotlinParsing.parseDelegationSpecifierList + * @see org.jetbrains.kotlin.fir.builder.RawFirBuilder.Visitor.extractSuperTypeListEntriesTo * * SUPER_TYPE_ENTRY - userType * SUPER_TYPE_CALL_ENTRY - constructorInvocation @@ -466,6 +474,7 @@ class Converter( } return FirDelegatedTypeRefImpl( + session, firTypeRef, expression ) @@ -489,7 +498,8 @@ class Converter( } /** - * see org.jetbrains.kotlin.fir.builder.RawFirBuilder.Visitor#convert(KtConstructorDelegationCall, FirTypeRef, Boolean) + * @see org.jetbrains.kotlin.fir.builder.RawFirBuilder.Visitor.convert( + * KtConstructorDelegationCall, FirTypeRef, Boolean) */ private fun convertConstructorDelegationCall(constructorDelegationCall: LighterASTNode?): FirDelegatedConstructorCallImpl { var isThis: Boolean = false @@ -755,6 +765,7 @@ class Converter( * this is just a VALUE_PARAMETER_LIST * * @see org.jetbrains.kotlin.parsing.KotlinParsing.parsePropertyGetterOrSetter + * @see org.jetbrains.kotlin.fir.builder.RawFirBuilder.Visitor.toFirValueParameter */ private fun convertSetterParameter(setterParameter: LighterASTNode, propertyTypeRef: FirTypeRef): FirValueParameter { var modifiers = Modifier(session) @@ -771,7 +782,7 @@ class Converter( null, firValueParameter.name, if (firValueParameter.returnTypeRef == implicitType) propertyTypeRef else firValueParameter.returnTypeRef, - null, + null,//TODO implement isCrossinline = modifiers.parameterModifier == ParameterModifier.CROSSINLINE, isNoinline = modifiers.parameterModifier == ParameterModifier.NOINLINE, isVararg = modifiers.parameterModifier == ParameterModifier.VARARG @@ -850,7 +861,7 @@ class Converter( returnType, isVar, firExpression, - if (isDelegate) { + delegate = if (isDelegate) { FirExpressionStub(session, null) //TODO("not implemented") //{ property.delegate?.expression }.toFirExpression("Should have delegate") diff --git a/compiler/fir/lightTree/src/org/jetbrains/kotlin/fir/lightTree/ConverterUtil.kt b/compiler/fir/lightTree/src/org/jetbrains/kotlin/fir/lightTree/ConverterUtil.kt index fb749e10157..df4fcfccdd9 100644 --- a/compiler/fir/lightTree/src/org/jetbrains/kotlin/fir/lightTree/ConverterUtil.kt +++ b/compiler/fir/lightTree/src/org/jetbrains/kotlin/fir/lightTree/ConverterUtil.kt @@ -14,10 +14,7 @@ import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.declarations.impl.* import org.jetbrains.kotlin.fir.expressions.FirExpression import org.jetbrains.kotlin.fir.expressions.FirReturnExpression -import org.jetbrains.kotlin.fir.expressions.impl.FirAbstractCall -import org.jetbrains.kotlin.fir.expressions.impl.FirDelegatedConstructorCallImpl -import org.jetbrains.kotlin.fir.expressions.impl.FirExpressionStub -import org.jetbrains.kotlin.fir.expressions.impl.FirReturnExpressionImpl +import org.jetbrains.kotlin.fir.expressions.impl.* import org.jetbrains.kotlin.fir.lightTree.fir.TypeConstraint import org.jetbrains.kotlin.fir.symbols.CallableId import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol @@ -40,7 +37,7 @@ object ConverterUtil { } fun Name?.toDelegatedSelfType(session: FirSession): FirTypeRef = - FirUserTypeRefImpl(session, null, isNullable = false).apply { + FirUserTypeRefImpl(session, null, isMarkedNullable = false).apply { qualifier.add( FirQualifierPartImpl( this@toDelegatedSelfType ?: SpecialNames.NO_NAME_PROVIDED @@ -108,7 +105,7 @@ object ConverterUtil { } } - fun T.extractArgumentsFrom(container: List, stubMode: Boolean): T { + fun T.extractArgumentsFrom(container: List, stubMode: Boolean): T { if (!stubMode) { //TODO("not implemented") this.arguments += container diff --git a/compiler/fir/lightTree/src/org/jetbrains/kotlin/fir/lightTree/LightTree2Fir.kt b/compiler/fir/lightTree/src/org/jetbrains/kotlin/fir/lightTree/LightTree2Fir.kt index 8c1b092ed11..5e3c9032f6e 100644 --- a/compiler/fir/lightTree/src/org/jetbrains/kotlin/fir/lightTree/LightTree2Fir.kt +++ b/compiler/fir/lightTree/src/org/jetbrains/kotlin/fir/lightTree/LightTree2Fir.kt @@ -41,7 +41,7 @@ class LightTree2Fir( fun buildFirFile(code: String, fileName: String): FirFile { val lightTree = buildLightTree(code) - return Converter(object : FirSessionBase() {}, stubMode, lightTree) + return Converter(object : FirSessionBase(null) {}, stubMode, lightTree) .convertFile(lightTree.root, fileName) } } \ No newline at end of file diff --git a/compiler/fir/lightTree/src/org/jetbrains/kotlin/fir/lightTree/fir/ValueParameter.kt b/compiler/fir/lightTree/src/org/jetbrains/kotlin/fir/lightTree/fir/ValueParameter.kt index cc3501e6eff..25a6668b05c 100644 --- a/compiler/fir/lightTree/src/org/jetbrains/kotlin/fir/lightTree/fir/ValueParameter.kt +++ b/compiler/fir/lightTree/src/org/jetbrains/kotlin/fir/lightTree/fir/ValueParameter.kt @@ -10,10 +10,12 @@ import org.jetbrains.kotlin.fir.declarations.FirValueParameter import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyGetter import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertySetter import org.jetbrains.kotlin.fir.declarations.impl.FirMemberPropertyImpl +import org.jetbrains.kotlin.fir.expressions.impl.FirQualifiedAccessExpressionImpl import org.jetbrains.kotlin.fir.lightTree.ClassNameUtil import org.jetbrains.kotlin.fir.lightTree.fir.modifier.MemberModifier import org.jetbrains.kotlin.fir.lightTree.fir.modifier.Modifier import org.jetbrains.kotlin.fir.lightTree.fir.modifier.PlatformModifier +import org.jetbrains.kotlin.fir.references.FirPropertyFromParameterCallableReference import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol class ValueParameter( @@ -45,9 +47,18 @@ class ValueParameter( receiverTypeRef = null, returnTypeRef = type, isVar = this.isVar, - initializer = null, + initializer = FirQualifiedAccessExpressionImpl(this.firValueParameter.session, null).apply { + calleeReference = FirPropertyFromParameterCallableReference( + this@ValueParameter.firValueParameter.session, null, name, this@ValueParameter.firValueParameter.symbol + ) + }, getter = FirDefaultPropertyGetter(this.firValueParameter.session, null, type, modifier.visibilityModifier.toVisibility()), - setter = FirDefaultPropertySetter(this.firValueParameter.session, null, type, modifier.visibilityModifier.toVisibility()), + setter = if (this.isVar) FirDefaultPropertySetter( + this.firValueParameter.session, + null, + type, + modifier.visibilityModifier.toVisibility() + ) else null, delegate = null ).apply { annotations += this@ValueParameter.firValueParameter.annotations } }