FIR: construct type with actual type arguments during GetClassCall transformation
This commit is contained in:
committed by
Mikhail Glukhikh
parent
4f8ad6bdcb
commit
0d6e309372
@@ -5,5 +5,5 @@ FILE: reflectionClass.kt
|
||||
public get(): R|kotlin/reflect/KClass<kotlin/String>|
|
||||
public final fun foo(): R|kotlin/Unit| {
|
||||
lval stringClass: R|java/lang/Class<kotlin/String>| = <getClass>(Q|kotlin/String|).R|kotlin/jvm/java|<R|kotlin/String|>
|
||||
lval arrayStringClass: R|java/lang/Class<kotlin/Array<*>>| = <getClass>(Q|kotlin/Array|).R|kotlin/jvm/java|<R|kotlin/Array<*>|>
|
||||
lval arrayStringClass: R|java/lang/Class<kotlin/Array<kotlin/String>>| = <getClass>(Q|kotlin/Array|).R|kotlin/jvm/java|<R|kotlin/Array<kotlin/String>|>
|
||||
}
|
||||
|
||||
@@ -188,19 +188,8 @@ fun FirClassifierSymbol<*>.constructType(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun List<FirQualifierPart>.toTypeProjections(): Array<ConeTypeProjection> = asReversed().flatMap {
|
||||
it.typeArguments.map { typeArgument ->
|
||||
when (typeArgument) {
|
||||
is FirStarProjection -> ConeStarProjection
|
||||
is FirTypeProjectionWithVariance -> {
|
||||
val type = (typeArgument.typeRef as FirResolvedTypeRef).type
|
||||
type.toTypeProjection(typeArgument.variance)
|
||||
}
|
||||
else -> error("!")
|
||||
}
|
||||
}
|
||||
}.toTypedArray()
|
||||
private fun List<FirQualifierPart>.toTypeProjections(): Array<ConeTypeProjection> =
|
||||
asReversed().flatMap { it.typeArguments.map { typeArgument -> typeArgument.toConeTypeProjection() } }.toTypedArray()
|
||||
|
||||
fun FirFunction<*>.constructFunctionalTypeRef(session: FirSession, isSuspend: Boolean = false): FirResolvedTypeRef {
|
||||
val receiverTypeRef = when (this) {
|
||||
|
||||
+2
-7
@@ -34,6 +34,7 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirVariableSymbol
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.fir.types.builder.*
|
||||
import org.jetbrains.kotlin.fir.types.impl.FirQualifierPartImpl
|
||||
import org.jetbrains.kotlin.fir.visitors.*
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
@@ -540,13 +541,7 @@ class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransformer) :
|
||||
val typeOfExpression = when (val lhs = transformedGetClassCall.argument) {
|
||||
is FirResolvedQualifier -> {
|
||||
val symbol = lhs.symbol
|
||||
val typeRef =
|
||||
symbol?.constructType(
|
||||
Array((symbol.phasedFir as? FirTypeParameterRefsOwner)?.typeParameters?.size ?: 0) {
|
||||
ConeStarProjection
|
||||
},
|
||||
isNullable = false,
|
||||
)
|
||||
val typeRef = symbol?.constructType(lhs.typeArguments.map { it.toConeTypeProjection() }.toTypedArray(), isNullable = false)
|
||||
if (typeRef != null) {
|
||||
lhs.replaceTypeRef(buildResolvedTypeRef { type = typeRef })
|
||||
typeRef
|
||||
|
||||
@@ -184,6 +184,16 @@ fun ConeKotlinType.toTypeProjection(variance: Variance): ConeTypeProjection =
|
||||
Variance.OUT_VARIANCE -> ConeKotlinTypeProjectionOut(this)
|
||||
}
|
||||
|
||||
internal fun FirTypeProjection.toConeTypeProjection(): ConeTypeProjection =
|
||||
when (this) {
|
||||
is FirStarProjection -> ConeStarProjection
|
||||
is FirTypeProjectionWithVariance -> {
|
||||
val type = (this.typeRef as FirResolvedTypeRef).type
|
||||
type.toTypeProjection(this.variance)
|
||||
}
|
||||
else -> error("!")
|
||||
}
|
||||
|
||||
fun ConeClassLikeLookupTag.constructClassType(
|
||||
typeArguments: Array<out ConeTypeProjection>,
|
||||
isNullable: Boolean,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// WITH_RUNTIME
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// WITH_RUNTIME
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_REFLECT
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// IGNORE_BACKEND: JS_IR_ES6
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// IGNORE_BACKEND: JS_IR_ES6
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
+8
-8
@@ -23,21 +23,21 @@ val test3: MutableList<Int> =
|
||||
}
|
||||
|
||||
val test4: Collection<Int> =
|
||||
listOf(1, 2, 3).<!AMBIGUITY!>flatMapTo<!>(LinkedHashSet()) {
|
||||
<!INAPPLICABLE_CANDIDATE!>listOf<!>(<!UNRESOLVED_REFERENCE!>it<!>)
|
||||
listOf(1, 2, 3).flatMapTo(LinkedHashSet()) {
|
||||
listOf(it)
|
||||
}
|
||||
|
||||
val test5: Collection<Int> =
|
||||
listOf(1, 2, 3).<!AMBIGUITY!>flatMapTo<!>(LinkedHashSet()) { // TODO
|
||||
if (true) <!INAPPLICABLE_CANDIDATE!>listOf<!>(<!UNRESOLVED_REFERENCE!>it<!>) else <!INAPPLICABLE_CANDIDATE!>listOf<!>(<!UNRESOLVED_REFERENCE!>it<!>)
|
||||
listOf(1, 2, 3).flatMapTo(LinkedHashSet()) { // TODO
|
||||
if (true) listOf(it) else listOf(it)
|
||||
}
|
||||
|
||||
val test6: Collection<Int> =
|
||||
listOf(1, 2, 3).<!AMBIGUITY!>flatMapTo<!>(LinkedHashSet<Int>()) {
|
||||
if (true) <!INAPPLICABLE_CANDIDATE!>listOf<!>(<!UNRESOLVED_REFERENCE!>it<!>) else <!INAPPLICABLE_CANDIDATE!>listOf<!>(<!UNRESOLVED_REFERENCE!>it<!>)
|
||||
listOf(1, 2, 3).flatMapTo(LinkedHashSet<Int>()) {
|
||||
if (true) listOf(it) else listOf(it)
|
||||
}
|
||||
|
||||
val test7: Collection<Int> =
|
||||
listOf(1, 2, 3).<!AMBIGUITY!>flatMapTo<!>(LinkedHashSet()) {
|
||||
<!INAPPLICABLE_CANDIDATE!>select<!>(<!INAPPLICABLE_CANDIDATE!>listOf<!>(<!UNRESOLVED_REFERENCE!>it<!>), <!INAPPLICABLE_CANDIDATE!>listOf<!>(<!UNRESOLVED_REFERENCE!>it<!>))
|
||||
listOf(1, 2, 3).flatMapTo(LinkedHashSet()) {
|
||||
select(listOf(it), listOf(it))
|
||||
}
|
||||
Reference in New Issue
Block a user