Introduce StandardNames.IMPLICIT_LAMBDA_PARAMETER_NAME

and use it instead of hardcoded constant
This commit is contained in:
Ilya Kirillov
2023-06-26 15:54:33 +02:00
committed by Space Team
parent 0a1f27e43a
commit 5b4916a808
6 changed files with 11 additions and 5 deletions
@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.analysis.api.symbols.KtValueParameterSymbol
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtPsiBasedSymbolPointer
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
import org.jetbrains.kotlin.descriptors.impl.AnonymousFunctionDescriptor
import org.jetbrains.kotlin.name.Name
@@ -54,7 +55,7 @@ internal class KtFe10DescValueParameterSymbol(
override val isImplicitLambdaParameter: Boolean
get() = withValidityAssertion {
descriptor.containingDeclaration is AnonymousFunctionDescriptor &&
descriptor.name.identifierOrNullIfSpecial == "it" &&
descriptor.name == StandardNames.IMPLICIT_LAMBDA_PARAMETER_NAME &&
// Implicit lambda parameter doesn't have a source PSI.
descriptor.source.getPsi() == null &&
// But, that could be the case for a declaration from Library. Double-check the slice in the binding context
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KtTypeNullability
import org.jetbrains.kotlin.analysis.utils.errors.unexpectedElementError
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.builtins.functions.FunctionClassDescriptor
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
@@ -349,7 +350,7 @@ internal fun DeclarationDescriptor.getSymbolOrigin(analysisContext: Fe10Analysis
return analysisContext.getOrigin(virtualFile)
} else { // psi == null
// Implicit lambda parameter
if (this is ValueParameterDescriptor && this.name.identifierOrNullIfSpecial == "it") {
if (this is ValueParameterDescriptor && this.name == StandardNames.IMPLICIT_LAMBDA_PARAMETER_NAME) {
return KtSymbolOrigin.SOURCE_MEMBER_GENERATED
}
}
@@ -6,6 +6,7 @@
package org.jetbrains.kotlin.fir.resolve.inference
import org.jetbrains.kotlin.KtFakeSourceElementKind
import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.fakeElement
import org.jetbrains.kotlin.fir.*
import org.jetbrains.kotlin.fir.declarations.FirAnonymousFunction
@@ -258,7 +259,7 @@ class FirCallCompleter(
val itParam = when {
needItParam -> {
val name = Name.identifier("it")
val name = StandardNames.IMPLICIT_LAMBDA_PARAMETER_NAME
val itType = parameters.single()
buildValueParameter {
resolvePhase = FirResolvePhase.BODY_RESOLVE
@@ -6,6 +6,7 @@
package org.jetbrains.kotlin.fir.resolve.transformers.body.resolve
import org.jetbrains.kotlin.KtFakeSourceElementKind
import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.descriptors.Visibility
import org.jetbrains.kotlin.fakeElement
@@ -905,7 +906,7 @@ open class FirDeclarationsResolveTransformer(
val singleParameterType = resolvedLambdaAtom.parameters.singleOrNull()
return when {
lambda.valueParameters.isEmpty() && singleParameterType != null -> {
val name = Name.identifier("it")
val name = StandardNames.IMPLICIT_LAMBDA_PARAMETER_NAME
val itParam = buildValueParameter {
resolvePhase = FirResolvePhase.BODY_RESOLVE
source = lambda.source?.fakeElement(KtFakeSourceElementKind.ItLambdaParameter)
@@ -333,7 +333,7 @@ class FunctionDescriptorResolver(
// it parameter for lambda
val valueParameterDescriptor = expectedValueParameters.single()
val it = ValueParameterDescriptorImpl(
functionDescriptor, null, 0, Annotations.EMPTY, Name.identifier("it"),
functionDescriptor, null, 0, Annotations.EMPTY, StandardNames.IMPLICIT_LAMBDA_PARAMETER_NAME,
expectedParameterTypes!!.single(), valueParameterDescriptor.declaresDefaultValue(),
valueParameterDescriptor.isCrossinline, valueParameterDescriptor.isNoinline,
valueParameterDescriptor.varargElementType, SourceElement.NO_SOURCE
@@ -38,6 +38,8 @@ object StandardNames {
@JvmField val NEXT_CHAR = Name.identifier("nextChar")
@JvmField val IMPLICIT_LAMBDA_PARAMETER_NAME = Name.identifier("it")
@JvmField val CONTEXT_FUNCTION_TYPE_PARAMETER_COUNT_NAME = Name.identifier("count")
@JvmField val DYNAMIC_FQ_NAME = FqName("<dynamic>")