[FIR] Remove duplicated code

This commit is contained in:
simon.ogorodnik
2020-02-17 14:59:03 +03:00
parent c29c140a9c
commit 8ca2aa47f8
@@ -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 <K> select(vararg values: K): K
val functionSymbol = FirSyntheticFunctionSymbol(callableId)
private fun generateSyntheticSelectTypeParameter(): Pair<FirTypeParameter, FirResolvedTypeRef> {
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 <K> select(vararg values: K): K
val functionSymbol = FirSyntheticFunctionSymbol(callableId)
val (typeParameter, returnType) = generateSyntheticSelectTypeParameter()
val argumentType = buildResolvedTypeRef { type = returnType.coneTypeUnsafe<ConeKotlinType>().createArrayOf(session) }
val typeArgument = buildTypeProjectionWithVariance {
@@ -200,18 +204,7 @@ class FirSyntheticCallGenerator(
// fun <X> 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<ConeKotlinType>().withNullability(ConeNullability.NULLABLE, session.inferenceContext)