[FIR] Consistently use _function_ instead of _functional_ in names of classes and functions
This commit is contained in:
committed by
Space Team
parent
f268ab8858
commit
89c42e20c9
+2
-2
@@ -18,7 +18,7 @@ import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirAbstractBodyResolveTransformer
|
||||
import org.jetbrains.kotlin.fir.types.classId
|
||||
import org.jetbrains.kotlin.fir.types.coneType
|
||||
import org.jetbrains.kotlin.fir.types.isSomeFunctionalType
|
||||
import org.jetbrains.kotlin.fir.types.isSomeFunctionType
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintSystemCompletionMode
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.OVERLOAD_RESOLUTION_BY_LAMBDA_ANNOTATION_CLASS_ID
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.same
|
||||
@@ -104,7 +104,7 @@ class FirOverloadByLambdaReturnTypeResolver(
|
||||
.values.singleOrNull()?.toMap() ?: return null
|
||||
|
||||
if (!lambdas.values.same { it.parameters.size }) return null
|
||||
if (!lambdas.values.all { it.expectedType?.isSomeFunctionalType(session) == true }) return null
|
||||
if (!lambdas.values.all { it.expectedType?.isSomeFunctionType(session) == true }) return null
|
||||
|
||||
val originalCalleeReference = call.calleeReference
|
||||
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ abstract class FirSamConversionTransformerExtension(session: FirSession) : FirEx
|
||||
|
||||
final override val extensionType: KClass<out FirExtension> = FirSamConversionTransformerExtension::class
|
||||
|
||||
abstract fun getCustomFunctionalTypeForSamConversion(function: FirSimpleFunction): ConeLookupTagBasedType?
|
||||
abstract fun getCustomFunctionTypeForSamConversion(function: FirSimpleFunction): ConeLookupTagBasedType?
|
||||
|
||||
fun interface Factory : FirExtension.Factory<FirSamConversionTransformerExtension>
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ package org.jetbrains.kotlin.fir.resolve
|
||||
|
||||
import org.jetbrains.kotlin.KtFakeSourceElementKind
|
||||
import org.jetbrains.kotlin.KtSourceElement
|
||||
import org.jetbrains.kotlin.builtins.functions.FunctionalTypeKind
|
||||
import org.jetbrains.kotlin.builtins.functions.FunctionTypeKind
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
@@ -88,9 +88,9 @@ fun FirAnonymousFunction.addReturnToLastStatementIfNeeded() {
|
||||
}
|
||||
|
||||
/**
|
||||
* [kind] == null means that [FunctionalTypeKind.Function] will be used
|
||||
* [kind] == null means that [FunctionTypeKind.Function] will be used
|
||||
*/
|
||||
fun FirFunction.constructFunctionalType(kind: FunctionalTypeKind? = null): ConeLookupTagBasedType {
|
||||
fun FirFunction.constructFunctionType(kind: FunctionTypeKind? = null): ConeLookupTagBasedType {
|
||||
val receiverTypeRef = when (this) {
|
||||
is FirSimpleFunction -> receiverParameter
|
||||
is FirAnonymousFunction -> receiverParameter
|
||||
@@ -107,28 +107,28 @@ fun FirFunction.constructFunctionalType(kind: FunctionalTypeKind? = null): ConeL
|
||||
}
|
||||
val rawReturnType = (this as FirCallableDeclaration).returnTypeRef.coneType
|
||||
|
||||
return createFunctionalType(
|
||||
kind ?: FunctionalTypeKind.Function, parameters, receiverTypeRef?.coneType, rawReturnType,
|
||||
return createFunctionType(
|
||||
kind ?: FunctionTypeKind.Function, parameters, receiverTypeRef?.coneType, rawReturnType,
|
||||
contextReceivers = contextReceivers.map { it.typeRef.coneType }
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* [kind] == null means that [FunctionalTypeKind.Function] will be used
|
||||
* [kind] == null means that [FunctionTypeKind.Function] will be used
|
||||
*/
|
||||
fun FirAnonymousFunction.constructFunctionalTypeRef(session: FirSession, kind: FunctionalTypeKind? = null): FirResolvedTypeRef {
|
||||
fun FirAnonymousFunction.constructFunctionTypeRef(session: FirSession, kind: FunctionTypeKind? = null): FirResolvedTypeRef {
|
||||
var diagnostic: ConeDiagnostic? = null
|
||||
val kinds = session.functionalTypeService.extractAllSpecialKindsForFunction(symbol)
|
||||
val kinds = session.functionTypeService.extractAllSpecialKindsForFunction(symbol)
|
||||
val kindFromDeclaration = when(kinds.size) {
|
||||
0 -> null
|
||||
1 -> kinds.single()
|
||||
else -> {
|
||||
diagnostic = ConeAmbiguousFunctionalTypeKinds(kinds)
|
||||
FunctionalTypeKind.Function
|
||||
diagnostic = ConeAmbiguousFunctionTypeKinds(kinds)
|
||||
FunctionTypeKind.Function
|
||||
}
|
||||
}
|
||||
val type = constructFunctionalType(kindFromDeclaration ?: kind)
|
||||
val source = this@constructFunctionalTypeRef.source?.fakeElement(KtFakeSourceElementKind.ImplicitTypeRef)
|
||||
val type = constructFunctionType(kindFromDeclaration ?: kind)
|
||||
val source = this@constructFunctionTypeRef.source?.fakeElement(KtFakeSourceElementKind.ImplicitTypeRef)
|
||||
return if (diagnostic == null) {
|
||||
buildResolvedTypeRef {
|
||||
this.source = source
|
||||
@@ -143,8 +143,8 @@ fun FirAnonymousFunction.constructFunctionalTypeRef(session: FirSession, kind: F
|
||||
}
|
||||
}
|
||||
|
||||
fun createFunctionalType(
|
||||
kind: FunctionalTypeKind,
|
||||
fun createFunctionType(
|
||||
kind: FunctionTypeKind,
|
||||
parameters: List<ConeKotlinType>,
|
||||
receiverType: ConeKotlinType?,
|
||||
rawReturnType: ConeKotlinType,
|
||||
@@ -158,7 +158,7 @@ fun createFunctionalType(
|
||||
add(rawReturnType)
|
||||
}
|
||||
|
||||
val functionalTypeId = ClassId(kind.packageFqName, kind.numberedClassName(receiverAndParameterTypes.size - 1))
|
||||
val functionTypeId = ClassId(kind.packageFqName, kind.numberedClassName(receiverAndParameterTypes.size - 1))
|
||||
val attributes = when {
|
||||
contextReceivers.isNotEmpty() -> ConeAttributes.create(
|
||||
buildList {
|
||||
@@ -172,7 +172,7 @@ fun createFunctionalType(
|
||||
else -> ConeAttributes.Empty
|
||||
}
|
||||
return ConeClassLikeTypeImpl(
|
||||
functionalTypeId.toLookupTag(),
|
||||
functionTypeId.toLookupTag(),
|
||||
receiverAndParameterTypes.toTypedArray(),
|
||||
isNullable = false,
|
||||
attributes = attributes
|
||||
@@ -592,7 +592,7 @@ fun FirFunction.getAsForbiddenNamedArgumentsTarget(
|
||||
result
|
||||
}
|
||||
// referenced function of a Kotlin function type
|
||||
FirDeclarationOrigin.BuiltIns -> runIf(dispatchReceiverClassLookupTagOrNull()?.isSomeFunctionalType(session) == true) {
|
||||
FirDeclarationOrigin.BuiltIns -> runIf(dispatchReceiverClassLookupTagOrNull()?.isSomeFunctionType(session) == true) {
|
||||
ForbiddenNamedArgumentsTarget.INVOKE_ON_FUNCTION_TYPE
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.resolve
|
||||
|
||||
import org.jetbrains.kotlin.builtins.functions.FunctionalTypeKind
|
||||
import org.jetbrains.kotlin.builtins.functions.FunctionTypeKind
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.descriptors.EffectiveVisibility
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
@@ -263,7 +263,7 @@ class FirSamResolver(
|
||||
// TODO: val shouldConvertFirstParameterToDescriptor = samWithReceiverResolvers.any { it.shouldConvertFirstSamParameterToReceiver(abstractMethod) }
|
||||
|
||||
val typeFromExtension = samConversionTransformers.firstNotNullOfOrNull {
|
||||
it.getCustomFunctionalTypeForSamConversion(abstractMethod)
|
||||
it.getCustomFunctionTypeForSamConversion(abstractMethod)
|
||||
}
|
||||
|
||||
SAMInfo(abstractMethod.symbol, typeFromExtension ?: abstractMethod.getFunctionTypeForAbstractMethod(session))
|
||||
@@ -415,8 +415,8 @@ private fun FirSimpleFunction.getFunctionTypeForAbstractMethod(session: FirSessi
|
||||
val contextReceiversTypes = contextReceivers.map {
|
||||
it.typeRef.coneTypeSafe<ConeKotlinType>() ?: ConeErrorType(ConeIntermediateDiagnostic("No type for context receiver $it"))
|
||||
}
|
||||
val kind = session.functionalTypeService.extractSingleSpecialKindForFunction(symbol) ?: FunctionalTypeKind.Function
|
||||
return createFunctionalType(
|
||||
val kind = session.functionTypeService.extractSingleSpecialKindForFunction(symbol) ?: FunctionTypeKind.Function
|
||||
return createFunctionType(
|
||||
kind,
|
||||
parameterTypes,
|
||||
receiverType = receiverParameter?.typeRef?.coneType,
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.resolve.calls
|
||||
|
||||
import org.jetbrains.kotlin.builtins.functions.isRegularFunction
|
||||
import org.jetbrains.kotlin.builtins.functions.isBasicFunctionOrKFunction
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
|
||||
@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.fir.expressions.*
|
||||
import org.jetbrains.kotlin.fir.lookupTracker
|
||||
import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
|
||||
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
||||
import org.jetbrains.kotlin.fir.resolve.createFunctionalType
|
||||
import org.jetbrains.kotlin.fir.resolve.createFunctionType
|
||||
import org.jetbrains.kotlin.fir.resolve.dfa.unwrapSmartcastExpression
|
||||
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
||||
import org.jetbrains.kotlin.fir.resolve.inference.model.ConeArgumentConstraintPosition
|
||||
@@ -271,7 +271,7 @@ fun Candidate.resolvePlainArgumentType(
|
||||
)?.let {
|
||||
argumentTypeForApplicabilityCheck = it
|
||||
substitutor.substituteOrSelf(argumentTypeForApplicabilityCheck)
|
||||
usesFunctionalConversion = true
|
||||
usesFunctionConversion = true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -287,21 +287,21 @@ private fun argumentTypeWithCustomConversion(
|
||||
argumentType: ConeKotlinType
|
||||
): ConeKotlinType? {
|
||||
// Expect the expected type to be a not regular functional type (e.g. suspend or custom)
|
||||
val expectedTypeKind = expectedType.functionalTypeKind(session) ?: return null
|
||||
if (expectedTypeKind.isRegularFunction) return null
|
||||
val expectedTypeKind = expectedType.functionTypeKind(session) ?: return null
|
||||
if (expectedTypeKind.isBasicFunctionOrKFunction) return null
|
||||
|
||||
// We want to check the argument type against non-suspend functional type.
|
||||
val expectedFunctionalType = expectedType.customFunctionalTypeToSimpleFunctionalType(session)
|
||||
val expectedFunctionType = expectedType.customFunctionTypeToSimpleFunctionType(session)
|
||||
|
||||
val argumentTypeWithInvoke = argumentType.findSubtypeOfSimpleFunctionalType(session, expectedFunctionalType)
|
||||
val argumentTypeWithInvoke = argumentType.findSubtypeOfBasicFunctionType(session, expectedFunctionType)
|
||||
|
||||
return argumentTypeWithInvoke?.findContributedInvokeSymbol(
|
||||
session,
|
||||
scopeSession,
|
||||
expectedFunctionalType,
|
||||
expectedFunctionType,
|
||||
shouldCalculateReturnTypesOfFakeOverrides = false
|
||||
)?.let { invokeSymbol ->
|
||||
createFunctionalType(
|
||||
createFunctionType(
|
||||
expectedTypeKind,
|
||||
invokeSymbol.fir.valueParameters.map { it.returnTypeRef.coneType },
|
||||
null,
|
||||
@@ -495,7 +495,7 @@ private fun Candidate.getExpectedTypeWithSAMConversion(
|
||||
candidateExpectedType: ConeKotlinType,
|
||||
context: ResolutionContext
|
||||
): ConeKotlinType? {
|
||||
if (candidateExpectedType.isSomeFunctionalType(session)) return null
|
||||
if (candidateExpectedType.isSomeFunctionType(session)) return null
|
||||
|
||||
// TODO: resolvedCall.registerArgumentWithSamConversion(argument, SamConversionDescription(convertedTypeByOriginal, convertedTypeByCandidate!!))
|
||||
|
||||
@@ -518,7 +518,7 @@ fun FirExpression.isFunctional(
|
||||
else -> {
|
||||
// Either a functional type or a subtype of a class that has a contributed `invoke`.
|
||||
val coneType = typeRef.coneTypeSafe<ConeKotlinType>() ?: return false
|
||||
if (coneType.isSomeFunctionalType(session)) {
|
||||
if (coneType.isSomeFunctionType(session)) {
|
||||
return true
|
||||
}
|
||||
val classLikeExpectedFunctionType = expectedFunctionType?.lowerBoundIfFlexible() as? ConeClassLikeType
|
||||
|
||||
+15
-15
@@ -7,8 +7,8 @@ package org.jetbrains.kotlin.fir.resolve.calls
|
||||
|
||||
import org.jetbrains.kotlin.KtFakeSourceElementKind
|
||||
import org.jetbrains.kotlin.KtSourceElement
|
||||
import org.jetbrains.kotlin.builtins.functions.FunctionalTypeKind
|
||||
import org.jetbrains.kotlin.builtins.functions.isRegularFunction
|
||||
import org.jetbrains.kotlin.builtins.functions.FunctionTypeKind
|
||||
import org.jetbrains.kotlin.builtins.functions.isBasicFunctionOrKFunction
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.fir.*
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
@@ -19,7 +19,7 @@ import org.jetbrains.kotlin.fir.expressions.FirResolvedQualifier
|
||||
import org.jetbrains.kotlin.fir.expressions.builder.buildNamedArgumentExpression
|
||||
import org.jetbrains.kotlin.fir.resolve.BodyResolveComponents
|
||||
import org.jetbrains.kotlin.fir.resolve.DoubleColonLHS
|
||||
import org.jetbrains.kotlin.fir.resolve.createFunctionalType
|
||||
import org.jetbrains.kotlin.fir.resolve.createFunctionType
|
||||
import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeUnsupportedCallableReferenceTarget
|
||||
import org.jetbrains.kotlin.fir.resolve.inference.extractInputOutputTypesFromCallableReferenceExpectedType
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
|
||||
@@ -131,12 +131,12 @@ private fun buildReflectionType(
|
||||
}
|
||||
|
||||
|
||||
val baseFunctionalTypeKind = callableReferenceAdaptation?.suspendConversionStrategy?.kind
|
||||
?: fir.specialFunctionalTypeKind(context.session)
|
||||
?: FunctionalTypeKind.Function
|
||||
val baseFunctionTypeKind = callableReferenceAdaptation?.suspendConversionStrategy?.kind
|
||||
?: fir.specialFunctionTypeKind(context.session)
|
||||
?: FunctionTypeKind.Function
|
||||
|
||||
return createFunctionalType(
|
||||
baseFunctionalTypeKind.reflectKind(),
|
||||
return createFunctionType(
|
||||
baseFunctionTypeKind.reflectKind(),
|
||||
parameters,
|
||||
receiverType = receiverType.takeIf { fir.receiverParameter != null },
|
||||
rawReturnType = returnType,
|
||||
@@ -255,11 +255,11 @@ private fun BodyResolveComponents.getCallableReferenceAdaptation(
|
||||
else
|
||||
mappedArguments
|
||||
|
||||
val expectedTypeFunctionalKind = expectedType.functionalTypeKind(session)?.takeUnless { it.isRegularFunction }
|
||||
val functionKind = function.specialFunctionalTypeKind(session)
|
||||
val expectedTypeFunctionKind = expectedType.functionTypeKind(session)?.takeUnless { it.isBasicFunctionOrKFunction }
|
||||
val functionKind = function.specialFunctionTypeKind(session)
|
||||
|
||||
val conversionStrategy = if (expectedTypeFunctionalKind != null && functionKind == null) {
|
||||
CallableReferenceConversionStrategy.CustomConversion(expectedTypeFunctionalKind)
|
||||
val conversionStrategy = if (expectedTypeFunctionKind != null && functionKind == null) {
|
||||
CallableReferenceConversionStrategy.CustomConversion(expectedTypeFunctionKind)
|
||||
} else {
|
||||
CallableReferenceConversionStrategy.NoConversion
|
||||
}
|
||||
@@ -277,14 +277,14 @@ private fun BodyResolveComponents.getCallableReferenceAdaptation(
|
||||
|
||||
|
||||
sealed class CallableReferenceConversionStrategy {
|
||||
abstract val kind: FunctionalTypeKind?
|
||||
abstract val kind: FunctionTypeKind?
|
||||
|
||||
object NoConversion : CallableReferenceConversionStrategy() {
|
||||
override val kind: FunctionalTypeKind?
|
||||
override val kind: FunctionTypeKind?
|
||||
get() = null
|
||||
}
|
||||
|
||||
class CustomConversion(override val kind: FunctionalTypeKind) : CallableReferenceConversionStrategy()
|
||||
class CustomConversion(override val kind: FunctionTypeKind) : CallableReferenceConversionStrategy()
|
||||
}
|
||||
|
||||
private fun varargParameterTypeByExpectedParameter(
|
||||
|
||||
@@ -62,13 +62,13 @@ class Candidate(
|
||||
internal var callableReferenceAdaptation: CallableReferenceAdaptation? = null
|
||||
set(value) {
|
||||
field = value
|
||||
usesFunctionalConversion = value?.suspendConversionStrategy is CallableReferenceConversionStrategy.CustomConversion
|
||||
usesFunctionConversion = value?.suspendConversionStrategy is CallableReferenceConversionStrategy.CustomConversion
|
||||
if (value != null) {
|
||||
numDefaults = value.defaults
|
||||
}
|
||||
}
|
||||
|
||||
var usesFunctionalConversion: Boolean = false
|
||||
var usesFunctionConversion: Boolean = false
|
||||
|
||||
var argumentMapping: LinkedHashMap<FirExpression, FirValueParameter>? = null
|
||||
var numDefaults: Int = 0
|
||||
|
||||
+1
-1
@@ -94,7 +94,7 @@ class ConeOverloadConflictResolver(
|
||||
}
|
||||
|
||||
if (discriminateSuspendConversions) {
|
||||
val filtered = candidates.filterTo(mutableSetOf()) { !it.usesFunctionalConversion }
|
||||
val filtered = candidates.filterTo(mutableSetOf()) { !it.usesFunctionConversion }
|
||||
when (filtered.size) {
|
||||
1 -> return filtered
|
||||
0, candidates.size -> {
|
||||
|
||||
@@ -297,7 +297,7 @@ object CheckDslScopeViolation : ResolutionStage() {
|
||||
// ```
|
||||
// `useX()` is a call to `invoke` with `useX` as the dispatch receiver. In the FIR tree, extension receiver is represented as an
|
||||
// implicit `this` expression passed as the first argument.
|
||||
if (candidate.dispatchReceiverValue?.type?.fullyExpandedType(context.session)?.isSomeFunctionalType(context.session) == true &&
|
||||
if (candidate.dispatchReceiverValue?.type?.fullyExpandedType(context.session)?.isSomeFunctionType(context.session) == true &&
|
||||
(candidate.symbol as? FirNamedFunctionSymbol)?.name == OperatorNameConventions.INVOKE
|
||||
) {
|
||||
val firstArg = candidate.argumentMapping?.keys?.firstOrNull() as? FirThisReceiverExpression ?: return
|
||||
|
||||
+2
-2
@@ -133,7 +133,7 @@ class ConstraintSystemCompleter(components: BodyResolveComponents, private val c
|
||||
|
||||
// Stage 4: create atoms with revised expected types if needed
|
||||
for (argument in postponedArgumentsWithRevisableType) {
|
||||
val argumentWasTransformed = transformToAtomWithNewFunctionalExpectedType(
|
||||
val argumentWasTransformed = transformToAtomWithNewFunctionExpectedType(
|
||||
this, context, argument
|
||||
)
|
||||
|
||||
@@ -214,7 +214,7 @@ class ConstraintSystemCompleter(components: BodyResolveComponents, private val c
|
||||
return variableForFixation?.hasProperConstraint == true
|
||||
}
|
||||
|
||||
private fun transformToAtomWithNewFunctionalExpectedType(
|
||||
private fun transformToAtomWithNewFunctionExpectedType(
|
||||
c: ConstraintSystemCompletionContext,
|
||||
resolutionContext: ResolutionContext,
|
||||
argument: PostponedAtomWithRevisableExpectedType,
|
||||
|
||||
+5
-5
@@ -14,7 +14,7 @@ import org.jetbrains.kotlin.fir.resolve.BodyResolveComponents
|
||||
import org.jetbrains.kotlin.fir.resolve.calls.Candidate
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
|
||||
fun extractLambdaInfoFromFunctionalType(
|
||||
fun extractLambdaInfoFromFunctionType(
|
||||
expectedType: ConeKotlinType?,
|
||||
expectedTypeRef: FirTypeRef?,
|
||||
argument: FirAnonymousFunction,
|
||||
@@ -26,7 +26,7 @@ fun extractLambdaInfoFromFunctionalType(
|
||||
val session = components.session
|
||||
if (expectedType == null) return null
|
||||
if (expectedType is ConeFlexibleType) {
|
||||
return extractLambdaInfoFromFunctionalType(
|
||||
return extractLambdaInfoFromFunctionType(
|
||||
expectedType.lowerBound,
|
||||
expectedTypeRef,
|
||||
argument,
|
||||
@@ -36,8 +36,8 @@ fun extractLambdaInfoFromFunctionalType(
|
||||
duringCompletion
|
||||
)
|
||||
}
|
||||
val expectedFunctionalKind = expectedType.functionalTypeKind(session) ?: return null
|
||||
val actualFunctionalKind = session.functionalTypeService.extractSingleSpecialKindForFunction(argument.symbol)
|
||||
val expectedFunctionKind = expectedType.functionTypeKind(session) ?: return null
|
||||
val actualFunctionKind = session.functionTypeService.extractSingleSpecialKindForFunction(argument.symbol)
|
||||
|
||||
val singleStatement = argument.body?.statements?.singleOrNull() as? FirReturnExpression
|
||||
if (argument.returnType == null && singleStatement != null &&
|
||||
@@ -101,7 +101,7 @@ fun extractLambdaInfoFromFunctionalType(
|
||||
return ResolvedLambdaAtom(
|
||||
argument,
|
||||
expectedType,
|
||||
actualFunctionalKind ?: expectedFunctionalKind,
|
||||
actualFunctionKind ?: expectedFunctionKind,
|
||||
receiverType,
|
||||
contextReceivers,
|
||||
parameters,
|
||||
|
||||
+8
-8
@@ -5,7 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.resolve.inference
|
||||
|
||||
import org.jetbrains.kotlin.builtins.functions.FunctionalTypeKind
|
||||
import org.jetbrains.kotlin.builtins.functions.FunctionTypeKind
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirAnonymousFunction
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnonymousFunctionExpression
|
||||
@@ -14,7 +14,7 @@ import org.jetbrains.kotlin.fir.resolve.calls.ArgumentTypeMismatch
|
||||
import org.jetbrains.kotlin.fir.resolve.calls.Candidate
|
||||
import org.jetbrains.kotlin.fir.resolve.calls.CheckerSink
|
||||
import org.jetbrains.kotlin.fir.resolve.calls.ResolutionContext
|
||||
import org.jetbrains.kotlin.fir.resolve.createFunctionalType
|
||||
import org.jetbrains.kotlin.fir.resolve.createFunctionType
|
||||
import org.jetbrains.kotlin.fir.resolve.inference.model.ConeArgumentConstraintPosition
|
||||
import org.jetbrains.kotlin.fir.resolve.inference.model.ConeExplicitTypeParameterConstraintPosition
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
@@ -51,7 +51,7 @@ fun Candidate.preprocessLambdaArgument(
|
||||
val anonymousFunction = argument.anonymousFunction
|
||||
|
||||
val resolvedArgument =
|
||||
extractLambdaInfoFromFunctionalType(
|
||||
extractLambdaInfoFromFunctionType(
|
||||
expectedType,
|
||||
expectedTypeRef,
|
||||
anonymousFunction,
|
||||
@@ -63,8 +63,8 @@ fun Candidate.preprocessLambdaArgument(
|
||||
|
||||
if (expectedType != null) {
|
||||
val parameters = resolvedArgument.parameters
|
||||
val lambdaType = createFunctionalType(
|
||||
resolvedArgument.expectedFunctionalTypeKind ?: FunctionalTypeKind.Function,
|
||||
val lambdaType = createFunctionType(
|
||||
resolvedArgument.expectedFunctionTypeKind ?: FunctionTypeKind.Function,
|
||||
if (resolvedArgument.coerceFirstParameterToExtensionReceiver) parameters.drop(1) else parameters,
|
||||
resolvedArgument.receiver,
|
||||
resolvedArgument.returnType,
|
||||
@@ -107,8 +107,8 @@ private fun extractLambdaInfo(
|
||||
session: FirSession,
|
||||
candidate: Candidate?
|
||||
): ResolvedLambdaAtom {
|
||||
val expectedFunctionalKind = expectedType?.lowerBoundIfFlexible()?.functionalTypeKind(session)
|
||||
val isFunctionSupertype = expectedFunctionalKind != null
|
||||
val expectedFunctionKind = expectedType?.lowerBoundIfFlexible()?.functionTypeKind(session)
|
||||
val isFunctionSupertype = expectedFunctionKind != null
|
||||
|
||||
val typeVariable = ConeTypeVariableForLambdaReturnType(argument, "_L")
|
||||
|
||||
@@ -133,7 +133,7 @@ private fun extractLambdaInfo(
|
||||
return ResolvedLambdaAtom(
|
||||
argument,
|
||||
expectedType,
|
||||
expectedFunctionalKind,
|
||||
expectedFunctionKind,
|
||||
receiverType,
|
||||
contextReceivers,
|
||||
parameters,
|
||||
|
||||
+3
-3
@@ -5,7 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.resolve.inference
|
||||
|
||||
import org.jetbrains.kotlin.builtins.functions.FunctionalTypeKind
|
||||
import org.jetbrains.kotlin.builtins.functions.FunctionTypeKind
|
||||
import org.jetbrains.kotlin.fir.FirElement
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirAnonymousFunction
|
||||
@@ -40,7 +40,7 @@ sealed class PostponedResolvedAtom : PostponedResolvedAtomMarker {
|
||||
class ResolvedLambdaAtom(
|
||||
override val atom: FirAnonymousFunction,
|
||||
expectedType: ConeKotlinType?,
|
||||
val expectedFunctionalTypeKind: FunctionalTypeKind?,
|
||||
val expectedFunctionTypeKind: FunctionTypeKind?,
|
||||
val receiver: ConeKotlinType?,
|
||||
val contextReceivers: List<ConeKotlinType>,
|
||||
val parameters: List<ConeKotlinType>,
|
||||
@@ -178,7 +178,7 @@ internal fun extractInputOutputTypesFromCallableReferenceExpectedType(
|
||||
if (expectedType == null) return null
|
||||
|
||||
return when {
|
||||
expectedType.isSomeFunctionalType(session) ->
|
||||
expectedType.isSomeFunctionType(session) ->
|
||||
InputOutputTypes(expectedType.valueParameterTypesIncludingReceiver(session), expectedType.returnType(session))
|
||||
|
||||
// ReflectionTypes.isBaseTypeForNumberedReferenceTypes(expectedType) ->
|
||||
|
||||
+9
-11
@@ -6,7 +6,7 @@
|
||||
package org.jetbrains.kotlin.fir.resolve.providers.impl
|
||||
|
||||
import org.jetbrains.kotlin.KtSourceElement
|
||||
import org.jetbrains.kotlin.builtins.functions.FunctionalTypeKind
|
||||
import org.jetbrains.kotlin.builtins.functions.FunctionTypeKind
|
||||
import org.jetbrains.kotlin.fir.*
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.impl.FirOuterClassTypeParameterRef
|
||||
@@ -19,7 +19,6 @@ import org.jetbrains.kotlin.fir.resolve.calls.AbstractCandidate
|
||||
import org.jetbrains.kotlin.fir.resolve.calls.ReceiverValue
|
||||
import org.jetbrains.kotlin.fir.resolve.calls.ResolutionDiagnostic
|
||||
import org.jetbrains.kotlin.fir.resolve.diagnostics.*
|
||||
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
|
||||
import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.ScopeClassDeclaration
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag
|
||||
@@ -30,7 +29,6 @@ import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl
|
||||
import org.jetbrains.kotlin.fir.types.impl.ConeTypeParameterTypeImpl
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.StandardClassIds
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintSystemError
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.CandidateApplicability
|
||||
@@ -445,20 +443,20 @@ class FirTypeResolverImpl(private val session: FirSession) : FirTypeResolver() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun createFunctionalType(typeRef: FirFunctionTypeRef): Pair<ConeClassLikeTypeImpl, ConeDiagnostic?> {
|
||||
private fun createFunctionType(typeRef: FirFunctionTypeRef): Pair<ConeClassLikeTypeImpl, ConeDiagnostic?> {
|
||||
val parameters =
|
||||
typeRef.contextReceiverTypeRefs.map { it.coneType } +
|
||||
listOfNotNull(typeRef.receiverTypeRef?.coneType) +
|
||||
typeRef.parameters.map { it.returnTypeRef.coneType.withParameterNameAnnotation(it, session) } +
|
||||
listOf(typeRef.returnTypeRef.coneType)
|
||||
val functionalKinds = session.functionalTypeService.extractAllSpecialKindsForFunctionalTypeRef(typeRef)
|
||||
val functionKinds = session.functionTypeService.extractAllSpecialKindsForFunctionTypeRef(typeRef)
|
||||
var diagnostic: ConeDiagnostic? = null
|
||||
val kind = when (functionalKinds.size) {
|
||||
0 -> FunctionalTypeKind.Function
|
||||
1 -> functionalKinds.single()
|
||||
val kind = when (functionKinds.size) {
|
||||
0 -> FunctionTypeKind.Function
|
||||
1 -> functionKinds.single()
|
||||
else -> {
|
||||
diagnostic = ConeAmbiguousFunctionalTypeKinds(functionalKinds)
|
||||
FunctionalTypeKind.Function
|
||||
diagnostic = ConeAmbiguousFunctionTypeKinds(functionKinds)
|
||||
FunctionTypeKind.Function
|
||||
}
|
||||
}
|
||||
|
||||
@@ -505,7 +503,7 @@ class FirTypeResolverImpl(private val session: FirSession) : FirTypeResolver() {
|
||||
isOperandOfIsOperator,
|
||||
) to (result as? TypeResolutionResult.Resolved)?.typeCandidate?.diagnostic
|
||||
}
|
||||
is FirFunctionTypeRef -> createFunctionalType(typeRef)
|
||||
is FirFunctionTypeRef -> createFunctionType(typeRef)
|
||||
is FirDynamicTypeRef -> ConeDynamicType.create(session) to null
|
||||
is FirIntersectionTypeRef -> {
|
||||
val leftType = typeRef.leftType.coneType
|
||||
|
||||
+7
-7
@@ -6,7 +6,7 @@
|
||||
package org.jetbrains.kotlin.fir.resolve.transformers
|
||||
|
||||
import org.jetbrains.kotlin.KtFakeSourceElementKind
|
||||
import org.jetbrains.kotlin.builtins.functions.FunctionalTypeKind
|
||||
import org.jetbrains.kotlin.builtins.functions.FunctionTypeKind
|
||||
import org.jetbrains.kotlin.fakeElement
|
||||
import org.jetbrains.kotlin.fir.*
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
@@ -561,7 +561,7 @@ class FirCallCompletionResultsWriterTransformer(
|
||||
// From the argument mapping, the expected type of this anonymous function would be:
|
||||
when {
|
||||
// a built-in functional type, no-brainer
|
||||
expectedArgumentType.isSomeFunctionalType(session) -> expectedArgumentType
|
||||
expectedArgumentType.isSomeFunctionType(session) -> expectedArgumentType
|
||||
// fun interface (a.k.a. SAM), then unwrap it and build a functional type from that interface function
|
||||
expectedArgumentType is ConeClassLikeType -> {
|
||||
val firRegularClass =
|
||||
@@ -570,8 +570,8 @@ class FirCallCompletionResultsWriterTransformer(
|
||||
firRegularClass?.let answer@{
|
||||
val functionType = samResolver.getFunctionTypeForPossibleSamType(firRegularClass.defaultType())
|
||||
?: return@answer null
|
||||
val kind = functionType.functionalTypeKind(session) ?: FunctionalTypeKind.Function
|
||||
createFunctionalType(
|
||||
val kind = functionType.functionTypeKind(session) ?: FunctionTypeKind.Function
|
||||
createFunctionType(
|
||||
kind,
|
||||
functionType.typeArguments.dropLast(1).map { it as ConeKotlinType },
|
||||
null,
|
||||
@@ -617,9 +617,9 @@ class FirCallCompletionResultsWriterTransformer(
|
||||
}
|
||||
|
||||
if (needUpdateLambdaType) {
|
||||
val kind = expectedType?.functionalTypeKind(session)
|
||||
?: result.typeRef.coneTypeSafe<ConeClassLikeType>()?.functionalTypeKind(session)
|
||||
result.replaceTypeRef(result.constructFunctionalTypeRef(session, kind))
|
||||
val kind = expectedType?.functionTypeKind(session)
|
||||
?: result.typeRef.coneTypeSafe<ConeClassLikeType>()?.functionTypeKind(session)
|
||||
result.replaceTypeRef(result.constructFunctionTypeRef(session, kind))
|
||||
session.lookupTracker?.recordTypeResolveAsLookup(result.typeRef, result.source, context.file.source)
|
||||
}
|
||||
// Have to delay this until the type is written to avoid adding a return if the type is Unit.
|
||||
|
||||
+1
-1
@@ -123,7 +123,7 @@ class FirSpecificTypeResolverTransformer(
|
||||
type = resolvedType
|
||||
}
|
||||
this.diagnostic = diagnostic ?: (resolvedType as? ConeErrorType)?.diagnostic
|
||||
?: ConeSimpleDiagnostic("Unresolved functional type: ${functionTypeRef.render()}")
|
||||
?: ConeSimpleDiagnostic("Unresolved function type: ${functionTypeRef.render()}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -19,7 +19,7 @@ import org.jetbrains.kotlin.fir.expressions.FirFunctionCall
|
||||
import org.jetbrains.kotlin.fir.expressions.FirWrappedArgumentExpression
|
||||
import org.jetbrains.kotlin.fir.resolve.calls.FirNamedReferenceWithCandidate
|
||||
import org.jetbrains.kotlin.fir.types.coneType
|
||||
import org.jetbrains.kotlin.fir.types.isNonReflectFunctionalType
|
||||
import org.jetbrains.kotlin.fir.types.isNonReflectFunctionType
|
||||
|
||||
tailrec fun FirExpression.unwrapAnonymousFunctionExpression(): FirAnonymousFunction? = when (this) {
|
||||
is FirAnonymousFunctionExpression -> anonymousFunction
|
||||
@@ -47,7 +47,7 @@ fun FirFunctionCall.replaceLambdaArgumentInvocationKinds(session: FirSession) {
|
||||
val kind = byParameter[parameter] ?: EventOccurrencesRange.UNKNOWN.takeIf {
|
||||
// Inline functional parameters have to be called in-place; that's the only permitted operation on them.
|
||||
isInline && !parameter.isNoinline && !parameter.isCrossinline &&
|
||||
parameter.returnTypeRef.coneType.isNonReflectFunctionalType(session)
|
||||
parameter.returnTypeRef.coneType.isNonReflectFunctionType(session)
|
||||
} ?: continue
|
||||
lambda.replaceInvocationKind(kind)
|
||||
}
|
||||
|
||||
+4
-4
@@ -33,7 +33,7 @@ import org.jetbrains.kotlin.fir.resolve.dfa.unwrapSmartcastExpression
|
||||
import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeLocalVariableNoTypeOrInitializer
|
||||
import org.jetbrains.kotlin.fir.resolve.inference.FirStubTypeTransformer
|
||||
import org.jetbrains.kotlin.fir.resolve.inference.ResolvedLambdaAtom
|
||||
import org.jetbrains.kotlin.fir.resolve.inference.extractLambdaInfoFromFunctionalType
|
||||
import org.jetbrains.kotlin.fir.resolve.inference.extractLambdaInfoFromFunctionType
|
||||
import org.jetbrains.kotlin.fir.resolve.substitution.createTypeSubstitutorByTypeConstructor
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.FirCallCompletionResultsWriterTransformer
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.FirStatusResolver
|
||||
@@ -763,7 +763,7 @@ open class FirDeclarationsResolveTransformer(transformer: FirAbstractBodyResolve
|
||||
data: ResolutionMode
|
||||
): FirAnonymousFunction {
|
||||
val resolvedLambdaAtom = (expectedTypeRef as? FirResolvedTypeRef)?.let {
|
||||
extractLambdaInfoFromFunctionalType(
|
||||
extractLambdaInfoFromFunctionType(
|
||||
it.type, it, anonymousFunction, returnTypeVariable = null, components, candidate = null, duringCompletion = false
|
||||
)
|
||||
}
|
||||
@@ -806,7 +806,7 @@ open class FirDeclarationsResolveTransformer(transformer: FirAbstractBodyResolve
|
||||
session.lookupTracker?.recordTypeResolveAsLookup(lambda.returnTypeRef, lambda.source, context.file.source)
|
||||
}
|
||||
|
||||
lambda.replaceTypeRef(lambda.constructFunctionalTypeRef(session, resolvedLambdaAtom?.expectedFunctionalTypeKind))
|
||||
lambda.replaceTypeRef(lambda.constructFunctionTypeRef(session, resolvedLambdaAtom?.expectedFunctionTypeKind))
|
||||
session.lookupTracker?.recordTypeResolveAsLookup(lambda.typeRef, lambda.source, context.file.source)
|
||||
lambda.addReturnToLastStatementIfNeeded()
|
||||
return lambda
|
||||
@@ -859,7 +859,7 @@ open class FirDeclarationsResolveTransformer(transformer: FirAbstractBodyResolve
|
||||
lambda: FirAnonymousFunction
|
||||
): List<FirValueParameter> {
|
||||
if (expectedType == null) return lambda.valueParameters
|
||||
if (!expectedType.isNonReflectFunctionalType(session)) return lambda.valueParameters
|
||||
if (!expectedType.isNonReflectFunctionType(session)) return lambda.valueParameters
|
||||
val parameterTypes = expectedType.typeArguments
|
||||
.mapTo(mutableListOf()) { it.type ?: session.builtinTypes.nullableAnyType.type }
|
||||
.also { it.removeLastOrNull() }
|
||||
|
||||
Reference in New Issue
Block a user