[FIR] Drop redundant FirIntegerOperatorCall and number of fir copy methods
This commit is contained in:
committed by
teamcity
parent
27901a55c4
commit
84913772ec
@@ -14,7 +14,6 @@ import org.jetbrains.kotlin.fir.expressions.*
|
|||||||
import org.jetbrains.kotlin.fir.references.FirErrorNamedReference
|
import org.jetbrains.kotlin.fir.references.FirErrorNamedReference
|
||||||
import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
|
import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
|
||||||
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
||||||
import org.jetbrains.kotlin.fir.scopes.impl.FirIntegerOperatorCall
|
|
||||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.SymbolInternals
|
import org.jetbrains.kotlin.fir.symbols.SymbolInternals
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||||
@@ -52,10 +51,6 @@ internal fun checkConstantArguments(
|
|||||||
expression is FirComparisonExpression -> {
|
expression is FirComparisonExpression -> {
|
||||||
return checkConstantArguments(expression.compareToCall, session)
|
return checkConstantArguments(expression.compareToCall, session)
|
||||||
}
|
}
|
||||||
expression is FirIntegerOperatorCall -> {
|
|
||||||
for (exp in (expression as FirCall).arguments.plus(expression.dispatchReceiver))
|
|
||||||
checkConstantArguments(exp, session).let { return it }
|
|
||||||
}
|
|
||||||
expression is FirStringConcatenationCall || expression is FirEqualityOperatorCall -> {
|
expression is FirStringConcatenationCall || expression is FirEqualityOperatorCall -> {
|
||||||
for (exp in (expression as FirCall).arguments)
|
for (exp in (expression as FirCall).arguments)
|
||||||
checkConstantArguments(exp, session).let { return it }
|
checkConstantArguments(exp, session).let { return it }
|
||||||
|
|||||||
+3
-19
@@ -13,7 +13,6 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
|||||||
import org.jetbrains.kotlin.diagnostics.reportOn
|
import org.jetbrains.kotlin.diagnostics.reportOn
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirConstExpression
|
import org.jetbrains.kotlin.fir.expressions.FirConstExpression
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirFunctionCall
|
import org.jetbrains.kotlin.fir.expressions.FirFunctionCall
|
||||||
import org.jetbrains.kotlin.fir.scopes.impl.FirIntegerOperatorCall
|
|
||||||
|
|
||||||
object EmptyRangeChecker : FirFunctionCallChecker() {
|
object EmptyRangeChecker : FirFunctionCallChecker() {
|
||||||
override fun check(expression: FirFunctionCall, context: CheckerContext, reporter: DiagnosticReporter) {
|
override fun check(expression: FirFunctionCall, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||||
@@ -41,27 +40,12 @@ object EmptyRangeChecker : FirFunctionCallChecker() {
|
|||||||
|
|
||||||
private val FirFunctionCall.rangeLeft: Long?
|
private val FirFunctionCall.rangeLeft: Long?
|
||||||
get() {
|
get() {
|
||||||
return if (explicitReceiver is FirIntegerOperatorCall) {
|
return (explicitReceiver as? FirConstExpression<*>)?.value as? Long
|
||||||
(explicitReceiver as? FirIntegerOperatorCall)?.asLong
|
|
||||||
} else {
|
|
||||||
(explicitReceiver as? FirConstExpression<*>)?.value as? Long
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private val FirFunctionCall.rangeRight: Long?
|
private val FirFunctionCall.rangeRight: Long?
|
||||||
get() {
|
get() {
|
||||||
val arg = argumentList.arguments.getOrNull(0)
|
val arg = argumentList.arguments.getOrNull(0) as? FirConstExpression<*>
|
||||||
return if (arg is FirIntegerOperatorCall) arg.asLong
|
return arg?.value as? Long
|
||||||
else (arg as? FirConstExpression<*>)?.value as? Long
|
|
||||||
}
|
|
||||||
|
|
||||||
// todo: add proper integer operator calls checking (e.g. (1+2)*3 transforms to 9)
|
|
||||||
private val FirIntegerOperatorCall.asLong: Long?
|
|
||||||
get() {
|
|
||||||
val value = (dispatchReceiver as? FirConstExpression<*>)?.value as Long? ?: return null
|
|
||||||
if (this.calleeReference.name.asString() == "unaryMinus") {
|
|
||||||
return -value
|
|
||||||
}
|
|
||||||
return value
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,60 +5,21 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.fir
|
package org.jetbrains.kotlin.fir
|
||||||
|
|
||||||
import org.jetbrains.kotlin.KtSourceElement
|
|
||||||
import org.jetbrains.kotlin.contracts.description.EventOccurrencesRange
|
|
||||||
import org.jetbrains.kotlin.descriptors.EffectiveVisibility
|
import org.jetbrains.kotlin.descriptors.EffectiveVisibility
|
||||||
import org.jetbrains.kotlin.descriptors.Modality
|
import org.jetbrains.kotlin.descriptors.Modality
|
||||||
import org.jetbrains.kotlin.descriptors.Visibility
|
import org.jetbrains.kotlin.descriptors.Visibility
|
||||||
import org.jetbrains.kotlin.fir.declarations.*
|
import org.jetbrains.kotlin.fir.declarations.FirDeclarationStatus
|
||||||
import org.jetbrains.kotlin.fir.declarations.builder.buildAnonymousFunction
|
import org.jetbrains.kotlin.fir.declarations.FirTypeParameter
|
||||||
import org.jetbrains.kotlin.fir.declarations.builder.buildTypeParameter
|
import org.jetbrains.kotlin.fir.declarations.builder.buildTypeParameter
|
||||||
import org.jetbrains.kotlin.fir.declarations.impl.FirDeclarationStatusImpl
|
import org.jetbrains.kotlin.fir.declarations.impl.FirDeclarationStatusImpl
|
||||||
import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic
|
import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic
|
||||||
import org.jetbrains.kotlin.fir.expressions.*
|
import org.jetbrains.kotlin.fir.expressions.*
|
||||||
import org.jetbrains.kotlin.fir.expressions.builder.*
|
import org.jetbrains.kotlin.fir.expressions.builder.*
|
||||||
import org.jetbrains.kotlin.fir.references.FirControlFlowGraphReference
|
|
||||||
import org.jetbrains.kotlin.fir.references.FirNamedReference
|
|
||||||
import org.jetbrains.kotlin.fir.references.FirReference
|
import org.jetbrains.kotlin.fir.references.FirReference
|
||||||
import org.jetbrains.kotlin.fir.scopes.impl.FirIntegerOperatorCall
|
|
||||||
import org.jetbrains.kotlin.fir.scopes.impl.FirIntegerOperatorCallBuilder
|
|
||||||
import org.jetbrains.kotlin.fir.types.*
|
import org.jetbrains.kotlin.fir.types.*
|
||||||
import org.jetbrains.kotlin.fir.types.builder.buildErrorTypeRef
|
import org.jetbrains.kotlin.fir.types.builder.buildErrorTypeRef
|
||||||
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
|
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
|
||||||
|
|
||||||
fun FirFunctionCall.copy(
|
|
||||||
annotations: List<FirAnnotation> = this.annotations,
|
|
||||||
argumentList: FirArgumentList = this.argumentList,
|
|
||||||
calleeReference: FirNamedReference = this.calleeReference,
|
|
||||||
explicitReceiver: FirExpression? = this.explicitReceiver,
|
|
||||||
dispatchReceiver: FirExpression = this.dispatchReceiver,
|
|
||||||
extensionReceiver: FirExpression = this.extensionReceiver,
|
|
||||||
source: KtSourceElement? = this.source,
|
|
||||||
typeArguments: List<FirTypeProjection> = this.typeArguments,
|
|
||||||
resultType: FirTypeRef = this.typeRef
|
|
||||||
): FirFunctionCall {
|
|
||||||
val builder = if (this is FirIntegerOperatorCall) {
|
|
||||||
FirIntegerOperatorCallBuilder().apply {
|
|
||||||
this.calleeReference = calleeReference
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
FirFunctionCallBuilder().apply {
|
|
||||||
this.calleeReference = calleeReference
|
|
||||||
}
|
|
||||||
}
|
|
||||||
builder.apply {
|
|
||||||
this.source = source
|
|
||||||
this.annotations.addAll(annotations)
|
|
||||||
this.argumentList = argumentList
|
|
||||||
this.explicitReceiver = explicitReceiver
|
|
||||||
this.dispatchReceiver = dispatchReceiver
|
|
||||||
this.extensionReceiver = extensionReceiver
|
|
||||||
this.typeArguments.addAll(typeArguments)
|
|
||||||
this.typeRef = resultType
|
|
||||||
}
|
|
||||||
return (builder as FirCallBuilder).build() as FirFunctionCall
|
|
||||||
}
|
|
||||||
|
|
||||||
inline fun FirFunctionCall.copyAsImplicitInvokeCall(
|
inline fun FirFunctionCall.copyAsImplicitInvokeCall(
|
||||||
setupCopy: FirImplicitInvokeCallBuilder.() -> Unit
|
setupCopy: FirImplicitInvokeCallBuilder.() -> Unit
|
||||||
): FirImplicitInvokeCall {
|
): FirImplicitInvokeCall {
|
||||||
@@ -78,39 +39,6 @@ inline fun FirFunctionCall.copyAsImplicitInvokeCall(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun FirAnonymousFunction.copy(
|
|
||||||
receiverTypeRef: FirTypeRef? = this.receiverTypeRef,
|
|
||||||
source: KtSourceElement? = this.source,
|
|
||||||
moduleData: FirModuleData = this.moduleData,
|
|
||||||
origin: FirDeclarationOrigin = this.origin,
|
|
||||||
returnTypeRef: FirTypeRef = this.returnTypeRef,
|
|
||||||
valueParameters: List<FirValueParameter> = this.valueParameters,
|
|
||||||
body: FirBlock? = this.body,
|
|
||||||
annotations: List<FirAnnotation> = this.annotations,
|
|
||||||
typeRef: FirTypeRef = this.typeRef,
|
|
||||||
label: FirLabel? = this.label,
|
|
||||||
controlFlowGraphReference: FirControlFlowGraphReference? = this.controlFlowGraphReference,
|
|
||||||
invocationKind: EventOccurrencesRange? = this.invocationKind
|
|
||||||
): FirAnonymousFunction {
|
|
||||||
return buildAnonymousFunction {
|
|
||||||
this.source = source
|
|
||||||
this.moduleData = moduleData
|
|
||||||
this.origin = origin
|
|
||||||
this.returnTypeRef = returnTypeRef
|
|
||||||
this.receiverTypeRef = receiverTypeRef
|
|
||||||
symbol = this@copy.symbol
|
|
||||||
isLambda = this@copy.isLambda
|
|
||||||
hasExplicitParameterList = this@copy.hasExplicitParameterList
|
|
||||||
this.valueParameters.addAll(valueParameters)
|
|
||||||
this.body = body
|
|
||||||
this.annotations.addAll(annotations)
|
|
||||||
this.typeRef = typeRef
|
|
||||||
this.label = label
|
|
||||||
this.controlFlowGraphReference = controlFlowGraphReference
|
|
||||||
this.invocationKind = invocationKind
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun FirTypeRef.resolvedTypeFromPrototype(
|
fun FirTypeRef.resolvedTypeFromPrototype(
|
||||||
type: ConeKotlinType
|
type: ConeKotlinType
|
||||||
): FirResolvedTypeRef {
|
): FirResolvedTypeRef {
|
||||||
@@ -138,65 +66,6 @@ fun FirTypeRef.errorTypeFromPrototype(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun FirTypeParameter.copy(
|
|
||||||
bounds: List<FirTypeRef> = this.bounds,
|
|
||||||
annotations: List<FirAnnotation> = this.annotations
|
|
||||||
): FirTypeParameter {
|
|
||||||
return buildTypeParameter {
|
|
||||||
source = this@copy.source
|
|
||||||
resolvePhase = this@copy.resolvePhase
|
|
||||||
moduleData = this@copy.moduleData
|
|
||||||
name = this@copy.name
|
|
||||||
symbol = this@copy.symbol
|
|
||||||
variance = this@copy.variance
|
|
||||||
isReified = this@copy.isReified
|
|
||||||
this.bounds += bounds
|
|
||||||
this.annotations += annotations
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun FirWhenExpression.copy(
|
|
||||||
resultType: FirTypeRef = this.typeRef,
|
|
||||||
calleeReference: FirReference = this.calleeReference,
|
|
||||||
annotations: List<FirAnnotation> = this.annotations
|
|
||||||
): FirWhenExpression = buildWhenExpression {
|
|
||||||
source = this@copy.source
|
|
||||||
subject = this@copy.subject
|
|
||||||
subjectVariable = this@copy.subjectVariable
|
|
||||||
this.calleeReference = calleeReference
|
|
||||||
branches += this@copy.branches
|
|
||||||
typeRef = resultType
|
|
||||||
this.annotations += annotations
|
|
||||||
usedAsExpression = this@copy.usedAsExpression
|
|
||||||
exhaustivenessStatus = this@copy.exhaustivenessStatus
|
|
||||||
}
|
|
||||||
|
|
||||||
fun FirTryExpression.copy(
|
|
||||||
resultType: FirTypeRef = this.typeRef,
|
|
||||||
calleeReference: FirReference = this.calleeReference,
|
|
||||||
annotations: List<FirAnnotation> = this.annotations
|
|
||||||
): FirTryExpression = buildTryExpression {
|
|
||||||
source = this@copy.source
|
|
||||||
tryBlock = this@copy.tryBlock
|
|
||||||
finallyBlock = this@copy.finallyBlock
|
|
||||||
this.calleeReference = calleeReference
|
|
||||||
catches += this@copy.catches
|
|
||||||
typeRef = resultType
|
|
||||||
this.annotations += annotations
|
|
||||||
}
|
|
||||||
|
|
||||||
fun FirCheckNotNullCall.copy(
|
|
||||||
resultType: FirTypeRef = this.typeRef,
|
|
||||||
calleeReference: FirReference = this.calleeReference,
|
|
||||||
annotations: List<FirAnnotation> = this.annotations
|
|
||||||
): FirCheckNotNullCall = buildCheckNotNullCall {
|
|
||||||
source = this@copy.source
|
|
||||||
this.calleeReference = calleeReference
|
|
||||||
argumentList = this@copy.argumentList
|
|
||||||
this.typeRef = resultType
|
|
||||||
this.annotations += annotations
|
|
||||||
}
|
|
||||||
|
|
||||||
fun FirDeclarationStatus.copy(
|
fun FirDeclarationStatus.copy(
|
||||||
isExpect: Boolean = this.isExpect,
|
isExpect: Boolean = this.isExpect,
|
||||||
newModality: Modality? = null,
|
newModality: Modality? = null,
|
||||||
|
|||||||
-81
@@ -1,81 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.fir.scopes.impl
|
|
||||||
|
|
||||||
import org.jetbrains.kotlin.KtSourceElement
|
|
||||||
import org.jetbrains.kotlin.fir.FirImplementationDetail
|
|
||||||
import org.jetbrains.kotlin.fir.builder.FirAnnotationContainerBuilder
|
|
||||||
import org.jetbrains.kotlin.fir.builder.FirBuilderDsl
|
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
|
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirArgumentList
|
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirFunctionCallOrigin
|
|
||||||
import org.jetbrains.kotlin.fir.expressions.builder.FirCallBuilder
|
|
||||||
import org.jetbrains.kotlin.fir.expressions.builder.FirExpressionBuilder
|
|
||||||
import org.jetbrains.kotlin.fir.expressions.builder.FirQualifiedAccessBuilder
|
|
||||||
import org.jetbrains.kotlin.fir.expressions.impl.FirFunctionCallImpl
|
|
||||||
import org.jetbrains.kotlin.fir.expressions.impl.FirNoReceiverExpression
|
|
||||||
import org.jetbrains.kotlin.fir.references.FirNamedReference
|
|
||||||
import org.jetbrains.kotlin.fir.types.FirTypeProjection
|
|
||||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
|
||||||
import org.jetbrains.kotlin.fir.types.builder.buildImplicitTypeRef
|
|
||||||
|
|
||||||
@OptIn(FirImplementationDetail::class)
|
|
||||||
class FirIntegerOperatorCall @FirImplementationDetail constructor(
|
|
||||||
source: KtSourceElement?,
|
|
||||||
typeRef: FirTypeRef,
|
|
||||||
annotations: MutableList<FirAnnotation>,
|
|
||||||
typeArguments: MutableList<FirTypeProjection>,
|
|
||||||
explicitReceiver: FirExpression?,
|
|
||||||
dispatchReceiver: FirExpression,
|
|
||||||
extensionReceiver: FirExpression,
|
|
||||||
argumentList: FirArgumentList,
|
|
||||||
calleeReference: FirNamedReference,
|
|
||||||
) : FirFunctionCallImpl(
|
|
||||||
source,
|
|
||||||
typeRef,
|
|
||||||
annotations,
|
|
||||||
typeArguments,
|
|
||||||
explicitReceiver,
|
|
||||||
dispatchReceiver,
|
|
||||||
extensionReceiver,
|
|
||||||
argumentList,
|
|
||||||
calleeReference,
|
|
||||||
FirFunctionCallOrigin.Operator
|
|
||||||
)
|
|
||||||
|
|
||||||
@FirBuilderDsl
|
|
||||||
class FirIntegerOperatorCallBuilder : FirQualifiedAccessBuilder, FirCallBuilder, FirAnnotationContainerBuilder, FirExpressionBuilder {
|
|
||||||
override var source: KtSourceElement? = null
|
|
||||||
override var typeRef: FirTypeRef = buildImplicitTypeRef()
|
|
||||||
override val annotations: MutableList<FirAnnotation> = mutableListOf()
|
|
||||||
override val typeArguments: MutableList<FirTypeProjection> = mutableListOf()
|
|
||||||
override var explicitReceiver: FirExpression? = null
|
|
||||||
override var dispatchReceiver: FirExpression = FirNoReceiverExpression
|
|
||||||
override var extensionReceiver: FirExpression = FirNoReceiverExpression
|
|
||||||
lateinit var calleeReference: FirNamedReference
|
|
||||||
override lateinit var argumentList: FirArgumentList
|
|
||||||
|
|
||||||
@OptIn(FirImplementationDetail::class)
|
|
||||||
override fun build(): FirIntegerOperatorCall {
|
|
||||||
return FirIntegerOperatorCall(
|
|
||||||
source,
|
|
||||||
typeRef,
|
|
||||||
annotations,
|
|
||||||
typeArguments,
|
|
||||||
explicitReceiver,
|
|
||||||
dispatchReceiver,
|
|
||||||
extensionReceiver,
|
|
||||||
argumentList,
|
|
||||||
calleeReference,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
inline fun buildIntegerOperatorFunctionCall(init: FirIntegerOperatorCallBuilder.() -> Unit): FirIntegerOperatorCall {
|
|
||||||
return FirIntegerOperatorCallBuilder().apply(init).build()
|
|
||||||
}
|
|
||||||
+23
-37
@@ -41,7 +41,6 @@ import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirArrayOfCall
|
|||||||
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.remapArgumentsWithVararg
|
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.remapArgumentsWithVararg
|
||||||
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.resultType
|
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.resultType
|
||||||
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.writeResultType
|
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.writeResultType
|
||||||
import org.jetbrains.kotlin.fir.scopes.impl.FirIntegerOperatorCall
|
|
||||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirConstructorSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirConstructorSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
|
||||||
@@ -195,50 +194,37 @@ class FirCallCompletionResultsWriterTransformer(
|
|||||||
override fun transformFunctionCall(functionCall: FirFunctionCall, data: ExpectedArgumentType?): FirStatement {
|
override fun transformFunctionCall(functionCall: FirFunctionCall, data: ExpectedArgumentType?): FirStatement {
|
||||||
val calleeReference = functionCall.calleeReference as? FirNamedReferenceWithCandidate
|
val calleeReference = functionCall.calleeReference as? FirNamedReferenceWithCandidate
|
||||||
?: return functionCall
|
?: return functionCall
|
||||||
var result = prepareQualifiedTransform(functionCall, calleeReference)
|
val result = prepareQualifiedTransform(functionCall, calleeReference)
|
||||||
val typeRef = result.typeRef as FirResolvedTypeRef
|
val typeRef = result.typeRef as FirResolvedTypeRef
|
||||||
val subCandidate = calleeReference.candidate
|
val subCandidate = calleeReference.candidate
|
||||||
val resultType: FirTypeRef
|
val resultType: FirTypeRef
|
||||||
result = when (result) {
|
resultType = typeRef.substituteTypeRef(subCandidate)
|
||||||
is FirIntegerOperatorCall -> {
|
val expectedArgumentsTypeMapping = runIf(!calleeReference.isError) { subCandidate.createArgumentsMapping() }
|
||||||
val expectedType = data?.getExpectedType(functionCall)
|
result.argumentList.transformArguments(this, expectedArgumentsTypeMapping)
|
||||||
resultType =
|
if (calleeReference.isError) {
|
||||||
typeRef.resolvedTypeFromPrototype(typeRef.coneTypeUnsafe<ConeIntegerLiteralType>().getApproximatedType(expectedType))
|
subCandidate.argumentMapping?.let {
|
||||||
result.argumentList.transformArguments(this, expectedType?.toExpectedType())
|
result.replaceArgumentList(buildArgumentListForErrorCall(result.argumentList, it))
|
||||||
result
|
|
||||||
}
|
}
|
||||||
else -> {
|
} else {
|
||||||
resultType = typeRef.substituteTypeRef(subCandidate)
|
subCandidate.handleVarargs()
|
||||||
val expectedArgumentsTypeMapping = runIf(!calleeReference.isError) { subCandidate.createArgumentsMapping() }
|
subCandidate.argumentMapping?.let {
|
||||||
result.argumentList.transformArguments(this, expectedArgumentsTypeMapping)
|
val newArgumentList = buildResolvedArgumentList(it, source = functionCall.argumentList.source)
|
||||||
if (calleeReference.isError) {
|
val symbol = subCandidate.symbol
|
||||||
subCandidate.argumentMapping?.let {
|
val functionIsInline =
|
||||||
result.replaceArgumentList(buildArgumentListForErrorCall(result.argumentList, it))
|
(symbol as? FirNamedFunctionSymbol)?.fir?.isInline == true || symbol.isArrayConstructorWithLambda
|
||||||
}
|
for ((argument, parameter) in newArgumentList.mapping) {
|
||||||
} else {
|
val lambda = (argument.unwrapArgument() as? FirAnonymousFunctionExpression)?.anonymousFunction ?: continue
|
||||||
subCandidate.handleVarargs()
|
val inlineStatus = when {
|
||||||
subCandidate.argumentMapping?.let {
|
parameter.isCrossinline && functionIsInline -> InlineStatus.CrossInline
|
||||||
val newArgumentList = buildResolvedArgumentList(it, source = functionCall.argumentList.source)
|
parameter.isNoinline -> InlineStatus.NoInline
|
||||||
val symbol = subCandidate.symbol
|
functionIsInline -> InlineStatus.Inline
|
||||||
val functionIsInline =
|
else -> InlineStatus.NoInline
|
||||||
(symbol as? FirNamedFunctionSymbol)?.fir?.isInline == true || symbol.isArrayConstructorWithLambda
|
|
||||||
for ((argument, parameter) in newArgumentList.mapping) {
|
|
||||||
val lambda = (argument.unwrapArgument() as? FirAnonymousFunctionExpression)?.anonymousFunction ?: continue
|
|
||||||
val inlineStatus = when {
|
|
||||||
parameter.isCrossinline && functionIsInline -> InlineStatus.CrossInline
|
|
||||||
parameter.isNoinline -> InlineStatus.NoInline
|
|
||||||
functionIsInline -> InlineStatus.Inline
|
|
||||||
else -> InlineStatus.NoInline
|
|
||||||
}
|
|
||||||
lambda.replaceInlineStatus(inlineStatus)
|
|
||||||
}
|
|
||||||
result.replaceArgumentList(newArgumentList)
|
|
||||||
}
|
}
|
||||||
|
lambda.replaceInlineStatus(inlineStatus)
|
||||||
}
|
}
|
||||||
result
|
result.replaceArgumentList(newArgumentList)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result.replaceTypeRef(resultType)
|
result.replaceTypeRef(resultType)
|
||||||
session.lookupTracker?.recordTypeResolveAsLookup(resultType, functionCall.source, null)
|
session.lookupTracker?.recordTypeResolveAsLookup(resultType, functionCall.source, null)
|
||||||
|
|
||||||
|
|||||||
+7
-5
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.descriptors.Visibility
|
|||||||
import org.jetbrains.kotlin.fakeElement
|
import org.jetbrains.kotlin.fakeElement
|
||||||
import org.jetbrains.kotlin.fir.*
|
import org.jetbrains.kotlin.fir.*
|
||||||
import org.jetbrains.kotlin.fir.declarations.*
|
import org.jetbrains.kotlin.fir.declarations.*
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.builder.buildAnonymousFunctionCopy
|
||||||
import org.jetbrains.kotlin.fir.declarations.builder.buildValueParameter
|
import org.jetbrains.kotlin.fir.declarations.builder.buildValueParameter
|
||||||
import org.jetbrains.kotlin.fir.declarations.impl.FirDeclarationStatusImpl
|
import org.jetbrains.kotlin.fir.declarations.impl.FirDeclarationStatusImpl
|
||||||
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyAccessor
|
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyAccessor
|
||||||
@@ -801,14 +802,15 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor
|
|||||||
}
|
}
|
||||||
val returnTypeRefFromResolvedAtom =
|
val returnTypeRefFromResolvedAtom =
|
||||||
resolvedLambdaAtom?.returnType?.let { lambda.returnTypeRef.resolvedTypeFromPrototype(it) }
|
resolvedLambdaAtom?.returnType?.let { lambda.returnTypeRef.resolvedTypeFromPrototype(it) }
|
||||||
lambda = lambda.copy(
|
lambda = buildAnonymousFunctionCopy(lambda) {
|
||||||
receiverTypeRef = lambda.receiverTypeRef?.takeIf { it !is FirImplicitTypeRef }
|
receiverTypeRef = lambda.receiverTypeRef?.takeIf { it !is FirImplicitTypeRef }
|
||||||
?: resolvedLambdaAtom?.receiver?.let { lambda.receiverTypeRef?.resolvedTypeFromPrototype(it) },
|
?: resolvedLambdaAtom?.receiver?.let { lambda.receiverTypeRef?.resolvedTypeFromPrototype(it) }
|
||||||
valueParameters = valueParameters,
|
this.valueParameters.clear()
|
||||||
|
this.valueParameters.addAll(valueParameters)
|
||||||
returnTypeRef = (lambda.returnTypeRef as? FirResolvedTypeRef)
|
returnTypeRef = (lambda.returnTypeRef as? FirResolvedTypeRef)
|
||||||
?: returnTypeRefFromResolvedAtom
|
?: returnTypeRefFromResolvedAtom
|
||||||
?: lambda.returnTypeRef
|
?: lambda.returnTypeRef
|
||||||
)
|
}
|
||||||
lambda = lambda.transformValueParameters(ImplicitToErrorTypeTransformer, null)
|
lambda = lambda.transformValueParameters(ImplicitToErrorTypeTransformer, null)
|
||||||
val bodyExpectedType = returnTypeRefFromResolvedAtom ?: expectedTypeRef
|
val bodyExpectedType = returnTypeRefFromResolvedAtom ?: expectedTypeRef
|
||||||
context.withAnonymousFunction(lambda, components, data) {
|
context.withAnonymousFunction(lambda, components, data) {
|
||||||
|
|||||||
+30
@@ -112,3 +112,33 @@ inline fun buildAnonymousFunction(init: FirAnonymousFunctionBuilder.() -> Unit):
|
|||||||
}
|
}
|
||||||
return FirAnonymousFunctionBuilder().apply(init).build()
|
return FirAnonymousFunctionBuilder().apply(init).build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalContracts::class)
|
||||||
|
inline fun buildAnonymousFunctionCopy(original: FirAnonymousFunction, init: FirAnonymousFunctionBuilder.() -> Unit): FirAnonymousFunction {
|
||||||
|
contract {
|
||||||
|
callsInPlace(init, kotlin.contracts.InvocationKind.EXACTLY_ONCE)
|
||||||
|
}
|
||||||
|
val copyBuilder = FirAnonymousFunctionBuilder()
|
||||||
|
copyBuilder.source = original.source
|
||||||
|
copyBuilder.annotations.addAll(original.annotations)
|
||||||
|
copyBuilder.moduleData = original.moduleData
|
||||||
|
copyBuilder.origin = original.origin
|
||||||
|
copyBuilder.attributes = original.attributes.copy()
|
||||||
|
copyBuilder.returnTypeRef = original.returnTypeRef
|
||||||
|
copyBuilder.receiverTypeRef = original.receiverTypeRef
|
||||||
|
copyBuilder.deprecation = original.deprecation
|
||||||
|
copyBuilder.containerSource = original.containerSource
|
||||||
|
copyBuilder.dispatchReceiverType = original.dispatchReceiverType
|
||||||
|
copyBuilder.controlFlowGraphReference = original.controlFlowGraphReference
|
||||||
|
copyBuilder.valueParameters.addAll(original.valueParameters)
|
||||||
|
copyBuilder.body = original.body
|
||||||
|
copyBuilder.symbol = original.symbol
|
||||||
|
copyBuilder.label = original.label
|
||||||
|
copyBuilder.invocationKind = original.invocationKind
|
||||||
|
copyBuilder.inlineStatus = original.inlineStatus
|
||||||
|
copyBuilder.isLambda = original.isLambda
|
||||||
|
copyBuilder.hasExplicitParameterList = original.hasExplicitParameterList
|
||||||
|
copyBuilder.typeParameters.addAll(original.typeParameters)
|
||||||
|
copyBuilder.typeRef = original.typeRef
|
||||||
|
return copyBuilder.apply(init).build()
|
||||||
|
}
|
||||||
|
|||||||
+1
@@ -233,6 +233,7 @@ object BuilderConfigurator : AbstractBuilderConfigurator<FirTreeBuilder>(FirTree
|
|||||||
parents += functionBuilder
|
parents += functionBuilder
|
||||||
defaultNull("invocationKind", "label", "body", "controlFlowGraphReference")
|
defaultNull("invocationKind", "label", "body", "controlFlowGraphReference")
|
||||||
default("inlineStatus", "InlineStatus.Unknown")
|
default("inlineStatus", "InlineStatus.Unknown")
|
||||||
|
withCopy()
|
||||||
}
|
}
|
||||||
|
|
||||||
builder(propertyAccessor) {
|
builder(propertyAccessor) {
|
||||||
|
|||||||
Reference in New Issue
Block a user