From 0d6e3093726defd68ea1cc91435d378ffdf0274c Mon Sep 17 00:00:00 2001 From: Jinseong Jeon Date: Wed, 3 Jun 2020 11:53:16 -0700 Subject: [PATCH] FIR: construct type with actual type arguments during GetClassCall transformation --- .../resolveWithStdlib/reflectionClass.txt | 2 +- .../jetbrains/kotlin/fir/resolve/ResolveUtils.kt | 15 ++------------- .../resolve/FirExpressionsResolveTransformer.kt | 9 ++------- .../org/jetbrains/kotlin/fir/types/TypeUtils.kt | 10 ++++++++++ .../testData/codegen/box/jvmOverloads/varargs.kt | 1 - .../testData/codegen/box/package/mainInFiles.kt | 1 - .../reflection/annotations/localClassLiteral.kt | 1 - .../classes/jvmNameOfStandardClasses.kt | 1 - .../types/annotationConstructorParameters.kt | 1 - .../box/reflection/mapping/types/array.kt | 1 - .../supertypes/isSubclassOfIsSuperclassOf.kt | 1 - .../box/reflection/types/classifierIsClass.kt | 1 - .../box/reflection/types/jvmErasureOfClass.kt | 1 - .../types/jvmErasureOfTypeParameter.kt | 1 - .../when/noTypeArgumentsInConstructor.fir.kt | 16 ++++++++-------- 15 files changed, 23 insertions(+), 39 deletions(-) diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/reflectionClass.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/reflectionClass.txt index 72e3f2adbd3..57050f2b651 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/reflectionClass.txt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/reflectionClass.txt @@ -5,5 +5,5 @@ FILE: reflectionClass.kt public get(): R|kotlin/reflect/KClass| public final fun foo(): R|kotlin/Unit| { lval stringClass: R|java/lang/Class| = (Q|kotlin/String|).R|kotlin/jvm/java| - lval arrayStringClass: R|java/lang/Class>| = (Q|kotlin/Array|).R|kotlin/jvm/java||> + lval arrayStringClass: R|java/lang/Class>| = (Q|kotlin/Array|).R|kotlin/jvm/java||> } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ResolveUtils.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ResolveUtils.kt index 84a9572a2ba..4f06b30b820 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ResolveUtils.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ResolveUtils.kt @@ -188,19 +188,8 @@ fun FirClassifierSymbol<*>.constructType( } } - -private fun List.toTypeProjections(): Array = 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.toTypeProjections(): Array = + asReversed().flatMap { it.typeArguments.map { typeArgument -> typeArgument.toConeTypeProjection() } }.toTypedArray() fun FirFunction<*>.constructFunctionalTypeRef(session: FirSession, isSuspend: Boolean = false): FirResolvedTypeRef { val receiverTypeRef = when (this) { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt index a157503e3d3..f9b580a2298 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt @@ -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 diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/TypeUtils.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/TypeUtils.kt index 65481462520..54a494cbc3a 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/TypeUtils.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/TypeUtils.kt @@ -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, isNullable: Boolean, diff --git a/compiler/testData/codegen/box/jvmOverloads/varargs.kt b/compiler/testData/codegen/box/jvmOverloads/varargs.kt index 1082f4c7354..e78bb312d1d 100644 --- a/compiler/testData/codegen/box/jvmOverloads/varargs.kt +++ b/compiler/testData/codegen/box/jvmOverloads/varargs.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM // WITH_RUNTIME diff --git a/compiler/testData/codegen/box/package/mainInFiles.kt b/compiler/testData/codegen/box/package/mainInFiles.kt index 48bbd7ad905..423aa39d980 100644 --- a/compiler/testData/codegen/box/package/mainInFiles.kt +++ b/compiler/testData/codegen/box/package/mainInFiles.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM // WITH_RUNTIME diff --git a/compiler/testData/codegen/box/reflection/annotations/localClassLiteral.kt b/compiler/testData/codegen/box/reflection/annotations/localClassLiteral.kt index 1daaf72472e..7b50dad81a7 100644 --- a/compiler/testData/codegen/box/reflection/annotations/localClassLiteral.kt +++ b/compiler/testData/codegen/box/reflection/annotations/localClassLiteral.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM // WITH_REFLECT diff --git a/compiler/testData/codegen/box/reflection/classes/jvmNameOfStandardClasses.kt b/compiler/testData/codegen/box/reflection/classes/jvmNameOfStandardClasses.kt index db994d7ef83..302ffeaeeb8 100644 --- a/compiler/testData/codegen/box/reflection/classes/jvmNameOfStandardClasses.kt +++ b/compiler/testData/codegen/box/reflection/classes/jvmNameOfStandardClasses.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM // WITH_REFLECT diff --git a/compiler/testData/codegen/box/reflection/mapping/types/annotationConstructorParameters.kt b/compiler/testData/codegen/box/reflection/mapping/types/annotationConstructorParameters.kt index eeb42575d6e..80ef351b5b4 100644 --- a/compiler/testData/codegen/box/reflection/mapping/types/annotationConstructorParameters.kt +++ b/compiler/testData/codegen/box/reflection/mapping/types/annotationConstructorParameters.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM // WITH_REFLECT diff --git a/compiler/testData/codegen/box/reflection/mapping/types/array.kt b/compiler/testData/codegen/box/reflection/mapping/types/array.kt index ccbab6bae92..df4f7c3aa22 100644 --- a/compiler/testData/codegen/box/reflection/mapping/types/array.kt +++ b/compiler/testData/codegen/box/reflection/mapping/types/array.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM // WITH_REFLECT diff --git a/compiler/testData/codegen/box/reflection/supertypes/isSubclassOfIsSuperclassOf.kt b/compiler/testData/codegen/box/reflection/supertypes/isSubclassOfIsSuperclassOf.kt index a466f0858bb..3bf60712615 100644 --- a/compiler/testData/codegen/box/reflection/supertypes/isSubclassOfIsSuperclassOf.kt +++ b/compiler/testData/codegen/box/reflection/supertypes/isSubclassOfIsSuperclassOf.kt @@ -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 diff --git a/compiler/testData/codegen/box/reflection/types/classifierIsClass.kt b/compiler/testData/codegen/box/reflection/types/classifierIsClass.kt index 98180de90ab..1230ea7e07a 100644 --- a/compiler/testData/codegen/box/reflection/types/classifierIsClass.kt +++ b/compiler/testData/codegen/box/reflection/types/classifierIsClass.kt @@ -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 diff --git a/compiler/testData/codegen/box/reflection/types/jvmErasureOfClass.kt b/compiler/testData/codegen/box/reflection/types/jvmErasureOfClass.kt index c8845211670..bea77ac9c0f 100644 --- a/compiler/testData/codegen/box/reflection/types/jvmErasureOfClass.kt +++ b/compiler/testData/codegen/box/reflection/types/jvmErasureOfClass.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM // WITH_REFLECT diff --git a/compiler/testData/codegen/box/reflection/types/jvmErasureOfTypeParameter.kt b/compiler/testData/codegen/box/reflection/types/jvmErasureOfTypeParameter.kt index e6a94496695..0c30cd71cb7 100644 --- a/compiler/testData/codegen/box/reflection/types/jvmErasureOfTypeParameter.kt +++ b/compiler/testData/codegen/box/reflection/types/jvmErasureOfTypeParameter.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM // WITH_REFLECT diff --git a/compiler/testData/diagnostics/testsWithStdLib/when/noTypeArgumentsInConstructor.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/when/noTypeArgumentsInConstructor.fir.kt index 1c01b530832..b7212bcb280 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/when/noTypeArgumentsInConstructor.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/when/noTypeArgumentsInConstructor.fir.kt @@ -23,21 +23,21 @@ val test3: MutableList = } val test4: Collection = - listOf(1, 2, 3).flatMapTo(LinkedHashSet()) { - listOf(it) + listOf(1, 2, 3).flatMapTo(LinkedHashSet()) { + listOf(it) } val test5: Collection = - listOf(1, 2, 3).flatMapTo(LinkedHashSet()) { // TODO - if (true) listOf(it) else listOf(it) + listOf(1, 2, 3).flatMapTo(LinkedHashSet()) { // TODO + if (true) listOf(it) else listOf(it) } val test6: Collection = - listOf(1, 2, 3).flatMapTo(LinkedHashSet()) { - if (true) listOf(it) else listOf(it) + listOf(1, 2, 3).flatMapTo(LinkedHashSet()) { + if (true) listOf(it) else listOf(it) } val test7: Collection = - listOf(1, 2, 3).flatMapTo(LinkedHashSet()) { - select(listOf(it), listOf(it)) + listOf(1, 2, 3).flatMapTo(LinkedHashSet()) { + select(listOf(it), listOf(it)) } \ No newline at end of file