[FIR] Add Any? as default bound for all type parameters
This commit is contained in:
committed by
Mikhail Glukhikh
parent
8a21785883
commit
d3670d4f5f
@@ -444,6 +444,7 @@ class RawFirBuilder(val session: FirSession, val stubMode: Boolean) {
|
||||
val typeParameters = firClass.typeParameters.map {
|
||||
FirTypeParameterImpl(session, it.psi, FirTypeParameterSymbol(), it.name, Variance.INVARIANT, false).apply {
|
||||
this.bounds += it.bounds
|
||||
addDefaultBoundIfNecessary()
|
||||
}
|
||||
}
|
||||
return FirResolvedTypeRefImpl(
|
||||
@@ -457,6 +458,12 @@ class RawFirBuilder(val session: FirSession, val stubMode: Boolean) {
|
||||
)
|
||||
}
|
||||
|
||||
private fun FirTypeParameterImpl.addDefaultBoundIfNecessary() {
|
||||
if (bounds.isEmpty()) {
|
||||
bounds += FirImplicitNullableAnyTypeRef(session, null)
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitEnumEntry(enumEntry: KtEnumEntry, data: Unit): FirElement {
|
||||
return withChildClassName(enumEntry.nameAsSafeName) {
|
||||
val firEnumEntry = FirEnumEntryImpl(
|
||||
@@ -917,6 +924,7 @@ class RawFirBuilder(val session: FirSession, val stubMode: Boolean) {
|
||||
firTypeParameter.bounds += typeConstraint.boundTypeReference.toFirOrErrorType()
|
||||
}
|
||||
}
|
||||
firTypeParameter.addDefaultBoundIfNecessary()
|
||||
return firTypeParameter
|
||||
}
|
||||
|
||||
|
||||
+6
-1
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.fir.declarations.FirTypeParameter
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol
|
||||
import org.jetbrains.kotlin.fir.transformInplace
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.impl.FirImplicitNullableAnyTypeRef
|
||||
import org.jetbrains.kotlin.fir.visitors.FirTransformer
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
@@ -28,7 +29,11 @@ class FirTypeParameterImpl(
|
||||
symbol.bind(this)
|
||||
}
|
||||
|
||||
override val bounds = mutableListOf<FirTypeRef>()
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
override val bounds: MutableList<FirTypeRef> = mutableListOf()
|
||||
|
||||
override fun <D> transformChildren(transformer: FirTransformer<D>, data: D): FirElement {
|
||||
bounds.transformInplace(transformer, data)
|
||||
|
||||
Reference in New Issue
Block a user