From 317e3edba834d27a456b8728d474a2dc305d74dc Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Thu, 1 Aug 2019 11:53:04 +0300 Subject: [PATCH] [FIR] Add default upper bound to type parameter in fir deserializer --- .../kotlin/fir/lightTree/converter/ConverterUtil.kt | 2 +- .../org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt | 1 + .../org/jetbrains/kotlin/fir/builder/ConversionUtils.kt | 6 ------ .../kotlin/fir/deserialization/FirTypeDeserializer.kt | 2 ++ .../kotlin/fir/declarations/impl/FirTypeParameterImpl.kt | 9 ++++++++- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/compiler/fir/lightTree/src/org/jetbrains/kotlin/fir/lightTree/converter/ConverterUtil.kt b/compiler/fir/lightTree/src/org/jetbrains/kotlin/fir/lightTree/converter/ConverterUtil.kt index 6a156732679..ab2cd7e988b 100644 --- a/compiler/fir/lightTree/src/org/jetbrains/kotlin/fir/lightTree/converter/ConverterUtil.kt +++ b/compiler/fir/lightTree/src/org/jetbrains/kotlin/fir/lightTree/converter/ConverterUtil.kt @@ -11,11 +11,11 @@ import com.intellij.psi.tree.TokenSet import org.jetbrains.kotlin.KtNodeType import org.jetbrains.kotlin.KtNodeTypes.* import org.jetbrains.kotlin.fir.FirSession -import org.jetbrains.kotlin.fir.builder.addDefaultBoundIfNecessary import org.jetbrains.kotlin.fir.builder.generateResolvedAccessExpression import org.jetbrains.kotlin.fir.declarations.FirTypeParameterContainer import org.jetbrains.kotlin.fir.declarations.impl.FirTypeParameterImpl import org.jetbrains.kotlin.fir.declarations.impl.FirVariableImpl +import org.jetbrains.kotlin.fir.declarations.impl.addDefaultBoundIfNecessary import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall import org.jetbrains.kotlin.fir.expressions.FirExpression import org.jetbrains.kotlin.fir.expressions.FirVariable diff --git a/compiler/fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt b/compiler/fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt index 7c41d15d008..10545319595 100644 --- a/compiler/fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt +++ b/compiler/fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt @@ -19,6 +19,7 @@ import org.jetbrains.kotlin.fir.declarations.FirTypeParameter import org.jetbrains.kotlin.fir.declarations.impl.FirErrorFunction import org.jetbrains.kotlin.fir.declarations.impl.FirErrorLoop import org.jetbrains.kotlin.fir.declarations.impl.FirTypeParameterImpl +import org.jetbrains.kotlin.fir.declarations.impl.addDefaultBoundIfNecessary import org.jetbrains.kotlin.fir.expressions.* import org.jetbrains.kotlin.fir.expressions.impl.* import org.jetbrains.kotlin.fir.references.FirErrorNamedReference diff --git a/compiler/fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/ConversionUtils.kt b/compiler/fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/ConversionUtils.kt index 58c0593ffaa..d75010a8f08 100644 --- a/compiler/fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/ConversionUtils.kt +++ b/compiler/fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/ConversionUtils.kt @@ -128,12 +128,6 @@ fun IElementType.toFirOperation(): FirOperation = else -> throw AssertionError(this.toString()) } -fun FirTypeParameterImpl.addDefaultBoundIfNecessary() { - if (bounds.isEmpty()) { - bounds += FirImplicitNullableAnyTypeRef(null) - } -} - fun FirExpression.generateNotNullOrOther( session: FirSession, other: FirExpression, caseId: String, basePsi: KtElement? ): FirWhenExpression { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/deserialization/FirTypeDeserializer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/deserialization/FirTypeDeserializer.kt index 8153d3fd16e..3fe136f4408 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/deserialization/FirTypeDeserializer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/deserialization/FirTypeDeserializer.kt @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir.deserialization import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.declarations.impl.FirTypeParameterImpl +import org.jetbrains.kotlin.fir.declarations.impl.addDefaultBoundIfNecessary import org.jetbrains.kotlin.fir.resolve.toTypeProjection import org.jetbrains.kotlin.fir.symbols.* import org.jetbrains.kotlin.fir.symbols.impl.FirClassLikeSymbol @@ -98,6 +99,7 @@ class FirTypeDeserializer( proto.upperBoundList.mapTo(bounds) { FirResolvedTypeRefImpl(null, type(it), emptyList()) } + addDefaultBoundIfNecessary() } } } diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirTypeParameterImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirTypeParameterImpl.kt index 30048a7f9e8..f23bd5f7b24 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirTypeParameterImpl.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirTypeParameterImpl.kt @@ -31,7 +31,8 @@ class FirTypeParameterImpl( /* * Note that each type parameter have to has at least one upper bound (Any? if there is no other bounds) - * so if you create FirTypeParameterImpl you need to guarantee this contract + * so after initializing FirTypeParameterImpl you should call [addDefaultBoundIfNecessary] to guarantee + * this contract */ override val bounds: MutableList = mutableListOf() @@ -40,4 +41,10 @@ class FirTypeParameterImpl( return super.transformChildren(transformer, data) } +} + +fun FirTypeParameterImpl.addDefaultBoundIfNecessary() { + if (bounds.isEmpty()) { + bounds += FirImplicitNullableAnyTypeRef(null) + } } \ No newline at end of file