From 8ca2aa47f804c2ea7b6dd7a631127880e6935c4c Mon Sep 17 00:00:00 2001 From: "simon.ogorodnik" Date: Mon, 17 Feb 2020 14:59:03 +0300 Subject: [PATCH] [FIR] Remove duplicated code --- .../transformers/FirSyntheticCallGenerator.kt | 35 ++++++++----------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirSyntheticCallGenerator.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirSyntheticCallGenerator.kt index 9b1a719bf7b..16c1efccb29 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirSyntheticCallGenerator.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirSyntheticCallGenerator.kt @@ -8,10 +8,7 @@ package org.jetbrains.kotlin.fir.resolve.transformers import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.descriptors.Visibilities import org.jetbrains.kotlin.fir.FirElement -import org.jetbrains.kotlin.fir.declarations.FirResolvePhase -import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction -import org.jetbrains.kotlin.fir.declarations.FirValueParameter -import org.jetbrains.kotlin.fir.declarations.addDefaultBoundIfNecessary +import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.declarations.builder.FirSimpleFunctionBuilder import org.jetbrains.kotlin.fir.declarations.builder.buildTypeParameter import org.jetbrains.kotlin.fir.declarations.builder.buildValueParameter @@ -163,10 +160,7 @@ class FirSyntheticCallGenerator( implicitReceiverStack = implicitReceiverStack ) - private fun generateSyntheticSelectFunction(callableId: CallableId): FirSimpleFunction { - // Synthetic function signature: - // fun select(vararg values: K): K - val functionSymbol = FirSyntheticFunctionSymbol(callableId) + private fun generateSyntheticSelectTypeParameter(): Pair { val typeParameterSymbol = FirTypeParameterSymbol() val typeParameter = buildTypeParameter { @@ -178,7 +172,17 @@ class FirSyntheticCallGenerator( addDefaultBoundIfNecessary() } - val returnType = buildResolvedTypeRef { type = ConeTypeParameterTypeImpl(typeParameterSymbol.toLookupTag(), false) } + val typeParameterTypeRef = buildResolvedTypeRef { type = ConeTypeParameterTypeImpl(typeParameterSymbol.toLookupTag(), false) } + return typeParameter to typeParameterTypeRef + } + + + private fun generateSyntheticSelectFunction(callableId: CallableId): FirSimpleFunction { + // Synthetic function signature: + // fun select(vararg values: K): K + val functionSymbol = FirSyntheticFunctionSymbol(callableId) + + val (typeParameter, returnType) = generateSyntheticSelectTypeParameter() val argumentType = buildResolvedTypeRef { type = returnType.coneTypeUnsafe().createArrayOf(session) } val typeArgument = buildTypeProjectionWithVariance { @@ -200,18 +204,7 @@ class FirSyntheticCallGenerator( // fun test(a: X) = a!! // `X` is not a subtype of `Any` and hence cannot satisfy `K` if it had an upper bound of `Any`. val functionSymbol = FirSyntheticFunctionSymbol(SyntheticCallableId.CHECK_NOT_NULL) - val typeParameterSymbol = FirTypeParameterSymbol() - val typeParameter = - buildTypeParameter { - session = this@FirSyntheticCallGenerator.session - name = Name.identifier("K") - symbol = typeParameterSymbol - variance = Variance.INVARIANT - isReified = false - addDefaultBoundIfNecessary() - } - - val returnType = buildResolvedTypeRef { type = ConeTypeParameterTypeImpl(typeParameterSymbol.toLookupTag(), false) } + val (typeParameter, returnType) = generateSyntheticSelectTypeParameter() val argumentType = buildResolvedTypeRef { type = returnType.coneTypeUnsafe().withNullability(ConeNullability.NULLABLE, session.inferenceContext)