[FIR] Get rid of implicit type refs with source
#KT-55835
This commit is contained in:
committed by
Space Team
parent
91dad7b952
commit
070b694247
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir
|
||||
|
||||
import org.jetbrains.kotlin.KtSourceElement
|
||||
import org.jetbrains.kotlin.builtins.StandardNames
|
||||
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.expandedConeType
|
||||
@@ -40,17 +41,18 @@ inline fun FirFunctionCall.copyAsImplicitInvokeCall(
|
||||
}
|
||||
|
||||
fun FirTypeRef.resolvedTypeFromPrototype(
|
||||
type: ConeKotlinType
|
||||
type: ConeKotlinType,
|
||||
fallbackSource: KtSourceElement? = null,
|
||||
): FirResolvedTypeRef {
|
||||
return if (type is ConeErrorType) {
|
||||
buildErrorTypeRef {
|
||||
source = this@resolvedTypeFromPrototype.source
|
||||
source = this@resolvedTypeFromPrototype.source ?: fallbackSource
|
||||
this.type = type
|
||||
diagnostic = type.diagnostic
|
||||
}
|
||||
} else {
|
||||
buildResolvedTypeRef {
|
||||
source = this@resolvedTypeFromPrototype.source
|
||||
source = this@resolvedTypeFromPrototype.source ?: fallbackSource
|
||||
this.type = type
|
||||
delegatedTypeRef = when (val original = this@resolvedTypeFromPrototype) {
|
||||
is FirResolvedTypeRef -> original.delegatedTypeRef
|
||||
|
||||
-3
@@ -2353,9 +2353,6 @@ class LightTreeRawFirDeclarationBuilder(
|
||||
modifiers = modifiers,
|
||||
returnTypeRef = firType
|
||||
?: when {
|
||||
valueParameterDeclaration == ValueParameterDeclaration.LAMBDA -> buildImplicitTypeRef {
|
||||
source = valueParameterSource.fakeElement(KtFakeSourceElementKind.ImplicitReturnTypeOfLambdaValueParameter)
|
||||
}
|
||||
valueParameterDeclaration.shouldExplicitParameterTypeBePresent -> createNoTypeForParameterTypeRef()
|
||||
else -> implicitType
|
||||
},
|
||||
|
||||
+1
-1
@@ -146,7 +146,7 @@ class LightTreeRawFirExpressionBuilder(
|
||||
moduleData = baseModuleData
|
||||
origin = FirDeclarationOrigin.Source
|
||||
returnTypeRef = implicitType
|
||||
receiverParameter = implicitType.asReceiverParameter()
|
||||
receiverParameter = expressionSource.asReceiverParameter()
|
||||
symbol = functionSymbol
|
||||
isLambda = true
|
||||
hasExplicitParameterList = hasArrow
|
||||
|
||||
+4
-16
@@ -1680,21 +1680,14 @@ open class PsiRawFirBuilder(
|
||||
override fun visitLambdaExpression(expression: KtLambdaExpression, data: FirElement?): FirElement {
|
||||
val literal = expression.functionLiteral
|
||||
val literalSource = literal.toFirSourceElement()
|
||||
val implicitTypeRefSource = literal.toFirSourceElement(KtFakeSourceElementKind.ImplicitTypeRef)
|
||||
val returnType = buildImplicitTypeRef {
|
||||
source = implicitTypeRefSource
|
||||
}
|
||||
val receiverType = buildImplicitTypeRef {
|
||||
source = implicitTypeRefSource
|
||||
}
|
||||
|
||||
val target: FirFunctionTarget
|
||||
val anonymousFunction = buildAnonymousFunction {
|
||||
source = literalSource
|
||||
moduleData = baseModuleData
|
||||
origin = FirDeclarationOrigin.Source
|
||||
returnTypeRef = returnType
|
||||
receiverParameter = receiverType.asReceiverParameter()
|
||||
returnTypeRef = FirImplicitTypeRefImplWithoutSource
|
||||
receiverParameter = literalSource.asReceiverParameter()
|
||||
symbol = FirAnonymousFunctionSymbol()
|
||||
isLambda = true
|
||||
hasExplicitParameterList = expression.functionLiteral.arrow != null
|
||||
@@ -1709,9 +1702,7 @@ open class PsiRawFirBuilder(
|
||||
containingFunctionSymbol = this@buildAnonymousFunction.symbol
|
||||
moduleData = baseModuleData
|
||||
origin = FirDeclarationOrigin.Source
|
||||
returnTypeRef = valueParameter.typeReference?.convertSafe() ?: buildImplicitTypeRef {
|
||||
source = multiDeclaration.toFirSourceElement(KtFakeSourceElementKind.ImplicitTypeRef)
|
||||
}
|
||||
returnTypeRef = valueParameter.typeReference?.convertSafe() ?: FirImplicitTypeRefImplWithoutSource
|
||||
this.name = name
|
||||
symbol = FirValueParameterSymbol(name)
|
||||
isCrossinline = false
|
||||
@@ -1728,10 +1719,7 @@ open class PsiRawFirBuilder(
|
||||
) { toFirOrImplicitType() }.statements
|
||||
multiParameter
|
||||
} else {
|
||||
val typeRef = valueParameter.typeReference?.convertSafe() ?: buildImplicitTypeRef {
|
||||
source = valueParameter.toFirSourceElement()
|
||||
.fakeElement(KtFakeSourceElementKind.ImplicitReturnTypeOfLambdaValueParameter)
|
||||
}
|
||||
val typeRef = valueParameter.typeReference?.convertSafe() ?: FirImplicitTypeRefImplWithoutSource
|
||||
convertValueParameter(valueParameter, symbol, typeRef, ValueParameterDeclaration.LAMBDA)
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -625,9 +625,9 @@ fun FirTypeRef.convertToReceiverParameter(): FirReceiverParameter {
|
||||
}
|
||||
}
|
||||
|
||||
fun FirImplicitTypeRef.asReceiverParameter(): FirReceiverParameter = buildReceiverParameter {
|
||||
source = this@asReceiverParameter.source?.fakeElement(KtFakeSourceElementKind.ReceiverFromType)
|
||||
typeRef = this@asReceiverParameter
|
||||
fun KtSourceElement.asReceiverParameter(): FirReceiverParameter = buildReceiverParameter {
|
||||
source = this@asReceiverParameter.fakeElement(KtFakeSourceElementKind.ReceiverFromType)
|
||||
typeRef = FirImplicitTypeRefImplWithoutSource
|
||||
}
|
||||
|
||||
fun <T> FirCallableDeclaration.initContainingClassAttr(context: Context<T>) {
|
||||
|
||||
+6
-1
@@ -282,7 +282,12 @@ class FirCallCompleter(
|
||||
lambdaArgument.replaceReceiverParameter(null)
|
||||
} else {
|
||||
lambdaArgument.receiverParameter?.apply {
|
||||
replaceTypeRef(typeRef.resolvedTypeFromPrototype(receiverType.approximateLambdaInputType()))
|
||||
replaceTypeRef(
|
||||
typeRef.resolvedTypeFromPrototype(
|
||||
receiverType.approximateLambdaInputType(),
|
||||
source?.fakeElement(KtFakeSourceElementKind.ImplicitTypeRef),
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-1
@@ -931,7 +931,10 @@ open class FirDeclarationsResolveTransformer(
|
||||
param
|
||||
} else {
|
||||
val resolvedType =
|
||||
param.returnTypeRef.resolvedTypeFromPrototype(expectedTypeParameterTypes[index])
|
||||
param.returnTypeRef.resolvedTypeFromPrototype(
|
||||
expectedTypeParameterTypes[index],
|
||||
param.source?.fakeElement(KtFakeSourceElementKind.ImplicitReturnTypeOfLambdaValueParameter)
|
||||
)
|
||||
param.replaceReturnTypeRef(resolvedType)
|
||||
param
|
||||
}
|
||||
|
||||
-52
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2023 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.
|
||||
*/
|
||||
|
||||
@file:Suppress("DuplicatedCode", "unused")
|
||||
|
||||
package org.jetbrains.kotlin.fir.types.builder
|
||||
|
||||
import kotlin.contracts.*
|
||||
import org.jetbrains.kotlin.KtSourceElement
|
||||
import org.jetbrains.kotlin.fir.builder.FirBuilderDsl
|
||||
import org.jetbrains.kotlin.fir.builder.toMutableOrEmpty
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
|
||||
import org.jetbrains.kotlin.fir.types.FirImplicitTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.impl.FirImplicitTypeRefImpl
|
||||
import org.jetbrains.kotlin.fir.visitors.*
|
||||
|
||||
/*
|
||||
* This file was generated automatically
|
||||
* DO NOT MODIFY IT MANUALLY
|
||||
*/
|
||||
|
||||
@FirBuilderDsl
|
||||
class FirImplicitTypeRefBuilder {
|
||||
lateinit var source: KtSourceElement
|
||||
|
||||
fun build(): FirImplicitTypeRef {
|
||||
return FirImplicitTypeRefImpl(
|
||||
source,
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
inline fun buildImplicitTypeRef(init: FirImplicitTypeRefBuilder.() -> Unit): FirImplicitTypeRef {
|
||||
contract {
|
||||
callsInPlace(init, kotlin.contracts.InvocationKind.EXACTLY_ONCE)
|
||||
}
|
||||
return FirImplicitTypeRefBuilder().apply(init).build()
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
inline fun buildImplicitTypeRefCopy(original: FirImplicitTypeRef, init: FirImplicitTypeRefBuilder.() -> Unit): FirImplicitTypeRef {
|
||||
contract {
|
||||
callsInPlace(init, kotlin.contracts.InvocationKind.EXACTLY_ONCE)
|
||||
}
|
||||
val copyBuilder = FirImplicitTypeRefBuilder()
|
||||
original.source?.let { copyBuilder.source = it }
|
||||
return copyBuilder.apply(init).build()
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2023 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.
|
||||
*/
|
||||
|
||||
@file:Suppress("DuplicatedCode", "unused")
|
||||
|
||||
package org.jetbrains.kotlin.fir.types.impl
|
||||
|
||||
import org.jetbrains.kotlin.KtSourceElement
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
|
||||
import org.jetbrains.kotlin.fir.types.FirImplicitTypeRef
|
||||
import org.jetbrains.kotlin.fir.visitors.*
|
||||
import org.jetbrains.kotlin.fir.MutableOrEmptyList
|
||||
import org.jetbrains.kotlin.fir.builder.toMutableOrEmpty
|
||||
|
||||
/*
|
||||
* This file was generated automatically
|
||||
* DO NOT MODIFY IT MANUALLY
|
||||
*/
|
||||
|
||||
internal class FirImplicitTypeRefImpl(
|
||||
override val source: KtSourceElement,
|
||||
) : FirImplicitTypeRef() {
|
||||
override val annotations: List<FirAnnotation> get() = emptyList()
|
||||
|
||||
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
|
||||
}
|
||||
|
||||
override fun <D> transformChildren(transformer: FirTransformer<D>, data: D): FirImplicitTypeRefImpl {
|
||||
return this
|
||||
}
|
||||
|
||||
override fun <D> transformAnnotations(transformer: FirTransformer<D>, data: D): FirImplicitTypeRefImpl {
|
||||
return this
|
||||
}
|
||||
|
||||
override fun replaceAnnotations(newAnnotations: List<FirAnnotation>) {}
|
||||
}
|
||||
@@ -53,9 +53,6 @@ fun <R : FirTypeRef> R.copyWithNewSource(newSource: KtSourceElement?): R {
|
||||
qualifier += typeRef.qualifier
|
||||
annotations += typeRef.annotations
|
||||
}
|
||||
is FirImplicitTypeRef -> newSource?.let {
|
||||
buildImplicitTypeRefCopy(typeRef) { source = it }
|
||||
} ?: FirImplicitTypeRefImplWithoutSource
|
||||
is FirFunctionTypeRefImpl -> buildFunctionTypeRefCopy(typeRef) {
|
||||
source = newSource
|
||||
}
|
||||
|
||||
+1
-7
@@ -313,10 +313,6 @@ object BuilderConfigurator : AbstractBuilderConfigurator<FirTreeBuilder>(FirTree
|
||||
withCopy()
|
||||
}
|
||||
|
||||
builder(implicitTypeRef) {
|
||||
withCopy()
|
||||
}
|
||||
|
||||
builder(breakExpression) {
|
||||
parents += loopJumpBuilder
|
||||
}
|
||||
@@ -442,9 +438,7 @@ object BuilderConfigurator : AbstractBuilderConfigurator<FirTreeBuilder>(FirTree
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
findImplementationsWithElementInParents(annotationContainer) {
|
||||
it.type !in setOf("FirImplicitTypeRefImpl")
|
||||
}.forEach {
|
||||
findImplementationsWithElementInParents(annotationContainer).forEach {
|
||||
it.builder?.parents?.add(annotationContainerBuilder)
|
||||
}
|
||||
|
||||
|
||||
+1
-6
@@ -536,12 +536,7 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
|
||||
}
|
||||
|
||||
impl(functionTypeRef)
|
||||
impl(implicitTypeRef) {
|
||||
defaultEmptyList("annotations")
|
||||
default("source") {
|
||||
notNull = true
|
||||
}
|
||||
}
|
||||
noImpl(implicitTypeRef)
|
||||
|
||||
impl(reference, "FirStubReference") {
|
||||
default("source") {
|
||||
|
||||
Reference in New Issue
Block a user