Raw FIR: copy class type-parameters into constructors properly
This commit is contained in:
committed by
Mikhail Glukhikh
parent
9cef9e4056
commit
77817cb750
@@ -19,8 +19,7 @@ import org.jetbrains.kotlin.fir.labels.FirLabelImpl
|
||||
import org.jetbrains.kotlin.fir.references.*
|
||||
import org.jetbrains.kotlin.fir.symbols.CallableId
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeProjection
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.fir.types.impl.*
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.lexer.KtTokens.*
|
||||
@@ -110,7 +109,7 @@ class RawFirBuilder(val session: FirSession, val stubMode: Boolean) {
|
||||
return when (this) {
|
||||
is KtSecondaryConstructor -> toFirConstructor(
|
||||
delegatedSuperType,
|
||||
delegatedSelfType!!,
|
||||
delegatedSelfType ?: FirErrorTypeRefImpl(this@RawFirBuilder.session, this, "Constructor in object"),
|
||||
owner,
|
||||
hasPrimaryConstructor
|
||||
)
|
||||
@@ -408,7 +407,7 @@ class RawFirBuilder(val session: FirSession, val stubMode: Boolean) {
|
||||
firDelegatedCall
|
||||
)
|
||||
this?.extractAnnotationsTo(firConstructor)
|
||||
owner.extractTypeParametersTo(firConstructor)
|
||||
firConstructor.typeParameters += typeParametersFromSelfType(delegatedSelfTypeRef)
|
||||
this?.extractValueParametersTo(firConstructor)
|
||||
return firConstructor
|
||||
}
|
||||
@@ -437,16 +436,19 @@ class RawFirBuilder(val session: FirSession, val stubMode: Boolean) {
|
||||
}
|
||||
|
||||
private fun KtClassOrObject.toDelegatedSelfType(firClass: FirRegularClass): FirTypeRef {
|
||||
val typeParameters = firClass.typeParameters.map {
|
||||
FirTypeParameterImpl(session, it.psi, FirTypeParameterSymbol(), it.name, Variance.INVARIANT, false).apply {
|
||||
this.bounds += it.bounds
|
||||
}
|
||||
}
|
||||
return FirResolvedTypeRefImpl(
|
||||
session,
|
||||
this,
|
||||
ConeClassTypeImpl(
|
||||
firClass.symbol.toLookupTag(),
|
||||
firClass.typeParameters.map { ConeTypeParameterTypeImpl(it.symbol, false) }.toTypedArray(),
|
||||
typeParameters.map { ConeTypeParameterTypeImpl(it.symbol, false) }.toTypedArray(),
|
||||
false
|
||||
),
|
||||
isMarkedNullable = false,
|
||||
annotations = emptyList()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -752,13 +754,20 @@ class RawFirBuilder(val session: FirSession, val stubMode: Boolean) {
|
||||
)
|
||||
firFunctions += firConstructor
|
||||
extractAnnotationsTo(firConstructor)
|
||||
owner.extractTypeParametersTo(firConstructor)
|
||||
firConstructor.typeParameters += typeParametersFromSelfType(delegatedSelfTypeRef)
|
||||
extractValueParametersTo(firConstructor)
|
||||
firConstructor.body = buildFirBody()
|
||||
firFunctions.removeLast()
|
||||
return firConstructor
|
||||
}
|
||||
|
||||
private fun typeParametersFromSelfType(delegatedSelfTypeRef: FirTypeRef): List<FirTypeParameter> {
|
||||
return delegatedSelfTypeRef.coneTypeSafe()
|
||||
?.typeArguments
|
||||
?.map { ((it as ConeTypeParameterType).lookupTag as FirTypeParameterSymbol).fir }
|
||||
?: emptyList()
|
||||
}
|
||||
|
||||
private fun KtConstructorDelegationCall.convert(
|
||||
delegatedSuperTypeRef: FirTypeRef?,
|
||||
delegatedSelfTypeRef: FirTypeRef,
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
FILE: complexTypes.kt
|
||||
public? final? class C<T, out S> : kotlin/Any {
|
||||
public? constructor<T, out S>(): R|a/b/C<T, S>| {
|
||||
public? constructor<T, S>(): R|a/b/C<T, S>| {
|
||||
super<kotlin/Any>()
|
||||
}
|
||||
|
||||
public? final? inner class D<R, in P> : kotlin/Any {
|
||||
public? constructor<R, in P>(): R|a/b/C.D<R, P>| {
|
||||
public? constructor<R, P>(): R|a/b/C.D<R, P>| {
|
||||
super<kotlin/Any>()
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ FILE: typeParameters.kt
|
||||
public? final typealias StringList = List<out String>
|
||||
public? final typealias AnyList = List<*>
|
||||
public? abstract class AbstractList<out T : Any> : List<T> {
|
||||
public? constructor<out T : Any>(): R|AbstractList<T>| {
|
||||
public? constructor<T : Any>(): R|AbstractList<T>| {
|
||||
super<kotlin/Any>()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user