[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
|
package org.jetbrains.kotlin.fir
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.KtSourceElement
|
||||||
import org.jetbrains.kotlin.builtins.StandardNames
|
import org.jetbrains.kotlin.builtins.StandardNames
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
|
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
|
||||||
import org.jetbrains.kotlin.fir.declarations.utils.expandedConeType
|
import org.jetbrains.kotlin.fir.declarations.utils.expandedConeType
|
||||||
@@ -40,17 +41,18 @@ inline fun FirFunctionCall.copyAsImplicitInvokeCall(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun FirTypeRef.resolvedTypeFromPrototype(
|
fun FirTypeRef.resolvedTypeFromPrototype(
|
||||||
type: ConeKotlinType
|
type: ConeKotlinType,
|
||||||
|
fallbackSource: KtSourceElement? = null,
|
||||||
): FirResolvedTypeRef {
|
): FirResolvedTypeRef {
|
||||||
return if (type is ConeErrorType) {
|
return if (type is ConeErrorType) {
|
||||||
buildErrorTypeRef {
|
buildErrorTypeRef {
|
||||||
source = this@resolvedTypeFromPrototype.source
|
source = this@resolvedTypeFromPrototype.source ?: fallbackSource
|
||||||
this.type = type
|
this.type = type
|
||||||
diagnostic = type.diagnostic
|
diagnostic = type.diagnostic
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
buildResolvedTypeRef {
|
buildResolvedTypeRef {
|
||||||
source = this@resolvedTypeFromPrototype.source
|
source = this@resolvedTypeFromPrototype.source ?: fallbackSource
|
||||||
this.type = type
|
this.type = type
|
||||||
delegatedTypeRef = when (val original = this@resolvedTypeFromPrototype) {
|
delegatedTypeRef = when (val original = this@resolvedTypeFromPrototype) {
|
||||||
is FirResolvedTypeRef -> original.delegatedTypeRef
|
is FirResolvedTypeRef -> original.delegatedTypeRef
|
||||||
|
|||||||
-3
@@ -2353,9 +2353,6 @@ class LightTreeRawFirDeclarationBuilder(
|
|||||||
modifiers = modifiers,
|
modifiers = modifiers,
|
||||||
returnTypeRef = firType
|
returnTypeRef = firType
|
||||||
?: when {
|
?: when {
|
||||||
valueParameterDeclaration == ValueParameterDeclaration.LAMBDA -> buildImplicitTypeRef {
|
|
||||||
source = valueParameterSource.fakeElement(KtFakeSourceElementKind.ImplicitReturnTypeOfLambdaValueParameter)
|
|
||||||
}
|
|
||||||
valueParameterDeclaration.shouldExplicitParameterTypeBePresent -> createNoTypeForParameterTypeRef()
|
valueParameterDeclaration.shouldExplicitParameterTypeBePresent -> createNoTypeForParameterTypeRef()
|
||||||
else -> implicitType
|
else -> implicitType
|
||||||
},
|
},
|
||||||
|
|||||||
+1
-1
@@ -146,7 +146,7 @@ class LightTreeRawFirExpressionBuilder(
|
|||||||
moduleData = baseModuleData
|
moduleData = baseModuleData
|
||||||
origin = FirDeclarationOrigin.Source
|
origin = FirDeclarationOrigin.Source
|
||||||
returnTypeRef = implicitType
|
returnTypeRef = implicitType
|
||||||
receiverParameter = implicitType.asReceiverParameter()
|
receiverParameter = expressionSource.asReceiverParameter()
|
||||||
symbol = functionSymbol
|
symbol = functionSymbol
|
||||||
isLambda = true
|
isLambda = true
|
||||||
hasExplicitParameterList = hasArrow
|
hasExplicitParameterList = hasArrow
|
||||||
|
|||||||
+4
-16
@@ -1680,21 +1680,14 @@ open class PsiRawFirBuilder(
|
|||||||
override fun visitLambdaExpression(expression: KtLambdaExpression, data: FirElement?): FirElement {
|
override fun visitLambdaExpression(expression: KtLambdaExpression, data: FirElement?): FirElement {
|
||||||
val literal = expression.functionLiteral
|
val literal = expression.functionLiteral
|
||||||
val literalSource = literal.toFirSourceElement()
|
val literalSource = literal.toFirSourceElement()
|
||||||
val implicitTypeRefSource = literal.toFirSourceElement(KtFakeSourceElementKind.ImplicitTypeRef)
|
|
||||||
val returnType = buildImplicitTypeRef {
|
|
||||||
source = implicitTypeRefSource
|
|
||||||
}
|
|
||||||
val receiverType = buildImplicitTypeRef {
|
|
||||||
source = implicitTypeRefSource
|
|
||||||
}
|
|
||||||
|
|
||||||
val target: FirFunctionTarget
|
val target: FirFunctionTarget
|
||||||
val anonymousFunction = buildAnonymousFunction {
|
val anonymousFunction = buildAnonymousFunction {
|
||||||
source = literalSource
|
source = literalSource
|
||||||
moduleData = baseModuleData
|
moduleData = baseModuleData
|
||||||
origin = FirDeclarationOrigin.Source
|
origin = FirDeclarationOrigin.Source
|
||||||
returnTypeRef = returnType
|
returnTypeRef = FirImplicitTypeRefImplWithoutSource
|
||||||
receiverParameter = receiverType.asReceiverParameter()
|
receiverParameter = literalSource.asReceiverParameter()
|
||||||
symbol = FirAnonymousFunctionSymbol()
|
symbol = FirAnonymousFunctionSymbol()
|
||||||
isLambda = true
|
isLambda = true
|
||||||
hasExplicitParameterList = expression.functionLiteral.arrow != null
|
hasExplicitParameterList = expression.functionLiteral.arrow != null
|
||||||
@@ -1709,9 +1702,7 @@ open class PsiRawFirBuilder(
|
|||||||
containingFunctionSymbol = this@buildAnonymousFunction.symbol
|
containingFunctionSymbol = this@buildAnonymousFunction.symbol
|
||||||
moduleData = baseModuleData
|
moduleData = baseModuleData
|
||||||
origin = FirDeclarationOrigin.Source
|
origin = FirDeclarationOrigin.Source
|
||||||
returnTypeRef = valueParameter.typeReference?.convertSafe() ?: buildImplicitTypeRef {
|
returnTypeRef = valueParameter.typeReference?.convertSafe() ?: FirImplicitTypeRefImplWithoutSource
|
||||||
source = multiDeclaration.toFirSourceElement(KtFakeSourceElementKind.ImplicitTypeRef)
|
|
||||||
}
|
|
||||||
this.name = name
|
this.name = name
|
||||||
symbol = FirValueParameterSymbol(name)
|
symbol = FirValueParameterSymbol(name)
|
||||||
isCrossinline = false
|
isCrossinline = false
|
||||||
@@ -1728,10 +1719,7 @@ open class PsiRawFirBuilder(
|
|||||||
) { toFirOrImplicitType() }.statements
|
) { toFirOrImplicitType() }.statements
|
||||||
multiParameter
|
multiParameter
|
||||||
} else {
|
} else {
|
||||||
val typeRef = valueParameter.typeReference?.convertSafe() ?: buildImplicitTypeRef {
|
val typeRef = valueParameter.typeReference?.convertSafe() ?: FirImplicitTypeRefImplWithoutSource
|
||||||
source = valueParameter.toFirSourceElement()
|
|
||||||
.fakeElement(KtFakeSourceElementKind.ImplicitReturnTypeOfLambdaValueParameter)
|
|
||||||
}
|
|
||||||
convertValueParameter(valueParameter, symbol, typeRef, ValueParameterDeclaration.LAMBDA)
|
convertValueParameter(valueParameter, symbol, typeRef, ValueParameterDeclaration.LAMBDA)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -625,9 +625,9 @@ fun FirTypeRef.convertToReceiverParameter(): FirReceiverParameter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun FirImplicitTypeRef.asReceiverParameter(): FirReceiverParameter = buildReceiverParameter {
|
fun KtSourceElement.asReceiverParameter(): FirReceiverParameter = buildReceiverParameter {
|
||||||
source = this@asReceiverParameter.source?.fakeElement(KtFakeSourceElementKind.ReceiverFromType)
|
source = this@asReceiverParameter.fakeElement(KtFakeSourceElementKind.ReceiverFromType)
|
||||||
typeRef = this@asReceiverParameter
|
typeRef = FirImplicitTypeRefImplWithoutSource
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T> FirCallableDeclaration.initContainingClassAttr(context: Context<T>) {
|
fun <T> FirCallableDeclaration.initContainingClassAttr(context: Context<T>) {
|
||||||
|
|||||||
+6
-1
@@ -282,7 +282,12 @@ class FirCallCompleter(
|
|||||||
lambdaArgument.replaceReceiverParameter(null)
|
lambdaArgument.replaceReceiverParameter(null)
|
||||||
} else {
|
} else {
|
||||||
lambdaArgument.receiverParameter?.apply {
|
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
|
param
|
||||||
} else {
|
} else {
|
||||||
val resolvedType =
|
val resolvedType =
|
||||||
param.returnTypeRef.resolvedTypeFromPrototype(expectedTypeParameterTypes[index])
|
param.returnTypeRef.resolvedTypeFromPrototype(
|
||||||
|
expectedTypeParameterTypes[index],
|
||||||
|
param.source?.fakeElement(KtFakeSourceElementKind.ImplicitReturnTypeOfLambdaValueParameter)
|
||||||
|
)
|
||||||
param.replaceReturnTypeRef(resolvedType)
|
param.replaceReturnTypeRef(resolvedType)
|
||||||
param
|
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
|
qualifier += typeRef.qualifier
|
||||||
annotations += typeRef.annotations
|
annotations += typeRef.annotations
|
||||||
}
|
}
|
||||||
is FirImplicitTypeRef -> newSource?.let {
|
|
||||||
buildImplicitTypeRefCopy(typeRef) { source = it }
|
|
||||||
} ?: FirImplicitTypeRefImplWithoutSource
|
|
||||||
is FirFunctionTypeRefImpl -> buildFunctionTypeRefCopy(typeRef) {
|
is FirFunctionTypeRefImpl -> buildFunctionTypeRefCopy(typeRef) {
|
||||||
source = newSource
|
source = newSource
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-7
@@ -313,10 +313,6 @@ object BuilderConfigurator : AbstractBuilderConfigurator<FirTreeBuilder>(FirTree
|
|||||||
withCopy()
|
withCopy()
|
||||||
}
|
}
|
||||||
|
|
||||||
builder(implicitTypeRef) {
|
|
||||||
withCopy()
|
|
||||||
}
|
|
||||||
|
|
||||||
builder(breakExpression) {
|
builder(breakExpression) {
|
||||||
parents += loopJumpBuilder
|
parents += loopJumpBuilder
|
||||||
}
|
}
|
||||||
@@ -442,9 +438,7 @@ object BuilderConfigurator : AbstractBuilderConfigurator<FirTreeBuilder>(FirTree
|
|||||||
|
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
|
|
||||||
findImplementationsWithElementInParents(annotationContainer) {
|
findImplementationsWithElementInParents(annotationContainer).forEach {
|
||||||
it.type !in setOf("FirImplicitTypeRefImpl")
|
|
||||||
}.forEach {
|
|
||||||
it.builder?.parents?.add(annotationContainerBuilder)
|
it.builder?.parents?.add(annotationContainerBuilder)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-6
@@ -536,12 +536,7 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl(functionTypeRef)
|
impl(functionTypeRef)
|
||||||
impl(implicitTypeRef) {
|
noImpl(implicitTypeRef)
|
||||||
defaultEmptyList("annotations")
|
|
||||||
default("source") {
|
|
||||||
notNull = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl(reference, "FirStubReference") {
|
impl(reference, "FirStubReference") {
|
||||||
default("source") {
|
default("source") {
|
||||||
|
|||||||
Reference in New Issue
Block a user