[FIR] Add default upper bound to type parameter in fir deserializer

This commit is contained in:
Dmitriy Novozhilov
2019-08-01 11:53:04 +03:00
parent 2fe01f9086
commit 317e3edba8
5 changed files with 12 additions and 8 deletions
@@ -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
@@ -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
@@ -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 {
@@ -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()
}
}
}
@@ -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<FirTypeRef> = mutableListOf()
@@ -40,4 +41,10 @@ class FirTypeParameterImpl(
return super<FirAbstractNamedAnnotatedDeclaration>.transformChildren(transformer, data)
}
}
fun FirTypeParameterImpl.addDefaultBoundIfNecessary() {
if (bounds.isEmpty()) {
bounds += FirImplicitNullableAnyTypeRef(null)
}
}