[FIR] Rename FirArrayOfCall to FirArrayLiteral

This commit is contained in:
Ivan Kochurkin
2023-07-21 20:10:15 +02:00
committed by Space Team
parent f4e4c5e724
commit 2eba7da5eb
49 changed files with 165 additions and 178 deletions
@@ -29,8 +29,6 @@ import org.jetbrains.kotlin.analysis.low.level.api.fir.api.getOrBuildFir
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.resolveToFirSymbolOfTypeSafe import org.jetbrains.kotlin.analysis.low.level.api.fir.api.resolveToFirSymbolOfTypeSafe
import org.jetbrains.kotlin.analysis.low.level.api.fir.resolver.AllCandidatesResolver import org.jetbrains.kotlin.analysis.low.level.api.fir.resolver.AllCandidatesResolver
import org.jetbrains.kotlin.analysis.low.level.api.fir.util.errorWithFirSpecificEntries import org.jetbrains.kotlin.analysis.low.level.api.fir.util.errorWithFirSpecificEntries
import org.jetbrains.kotlin.fir.utils.exceptions.withFirEntry
import org.jetbrains.kotlin.utils.exceptions.rethrowExceptionWithDetails
import org.jetbrains.kotlin.analysis.utils.errors.withPsiEntry import org.jetbrains.kotlin.analysis.utils.errors.withPsiEntry
import org.jetbrains.kotlin.analysis.utils.printer.parentOfType import org.jetbrains.kotlin.analysis.utils.printer.parentOfType
import org.jetbrains.kotlin.fir.FirElement import org.jetbrains.kotlin.fir.FirElement
@@ -59,6 +57,7 @@ import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope
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.*
import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.fir.types.*
import org.jetbrains.kotlin.fir.utils.exceptions.withFirEntry
import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.*
@@ -72,6 +71,7 @@ import org.jetbrains.kotlin.util.OperatorNameConventions.EQUALS
import org.jetbrains.kotlin.utils.addIfNotNull import org.jetbrains.kotlin.utils.addIfNotNull
import org.jetbrains.kotlin.utils.addToStdlib.safeAs import org.jetbrains.kotlin.utils.addToStdlib.safeAs
import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment
import org.jetbrains.kotlin.utils.exceptions.rethrowExceptionWithDetails
internal class KtFirCallResolver( internal class KtFirCallResolver(
override val analysisSession: KtFirAnalysisSession, override val analysisSession: KtFirAnalysisSession,
@@ -245,7 +245,7 @@ internal class KtFirCallResolver(
else -> null else -> null
} }
} }
is FirArrayOfCall -> toKtCallInfo() is FirArrayLiteral -> toKtCallInfo()
is FirComparisonExpression -> compareToCall.toKtCallInfo( is FirComparisonExpression -> compareToCall.toKtCallInfo(
psi, psi,
resolveCalleeExpressionOfFunctionCall, resolveCalleeExpressionOfFunctionCall,
@@ -872,7 +872,7 @@ internal class KtFirCallResolver(
return result return result
} }
private fun FirArrayOfCall.toTypeArgumentsMapping( private fun FirArrayLiteral.toTypeArgumentsMapping(
partiallyAppliedSymbol: KtPartiallyAppliedSymbol<*, *> partiallyAppliedSymbol: KtPartiallyAppliedSymbol<*, *>
): Map<KtTypeParameterSymbol, KtType> { ): Map<KtTypeParameterSymbol, KtType> {
val elementType = typeRef.coneTypeSafe<ConeClassLikeType>()?.arrayElementType()?.asKtType() ?: return emptyMap() val elementType = typeRef.coneTypeSafe<ConeClassLikeType>()?.arrayElementType()?.asKtType() ?: return emptyMap()
@@ -929,7 +929,7 @@ internal class KtFirCallResolver(
resolveCalleeExpressionOfFunctionCall, resolveCalleeExpressionOfFunctionCall,
resolveFragmentOfCall resolveFragmentOfCall
) )
is FirArrayOfCall, is FirEqualityOperatorCall -> { is FirArrayLiteral, is FirEqualityOperatorCall -> {
toKtCallInfo(psi, resolveCalleeExpressionOfFunctionCall, resolveFragmentOfCall).toKtCallCandidateInfos() toKtCallInfo(psi, resolveCalleeExpressionOfFunctionCall, resolveFragmentOfCall).toKtCallCandidateInfos()
} }
is FirComparisonExpression -> compareToCall.toKtCallInfo( is FirComparisonExpression -> compareToCall.toKtCallInfo(
@@ -1107,7 +1107,7 @@ internal class KtFirCallResolver(
} }
} }
private fun FirArrayOfCall.toKtCallInfo(): KtCallInfo? { private fun FirArrayLiteral.toKtCallInfo(): KtCallInfo? {
val arrayOfSymbol = with(analysisSession) { val arrayOfSymbol = with(analysisSession) {
val type = typeRef.coneTypeSafe<ConeClassLikeType>() val type = typeRef.coneTypeSafe<ConeClassLikeType>()
?: return run { ?: return run {
@@ -1150,7 +1150,7 @@ internal class KtFirCallResolver(
) )
} }
private fun FirArrayOfCall.createSubstitutorFromTypeArguments(arrayOfSymbol: KtFirFunctionSymbol): KtSubstitutor { private fun FirArrayLiteral.createSubstitutorFromTypeArguments(arrayOfSymbol: KtFirFunctionSymbol): KtSubstitutor {
val firSymbol = arrayOfSymbol.firSymbol val firSymbol = arrayOfSymbol.firSymbol
// No type parameter means this is an arrayOf call of primitives, in which case there is no type arguments // No type parameter means this is an arrayOf call of primitives, in which case there is no type arguments
val typeParameter = firSymbol.fir.typeParameters.singleOrNull() ?: return KtSubstitutor.Empty(token) val typeParameter = firSymbol.fir.typeParameters.singleOrNull() ?: return KtSubstitutor.Empty(token)
@@ -1239,12 +1239,12 @@ internal class KtFirCallResolver(
return ktArgumentMapping return ktArgumentMapping
} }
private fun FirArrayOfCall.createArgumentMapping( private fun FirArrayLiteral.createArgumentMapping(
arrayOfCallSymbol: KtFirFunctionSymbol, arrayOfSymbol: KtFirFunctionSymbol,
substitutor: KtSubstitutor, substitutor: KtSubstitutor,
): LinkedHashMap<KtExpression, KtVariableLikeSignature<KtValueParameterSymbol>> { ): LinkedHashMap<KtExpression, KtVariableLikeSignature<KtValueParameterSymbol>> {
val ktArgumentMapping = LinkedHashMap<KtExpression, KtVariableLikeSignature<KtValueParameterSymbol>>() val ktArgumentMapping = LinkedHashMap<KtExpression, KtVariableLikeSignature<KtValueParameterSymbol>>()
val parameterSymbol = arrayOfCallSymbol.valueParameters.single() val parameterSymbol = arrayOfSymbol.valueParameters.single()
for (firExpression in argumentList.arguments) { for (firExpression in argumentList.arguments) {
mapArgumentExpressionToParameter( mapArgumentExpressionToParameter(
@@ -115,7 +115,7 @@ internal object FirAnnotationValueConverter {
KtArrayAnnotationValue(annotationValues, representativePsi ?: sourcePsi) KtArrayAnnotationValue(annotationValues, representativePsi ?: sourcePsi)
} }
is FirArrayOfCall -> { is FirArrayLiteral -> {
// Desugared collection literals. // Desugared collection literals.
KtArrayAnnotationValue(argumentList.arguments.convertVarargsExpression(session).first, sourcePsi) KtArrayAnnotationValue(argumentList.arguments.convertVarargsExpression(session).first, sourcePsi)
} }
@@ -227,7 +227,7 @@ internal object FirReferenceResolveHelper {
is FirResolvedImport -> getSymbolsByResolvedImport(expression, symbolBuilder, fir, session) is FirResolvedImport -> getSymbolsByResolvedImport(expression, symbolBuilder, fir, session)
is FirPackageDirective -> getSymbolsForPackageDirective(expression, symbolBuilder) is FirPackageDirective -> getSymbolsForPackageDirective(expression, symbolBuilder)
is FirFile -> getSymbolsByFirFile(symbolBuilder, fir) is FirFile -> getSymbolsByFirFile(symbolBuilder, fir)
is FirArrayOfCall -> { is FirArrayLiteral -> {
// We can't yet find PsiElement for arrayOf, intArrayOf, etc. // We can't yet find PsiElement for arrayOf, intArrayOf, etc.
emptyList() emptyList()
} }
@@ -12,7 +12,7 @@ import org.jetbrains.kotlin.analysis.api.fir.symbols.KtFirArrayOfSymbolProvider.
import org.jetbrains.kotlin.analysis.api.fir.symbols.KtFirArrayOfSymbolProvider.arrayTypeToArrayOfCall import org.jetbrains.kotlin.analysis.api.fir.symbols.KtFirArrayOfSymbolProvider.arrayTypeToArrayOfCall
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.getOrBuildFirSafe import org.jetbrains.kotlin.analysis.low.level.api.fir.api.getOrBuildFirSafe
import org.jetbrains.kotlin.fir.expressions.FirArrayOfCall import org.jetbrains.kotlin.fir.expressions.FirArrayLiteral
import org.jetbrains.kotlin.fir.types.ConeClassLikeType import org.jetbrains.kotlin.fir.types.ConeClassLikeType
import org.jetbrains.kotlin.fir.types.coneTypeSafe import org.jetbrains.kotlin.fir.types.coneTypeSafe
@@ -23,7 +23,7 @@ class KtFirCollectionLiteralReference(
) : KtCollectionLiteralReference(expression), KtFirReference { ) : KtCollectionLiteralReference(expression), KtFirReference {
override fun KtAnalysisSession.resolveToSymbols(): Collection<KtSymbol> { override fun KtAnalysisSession.resolveToSymbols(): Collection<KtSymbol> {
check(this is KtFirAnalysisSession) check(this is KtFirAnalysisSession)
val fir = element.getOrBuildFirSafe<FirArrayOfCall>(firResolveSession) ?: return emptyList() val fir = element.getOrBuildFirSafe<FirArrayLiteral>(firResolveSession) ?: return emptyList()
val type = fir.typeRef.coneTypeSafe<ConeClassLikeType>() ?: return listOfNotNull(arrayOfSymbol(arrayOf)) val type = fir.typeRef.coneTypeSafe<ConeClassLikeType>() ?: return listOfNotNull(arrayOfSymbol(arrayOf))
val call = arrayTypeToArrayOfCall[type.lookupTag.classId] ?: arrayOf val call = arrayTypeToArrayOfCall[type.lookupTag.classId] ?: arrayOf
return listOfNotNull(arrayOfSymbol(call)) return listOfNotNull(arrayOfSymbol(call))
@@ -120,7 +120,7 @@ class StubBasedAnnotationDeserializer(
) )
} }
is ArrayValue -> { is ArrayValue -> {
buildArrayOfCall { buildArrayLiteral {
source = KtRealPsiSourceElement(sourceElement) source = KtRealPsiSourceElement(sourceElement)
typeRef = buildResolvedTypeRef { typeRef = buildResolvedTypeRef {
// Not quite precise, yet doesn't require annotation resolution // Not quite precise, yet doesn't require annotation resolution
@@ -60,7 +60,7 @@ fun main(args: Array<String>) {
alias<FirWhileLoop>("WhileLoopChecker") alias<FirWhileLoop>("WhileLoopChecker")
alias<FirThrowExpression>("ThrowExpressionChecker") alias<FirThrowExpression>("ThrowExpressionChecker")
alias<FirDoWhileLoop>("DoWhileLoopChecker") alias<FirDoWhileLoop>("DoWhileLoopChecker")
alias<FirArrayOfCall>("ArrayOfCallChecker") alias<FirArrayLiteral>("ArrayLiteralChecker")
alias<FirClassReferenceExpression>("ClassReferenceExpressionChecker") alias<FirClassReferenceExpression>("ClassReferenceExpressionChecker")
alias<FirInaccessibleReceiverExpression>("InaccessibleReceiverChecker") alias<FirInaccessibleReceiverExpression>("InaccessibleReceiverChecker")
} }
@@ -73,8 +73,8 @@ class ComposedExpressionCheckers : ExpressionCheckers() {
get() = _throwExpressionCheckers get() = _throwExpressionCheckers
override val doWhileLoopCheckers: Set<FirDoWhileLoopChecker> override val doWhileLoopCheckers: Set<FirDoWhileLoopChecker>
get() = _doWhileLoopCheckers get() = _doWhileLoopCheckers
override val arrayOfCallCheckers: Set<FirArrayOfCallChecker> override val arrayLiteralCheckers: Set<FirArrayLiteralChecker>
get() = _arrayOfCallCheckers get() = _arrayLiteralCheckers
override val classReferenceExpressionCheckers: Set<FirClassReferenceExpressionChecker> override val classReferenceExpressionCheckers: Set<FirClassReferenceExpressionChecker>
get() = _classReferenceExpressionCheckers get() = _classReferenceExpressionCheckers
override val inaccessibleReceiverCheckers: Set<FirInaccessibleReceiverChecker> override val inaccessibleReceiverCheckers: Set<FirInaccessibleReceiverChecker>
@@ -110,7 +110,7 @@ class ComposedExpressionCheckers : ExpressionCheckers() {
private val _whileLoopCheckers: MutableSet<FirWhileLoopChecker> = mutableSetOf() private val _whileLoopCheckers: MutableSet<FirWhileLoopChecker> = mutableSetOf()
private val _throwExpressionCheckers: MutableSet<FirThrowExpressionChecker> = mutableSetOf() private val _throwExpressionCheckers: MutableSet<FirThrowExpressionChecker> = mutableSetOf()
private val _doWhileLoopCheckers: MutableSet<FirDoWhileLoopChecker> = mutableSetOf() private val _doWhileLoopCheckers: MutableSet<FirDoWhileLoopChecker> = mutableSetOf()
private val _arrayOfCallCheckers: MutableSet<FirArrayOfCallChecker> = mutableSetOf() private val _arrayLiteralCheckers: MutableSet<FirArrayLiteralChecker> = mutableSetOf()
private val _classReferenceExpressionCheckers: MutableSet<FirClassReferenceExpressionChecker> = mutableSetOf() private val _classReferenceExpressionCheckers: MutableSet<FirClassReferenceExpressionChecker> = mutableSetOf()
private val _inaccessibleReceiverCheckers: MutableSet<FirInaccessibleReceiverChecker> = mutableSetOf() private val _inaccessibleReceiverCheckers: MutableSet<FirInaccessibleReceiverChecker> = mutableSetOf()
@@ -146,7 +146,7 @@ class ComposedExpressionCheckers : ExpressionCheckers() {
_whileLoopCheckers += checkers.whileLoopCheckers _whileLoopCheckers += checkers.whileLoopCheckers
_throwExpressionCheckers += checkers.throwExpressionCheckers _throwExpressionCheckers += checkers.throwExpressionCheckers
_doWhileLoopCheckers += checkers.doWhileLoopCheckers _doWhileLoopCheckers += checkers.doWhileLoopCheckers
_arrayOfCallCheckers += checkers.arrayOfCallCheckers _arrayLiteralCheckers += checkers.arrayLiteralCheckers
_classReferenceExpressionCheckers += checkers.classReferenceExpressionCheckers _classReferenceExpressionCheckers += checkers.classReferenceExpressionCheckers
_inaccessibleReceiverCheckers += checkers.inaccessibleReceiverCheckers _inaccessibleReceiverCheckers += checkers.inaccessibleReceiverCheckers
} }
@@ -47,7 +47,7 @@ abstract class ExpressionCheckers {
open val whileLoopCheckers: Set<FirWhileLoopChecker> = emptySet() open val whileLoopCheckers: Set<FirWhileLoopChecker> = emptySet()
open val throwExpressionCheckers: Set<FirThrowExpressionChecker> = emptySet() open val throwExpressionCheckers: Set<FirThrowExpressionChecker> = emptySet()
open val doWhileLoopCheckers: Set<FirDoWhileLoopChecker> = emptySet() open val doWhileLoopCheckers: Set<FirDoWhileLoopChecker> = emptySet()
open val arrayOfCallCheckers: Set<FirArrayOfCallChecker> = emptySet() open val arrayLiteralCheckers: Set<FirArrayLiteralChecker> = emptySet()
open val classReferenceExpressionCheckers: Set<FirClassReferenceExpressionChecker> = emptySet() open val classReferenceExpressionCheckers: Set<FirClassReferenceExpressionChecker> = emptySet()
open val inaccessibleReceiverCheckers: Set<FirInaccessibleReceiverChecker> = emptySet() open val inaccessibleReceiverCheckers: Set<FirInaccessibleReceiverChecker> = emptySet()
@@ -81,7 +81,7 @@ abstract class ExpressionCheckers {
@CheckersComponentInternal internal val allWhileLoopCheckers: Set<FirWhileLoopChecker> by lazy { whileLoopCheckers + loopExpressionCheckers + basicExpressionCheckers } @CheckersComponentInternal internal val allWhileLoopCheckers: Set<FirWhileLoopChecker> by lazy { whileLoopCheckers + loopExpressionCheckers + basicExpressionCheckers }
@CheckersComponentInternal internal val allThrowExpressionCheckers: Set<FirThrowExpressionChecker> by lazy { throwExpressionCheckers + basicExpressionCheckers } @CheckersComponentInternal internal val allThrowExpressionCheckers: Set<FirThrowExpressionChecker> by lazy { throwExpressionCheckers + basicExpressionCheckers }
@CheckersComponentInternal internal val allDoWhileLoopCheckers: Set<FirDoWhileLoopChecker> by lazy { doWhileLoopCheckers + loopExpressionCheckers + basicExpressionCheckers } @CheckersComponentInternal internal val allDoWhileLoopCheckers: Set<FirDoWhileLoopChecker> by lazy { doWhileLoopCheckers + loopExpressionCheckers + basicExpressionCheckers }
@CheckersComponentInternal internal val allArrayOfCallCheckers: Set<FirArrayOfCallChecker> by lazy { arrayOfCallCheckers + basicExpressionCheckers + callCheckers } @CheckersComponentInternal internal val allArrayLiteralCheckers: Set<FirArrayLiteralChecker> by lazy { arrayLiteralCheckers + basicExpressionCheckers + callCheckers }
@CheckersComponentInternal internal val allClassReferenceExpressionCheckers: Set<FirClassReferenceExpressionChecker> by lazy { classReferenceExpressionCheckers + basicExpressionCheckers } @CheckersComponentInternal internal val allClassReferenceExpressionCheckers: Set<FirClassReferenceExpressionChecker> by lazy { classReferenceExpressionCheckers + basicExpressionCheckers }
@CheckersComponentInternal internal val allInaccessibleReceiverCheckers: Set<FirInaccessibleReceiverChecker> by lazy { inaccessibleReceiverCheckers + basicExpressionCheckers } @CheckersComponentInternal internal val allInaccessibleReceiverCheckers: Set<FirInaccessibleReceiverChecker> by lazy { inaccessibleReceiverCheckers + basicExpressionCheckers }
} }
@@ -12,7 +12,7 @@ package org.jetbrains.kotlin.fir.analysis.checkers.expression
import org.jetbrains.kotlin.fir.expressions.FirAnnotation import org.jetbrains.kotlin.fir.expressions.FirAnnotation
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
import org.jetbrains.kotlin.fir.expressions.FirArrayOfCall import org.jetbrains.kotlin.fir.expressions.FirArrayLiteral
import org.jetbrains.kotlin.fir.expressions.FirBinaryLogicExpression import org.jetbrains.kotlin.fir.expressions.FirBinaryLogicExpression
import org.jetbrains.kotlin.fir.expressions.FirBlock import org.jetbrains.kotlin.fir.expressions.FirBlock
import org.jetbrains.kotlin.fir.expressions.FirCall import org.jetbrains.kotlin.fir.expressions.FirCall
@@ -74,6 +74,6 @@ typealias FirThisReceiverExpressionChecker = FirExpressionChecker<FirThisReceive
typealias FirWhileLoopChecker = FirExpressionChecker<FirWhileLoop> typealias FirWhileLoopChecker = FirExpressionChecker<FirWhileLoop>
typealias FirThrowExpressionChecker = FirExpressionChecker<FirThrowExpression> typealias FirThrowExpressionChecker = FirExpressionChecker<FirThrowExpression>
typealias FirDoWhileLoopChecker = FirExpressionChecker<FirDoWhileLoop> typealias FirDoWhileLoopChecker = FirExpressionChecker<FirDoWhileLoop>
typealias FirArrayOfCallChecker = FirExpressionChecker<FirArrayOfCall> typealias FirArrayLiteralChecker = FirExpressionChecker<FirArrayLiteral>
typealias FirClassReferenceExpressionChecker = FirExpressionChecker<FirClassReferenceExpression> typealias FirClassReferenceExpressionChecker = FirExpressionChecker<FirClassReferenceExpression>
typealias FirInaccessibleReceiverChecker = FirExpressionChecker<FirInaccessibleReceiverExpression> typealias FirInaccessibleReceiverChecker = FirExpressionChecker<FirInaccessibleReceiverExpression>
@@ -165,7 +165,7 @@ object CommonExpressionCheckers : ExpressionCheckers() {
FirEqualityCompatibilityChecker, FirEqualityCompatibilityChecker,
) )
override val arrayOfCallCheckers: Set<FirArrayOfCallChecker> override val arrayLiteralCheckers: Set<FirArrayLiteralChecker>
get() = setOf( get() = setOf(
FirUnsupportedArrayLiteralChecker FirUnsupportedArrayLiteralChecker
) )
@@ -81,7 +81,7 @@ object FirAnnotationExpressionChecker : FirAnnotationCallChecker() {
} }
when (expression) { when (expression) {
is FirArrayOfCall -> return checkArgumentList(expression.argumentList) is FirArrayLiteral -> return checkArgumentList(expression.argumentList)
is FirVarargArgumentsExpression -> { is FirVarargArgumentsExpression -> {
for (arg in expression.arguments) { for (arg in expression.arguments) {
val unwrappedArg = arg.unwrapArgument() val unwrappedArg = arg.unwrapArgument()
@@ -11,10 +11,10 @@
package org.jetbrains.kotlin.fir.analysis.checkers.expression package org.jetbrains.kotlin.fir.analysis.checkers.expression
import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
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.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
import org.jetbrains.kotlin.fir.expressions.* import org.jetbrains.kotlin.fir.expressions.*
import org.jetbrains.kotlin.fir.languageVersionSettings import org.jetbrains.kotlin.fir.languageVersionSettings
import org.jetbrains.kotlin.fir.references.FirErrorNamedReference import org.jetbrains.kotlin.fir.references.FirErrorNamedReference
@@ -25,7 +25,7 @@ object FirNamedVarargChecker : FirCallChecker() {
if (expression !is FirFunctionCall && if (expression !is FirFunctionCall &&
expression !is FirAnnotation && expression !is FirAnnotation &&
expression !is FirDelegatedConstructorCall && expression !is FirDelegatedConstructorCall &&
expression !is FirArrayOfCall) return expression !is FirArrayLiteral) return
val isAnnotation = expression is FirAnnotation val isAnnotation = expression is FirAnnotation
val redundantSpreadWarningFactory = val redundantSpreadWarningFactory =
if (isAnnotation) FirErrors.REDUNDANT_SPREAD_OPERATOR_IN_NAMED_FORM_IN_ANNOTATION if (isAnnotation) FirErrors.REDUNDANT_SPREAD_OPERATOR_IN_NAMED_FORM_IN_ANNOTATION
@@ -46,7 +46,7 @@ object FirNamedVarargChecker : FirCallChecker() {
} }
val typeRef = argument.expression.typeRef val typeRef = argument.expression.typeRef
if (typeRef is FirErrorTypeRef) return if (typeRef is FirErrorTypeRef) return
if (argument.expression is FirArrayOfCall) return if (argument.expression is FirArrayLiteral) return
@OptIn(UnexpandedTypeCheck::class) @OptIn(UnexpandedTypeCheck::class)
if (allowAssignArray && typeRef.isArrayType) return if (allowAssignArray && typeRef.isArrayType) return
@@ -68,8 +68,8 @@ object FirNamedVarargChecker : FirCallChecker() {
} }
} }
if (expression is FirArrayOfCall) { if (expression is FirArrayLiteral) {
// FirArrayOfCall has the `vararg` argument expression pre-flattened and doesn't have an argument mapping. // FirArrayLiteral has the `vararg` argument expression pre-flattened and doesn't have an argument mapping.
expression.arguments.forEach { checkArgument(it, it is FirNamedArgumentExpression, expression.typeRef.coneTypeOrNull) } expression.arguments.forEach { checkArgument(it, it is FirNamedArgumentExpression, expression.typeRef.coneTypeOrNull) }
} else { } else {
val argumentMap = expression.resolvedArgumentMapping ?: return val argumentMap = expression.resolvedArgumentMapping ?: return
@@ -17,8 +17,8 @@ import org.jetbrains.kotlin.fir.declarations.impl.FirPrimaryConstructor
import org.jetbrains.kotlin.fir.declarations.utils.isCompanion import org.jetbrains.kotlin.fir.declarations.utils.isCompanion
import org.jetbrains.kotlin.fir.expressions.* import org.jetbrains.kotlin.fir.expressions.*
object FirUnsupportedArrayLiteralChecker : FirArrayOfCallChecker() { object FirUnsupportedArrayLiteralChecker : FirArrayLiteralChecker() {
override fun check(expression: FirArrayOfCall, context: CheckerContext, reporter: DiagnosticReporter) { override fun check(expression: FirArrayLiteral, context: CheckerContext, reporter: DiagnosticReporter) {
if (!isInsideAnnotationCall(expression, context) && if (!isInsideAnnotationCall(expression, context) &&
(context.callsOrAssignments.isNotEmpty() || !isInsideAnnotationClass(context)) (context.callsOrAssignments.isNotEmpty() || !isInsideAnnotationClass(context))
) { ) {
@@ -31,7 +31,7 @@ object FirUnsupportedArrayLiteralChecker : FirArrayOfCallChecker() {
} }
} }
private fun isInsideAnnotationCall(expression: FirArrayOfCall, context: CheckerContext): Boolean { private fun isInsideAnnotationCall(expression: FirArrayLiteral, context: CheckerContext): Boolean {
context.callsOrAssignments.lastOrNull()?.let { context.callsOrAssignments.lastOrNull()?.let {
val arguments = when (it) { val arguments = when (it) {
is FirFunctionCall -> is FirFunctionCall ->
@@ -55,8 +55,8 @@ object FirUnsupportedArrayLiteralChecker : FirArrayOfCallChecker() {
for (unwrapped in unwrappedArguments) { for (unwrapped in unwrappedArguments) {
if (unwrapped == expression || if (unwrapped == expression ||
(unwrapped is FirErrorExpression && unwrapped.expression == expression) || (unwrapped is FirErrorExpression && unwrapped.expression == expression) ||
unwrapped is FirArrayOfCall && unwrapped is FirArrayLiteral &&
unwrapped.arguments.any { arrayOfCallElement -> arrayOfCallElement.unwrapArgument() == expression } unwrapped.arguments.any { arrayLiteralElement -> arrayLiteralElement.unwrapArgument() == expression }
) { ) {
return@any true return@any true
} }
@@ -118,8 +118,8 @@ class ExpressionCheckersDiagnosticComponent(
checkers.allLogicExpressionCheckers.check(binaryLogicExpression, data) checkers.allLogicExpressionCheckers.check(binaryLogicExpression, data)
} }
override fun visitArrayOfCall(arrayOfCall: FirArrayOfCall, data: CheckerContext) { override fun visitArrayLiteral(arrayLiteral: FirArrayLiteral, data: CheckerContext) {
checkers.allArrayOfCallCheckers.check(arrayOfCall, data) checkers.allArrayLiteralCheckers.check(arrayLiteral, data)
} }
override fun visitStringConcatenationCall(stringConcatenationCall: FirStringConcatenationCall, data: CheckerContext) { override fun visitStringConcatenationCall(stringConcatenationCall: FirStringConcatenationCall, data: CheckerContext) {
@@ -305,7 +305,7 @@ abstract class AbstractAnnotationDeserializer(
} }
ARRAY -> { ARRAY -> {
val expectedArrayElementType = expectedType()?.arrayElementType() ?: session.builtinTypes.anyType.type val expectedArrayElementType = expectedType()?.arrayElementType() ?: session.builtinTypes.anyType.type
buildArrayOfCall { buildArrayLiteral {
argumentList = buildArgumentList { argumentList = buildArgumentList {
value.arrayElementList.mapTo(arguments) { resolveValue(it, nameResolver) { expectedArrayElementType } } value.arrayElementList.mapTo(arguments) { resolveValue(it, nameResolver) { expectedArrayElementType } }
} }
@@ -92,11 +92,11 @@ internal object FirToConstantValueTransformer : FirDefaultVisitor<ConstantValue<
return StringValue(strings.joinToString(separator = "") { (it as StringValue).value }) return StringValue(strings.joinToString(separator = "") { (it as StringValue).value })
} }
override fun visitArrayOfCall( override fun visitArrayLiteral(
arrayOfCall: FirArrayOfCall, arrayLiteral: FirArrayLiteral,
data: FirToConstantValueTransformerData data: FirToConstantValueTransformerData
): ConstantValue<*> { ): ConstantValue<*> {
return ArrayValue(arrayOfCall.argumentList.arguments.mapNotNull { it.toConstantValue(data) }) return ArrayValue(arrayLiteral.argumentList.arguments.mapNotNull { it.toConstantValue(data) })
} }
override fun visitAnnotation( override fun visitAnnotation(
@@ -207,9 +207,9 @@ internal object FirToConstantValueTransformer : FirDefaultVisitor<ConstantValue<
data: FirToConstantValueTransformerData, data: FirToConstantValueTransformerData,
): ConstantValue<*> { ): ConstantValue<*> {
val arguments = varargArgumentsExpression.arguments.let { val arguments = varargArgumentsExpression.arguments.let {
// Named, spread or array literal arguments for vararg parameters have the form Vararg(Named/Spread?(ArrayOfCall(..))). // Named, spread or array literal arguments for vararg parameters have the form Vararg(Named/Spread?(ArrayLiteral(..))).
// We need to extract the ArrayOfCall, otherwise we will get two nested ArrayValue as a result. // We need to extract the ArrayLiteral, otherwise we will get two nested ArrayValue as a result.
(it.singleOrNull()?.unwrapArgument() as? FirArrayOfCall)?.arguments ?: it (it.singleOrNull()?.unwrapArgument() as? FirArrayLiteral)?.arguments ?: it
} }
return ArrayValue(arguments.mapNotNull { it.toConstantValue(data) }) return ArrayValue(arguments.mapNotNull { it.toConstantValue(data) })
@@ -246,8 +246,8 @@ internal object FirToConstantValueChecker : FirDefaultVisitor<Boolean, FirSessio
return stringConcatenationCall.argumentList.arguments.all { it.accept(this, data) } return stringConcatenationCall.argumentList.arguments.all { it.accept(this, data) }
} }
override fun visitArrayOfCall(arrayOfCall: FirArrayOfCall, data: FirSession): Boolean { override fun visitArrayLiteral(arrayLiteral: FirArrayLiteral, data: FirSession): Boolean {
return arrayOfCall.arguments.all { it.accept(this, data) } return arrayLiteral.arguments.all { it.accept(this, data) }
} }
override fun visitAnnotation(annotation: FirAnnotation, data: FirSession): Boolean = true override fun visitAnnotation(annotation: FirAnnotation, data: FirSession): Boolean = true
@@ -83,7 +83,7 @@ class Fir2IrImplicitCastInserter(
override fun visitStringConcatenationCall(stringConcatenationCall: FirStringConcatenationCall, data: IrElement): IrElement = data override fun visitStringConcatenationCall(stringConcatenationCall: FirStringConcatenationCall, data: IrElement): IrElement = data
// TODO: element-wise cast? // TODO: element-wise cast?
override fun visitArrayOfCall(arrayOfCall: FirArrayOfCall, data: IrElement): IrElement = data override fun visitArrayLiteral(arrayLiteral: FirArrayLiteral, data: IrElement): IrElement = data
// TODO: something to do w.r.t. SAM? // TODO: something to do w.r.t. SAM?
override fun visitLambdaArgumentExpression(lambdaArgumentExpression: FirLambdaArgumentExpression, data: IrElement): IrElement = data override fun visitLambdaArgumentExpression(lambdaArgumentExpression: FirLambdaArgumentExpression, data: IrElement): IrElement = data
@@ -1469,10 +1469,10 @@ class Fir2IrVisitor(
classifierStorage.getIrClassSymbol(it) classifierStorage.getIrClassSymbol(it)
} }
private fun convertToArrayOfCall(arrayOfCall: FirArrayOfCall): IrVararg { private fun convertToArrayLiteral(arrayLiteral: FirArrayLiteral): IrVararg {
return arrayOfCall.convertWithOffsets { startOffset, endOffset -> return arrayLiteral.convertWithOffsets { startOffset, endOffset ->
val arrayType = arrayOfCall.typeRef.toIrType() val arrayType = arrayLiteral.typeRef.toIrType()
val elementType = if (arrayOfCall.typeRef is FirResolvedTypeRef) { val elementType = if (arrayLiteral.typeRef is FirResolvedTypeRef) {
arrayType.getArrayElementType(irBuiltIns) arrayType.getArrayElementType(irBuiltIns)
} else { } else {
createErrorType() createErrorType()
@@ -1481,13 +1481,13 @@ class Fir2IrVisitor(
startOffset, endOffset, startOffset, endOffset,
type = arrayType, type = arrayType,
varargElementType = elementType, varargElementType = elementType,
elements = arrayOfCall.arguments.map { it.convertToIrVarargElement() } elements = arrayLiteral.arguments.map { it.convertToIrVarargElement() }
) )
} }
} }
override fun visitArrayOfCall(arrayOfCall: FirArrayOfCall, data: Any?): IrElement = whileAnalysing(session, arrayOfCall) { override fun visitArrayLiteral(arrayLiteral: FirArrayLiteral, data: Any?): IrElement = whileAnalysing(session, arrayLiteral) {
return convertToArrayOfCall(arrayOfCall) return convertToArrayLiteral(arrayLiteral)
} }
override fun visitAugmentedArraySetCall( override fun visitAugmentedArraySetCall(
@@ -10,11 +10,10 @@ import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic
import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind
import org.jetbrains.kotlin.fir.expressions.FirArrayOfCall import org.jetbrains.kotlin.fir.expressions.FirArrayLiteral
import org.jetbrains.kotlin.fir.expressions.FirConstExpression
import org.jetbrains.kotlin.fir.expressions.FirExpression import org.jetbrains.kotlin.fir.expressions.FirExpression
import org.jetbrains.kotlin.fir.expressions.builder.buildArgumentList import org.jetbrains.kotlin.fir.expressions.builder.buildArgumentList
import org.jetbrains.kotlin.fir.expressions.builder.buildArrayOfCall import org.jetbrains.kotlin.fir.expressions.builder.buildArrayLiteral
import org.jetbrains.kotlin.fir.expressions.builder.buildConstExpression import org.jetbrains.kotlin.fir.expressions.builder.buildConstExpression
import org.jetbrains.kotlin.fir.expressions.builder.buildErrorExpression import org.jetbrains.kotlin.fir.expressions.builder.buildErrorExpression
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.expectedConeType import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.expectedConeType
@@ -90,14 +89,14 @@ internal fun Any?.createConstantIfAny(session: FirSession, unsigned: Boolean = f
is String -> buildConstExpression( is String -> buildConstExpression(
null, ConstantValueKind.String, this, setType = true null, ConstantValueKind.String, this, setType = true
) )
is ByteArray -> toList().createArrayOfCall(session, ConstantValueKind.Byte) is ByteArray -> toList().createArrayLiteral(session, ConstantValueKind.Byte)
is ShortArray -> toList().createArrayOfCall(session, ConstantValueKind.Short) is ShortArray -> toList().createArrayLiteral(session, ConstantValueKind.Short)
is IntArray -> toList().createArrayOfCall(session, ConstantValueKind.Int) is IntArray -> toList().createArrayLiteral(session, ConstantValueKind.Int)
is LongArray -> toList().createArrayOfCall(session, ConstantValueKind.Long) is LongArray -> toList().createArrayLiteral(session, ConstantValueKind.Long)
is CharArray -> toList().createArrayOfCall(session, ConstantValueKind.Char) is CharArray -> toList().createArrayLiteral(session, ConstantValueKind.Char)
is FloatArray -> toList().createArrayOfCall(session, ConstantValueKind.Float) is FloatArray -> toList().createArrayLiteral(session, ConstantValueKind.Float)
is DoubleArray -> toList().createArrayOfCall(session, ConstantValueKind.Double) is DoubleArray -> toList().createArrayLiteral(session, ConstantValueKind.Double)
is BooleanArray -> toList().createArrayOfCall(session, ConstantValueKind.Boolean) is BooleanArray -> toList().createArrayLiteral(session, ConstantValueKind.Boolean)
null -> buildConstExpression( null -> buildConstExpression(
null, ConstantValueKind.Null, null, setType = true null, ConstantValueKind.Null, null, setType = true
) )
@@ -106,10 +105,10 @@ internal fun Any?.createConstantIfAny(session: FirSession, unsigned: Boolean = f
} }
} }
private fun <T> List<T>.createArrayOfCall(session: FirSession, kind: ConstantValueKind<T>): FirArrayOfCall { private fun <T> List<T>.createArrayLiteral(session: FirSession, kind: ConstantValueKind<T>): FirArrayLiteral {
return buildArrayOfCall { return buildArrayLiteral {
argumentList = buildArgumentList { argumentList = buildArgumentList {
for (element in this@createArrayOfCall) { for (element in this@createArrayLiteral) {
arguments += element.createConstantOrError(session) arguments += element.createConstantOrError(session)
} }
} }
@@ -94,7 +94,7 @@ internal class AnnotationsLoader(private val session: FirSession, private val ko
} }
override fun visitEnd() { override fun visitEnd() {
visitExpression(name, buildArrayOfCall { visitExpression(name, buildArrayLiteral {
guessArrayTypeIfNeeded(name, elements)?.let { guessArrayTypeIfNeeded(name, elements)?.let {
typeRef = it typeRef = it
} ?: elements.firstOrNull()?.typeRef?.coneType?.createOutArrayType()?.let { } ?: elements.firstOrNull()?.typeRef?.coneType?.createOutArrayType()?.let {
@@ -48,7 +48,7 @@ class FirAnnotationTypeQualifierResolver(
private fun FirExpression.toEnumNames(): List<String> = private fun FirExpression.toEnumNames(): List<String> =
when (this) { when (this) {
is FirArrayOfCall -> arguments.flatMap { it.toEnumNames() } is FirArrayLiteral -> arguments.flatMap { it.toEnumNames() }
is FirVarargArgumentsExpression -> arguments.flatMap { it.toEnumNames() } is FirVarargArgumentsExpression -> arguments.flatMap { it.toEnumNames() }
else -> { else -> {
val name = when (val reference = toReference()) { val name = when (val reference = toReference()) {
@@ -15,11 +15,7 @@ import org.jetbrains.kotlin.fir.declarations.FirRegularClass
import org.jetbrains.kotlin.fir.declarations.FirValueParameter import org.jetbrains.kotlin.fir.declarations.FirValueParameter
import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic
import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind
import org.jetbrains.kotlin.fir.expressions.FirAnnotation import org.jetbrains.kotlin.fir.expressions.*
import org.jetbrains.kotlin.fir.expressions.FirAnnotationArgumentMapping
import org.jetbrains.kotlin.fir.expressions.FirExpression
import org.jetbrains.kotlin.fir.expressions.FirPropertyAccessExpression
import org.jetbrains.kotlin.fir.expressions.buildUnaryArgumentList
import org.jetbrains.kotlin.fir.expressions.builder.* import org.jetbrains.kotlin.fir.expressions.builder.*
import org.jetbrains.kotlin.fir.java.declarations.buildJavaValueParameter import org.jetbrains.kotlin.fir.java.declarations.buildJavaValueParameter
import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
@@ -89,7 +85,7 @@ internal fun JavaAnnotationArgument.toFirExpression(
): FirExpression { ): FirExpression {
return when (this) { return when (this) {
is JavaLiteralAnnotationArgument -> value.createConstantOrError(session) is JavaLiteralAnnotationArgument -> value.createConstantOrError(session)
is JavaArrayAnnotationArgument -> buildArrayOfCall { is JavaArrayAnnotationArgument -> buildArrayLiteral {
val argumentTypeRef = expectedTypeRef?.let { val argumentTypeRef = expectedTypeRef?.let {
typeRef = if (it is FirJavaTypeRef) buildResolvedTypeRef { typeRef = if (it is FirJavaTypeRef) buildResolvedTypeRef {
type = it.toConeKotlinTypeProbablyFlexible(session, javaTypeParameterStack) type = it.toConeKotlinTypeProbablyFlexible(session, javaTypeParameterStack)
@@ -201,7 +201,7 @@ inline fun <T> List<FirAnnotation>.mapAnnotationsWithClassIdTo(
fun FirExpression.unwrapVarargValue(): List<FirExpression> { fun FirExpression.unwrapVarargValue(): List<FirExpression> {
return when (this) { return when (this) {
is FirVarargArgumentsExpression -> arguments is FirVarargArgumentsExpression -> arguments
is FirArrayOfCall -> arguments is FirArrayLiteral -> arguments
else -> listOf(this) else -> listOf(this)
} }
} }
@@ -224,7 +224,7 @@ fun FirAnnotation.findArgumentByName(name: Name): FirExpression? {
fun FirAnnotation.getBooleanArgument(name: Name): Boolean? = getPrimitiveArgumentValue(name) fun FirAnnotation.getBooleanArgument(name: Name): Boolean? = getPrimitiveArgumentValue(name)
fun FirAnnotation.getStringArgument(name: Name): String? = getPrimitiveArgumentValue(name) fun FirAnnotation.getStringArgument(name: Name): String? = getPrimitiveArgumentValue(name)
fun FirAnnotation.getStringArrayArgument(name: Name): List<String>? { fun FirAnnotation.getStringArrayArgument(name: Name): List<String>? {
val argument = findArgumentByName(name) as? FirArrayOfCall ?: return null val argument = findArgumentByName(name) as? FirArrayLiteral ?: return null
return argument.arguments.mapNotNull { (it as? FirConstExpression<*>)?.value as? String } return argument.arguments.mapNotNull { (it as? FirConstExpression<*>)?.value as? String }
} }
@@ -562,7 +562,7 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext, Ty
} ?: return null } ?: return null
val argument = when (val argument = annotationCall.argumentMapping.mapping.values.firstOrNull() ?: return null) { val argument = when (val argument = annotationCall.argumentMapping.mapping.values.firstOrNull() ?: return null) {
is FirVarargArgumentsExpression -> argument.arguments.firstOrNull() is FirVarargArgumentsExpression -> argument.arguments.firstOrNull()
is FirArrayOfCall -> argument.arguments.firstOrNull() is FirArrayLiteral -> argument.arguments.firstOrNull()
is FirNamedArgumentExpression -> argument.expression is FirNamedArgumentExpression -> argument.expression
else -> argument else -> argument
} ?: return null } ?: return null
@@ -988,7 +988,7 @@ class LightTreeRawFirExpressionBuilder(
if (it.isExpression()) firExpressionList += getAsFirExpression<FirExpression>(it, "Incorrect collection literal argument") if (it.isExpression()) firExpressionList += getAsFirExpression<FirExpression>(it, "Incorrect collection literal argument")
} }
return buildArrayOfCall { return buildArrayLiteral {
source = expression.toFirSourceElement() source = expression.toFirSourceElement()
argumentList = buildArgumentList { argumentList = buildArgumentList {
arguments += firExpressionList arguments += firExpressionList
@@ -2953,7 +2953,7 @@ open class PsiRawFirBuilder(
} }
override fun visitCollectionLiteralExpression(expression: KtCollectionLiteralExpression, data: FirElement?): FirElement { override fun visitCollectionLiteralExpression(expression: KtCollectionLiteralExpression, data: FirElement?): FirElement {
return buildArrayOfCall { return buildArrayLiteral {
source = expression.toFirSourceElement() source = expression.toFirSourceElement()
argumentList = buildArgumentList { argumentList = buildArgumentList {
for (innerExpression in expression.getInnerExpressions()) { for (innerExpression in expression.getInnerExpressions()) {
@@ -542,7 +542,7 @@ class FirCallResolver(
annotation.replaceArgumentList(buildArgumentList { annotation.replaceArgumentList(buildArgumentList {
source = annotation.argumentList.source source = annotation.argumentList.source
annotation.arguments.mapTo(arguments) { arg -> annotation.arguments.mapTo(arguments) { arg ->
val resolutionMode = if (arg.unwrapArgument() is FirArrayOfCall) { val resolutionMode = if (arg.unwrapArgument() is FirArrayLiteral) {
(argumentsToParameters[arg]?.returnTypeRef as? FirResolvedTypeRef)?.let { (argumentsToParameters[arg]?.returnTypeRef as? FirResolvedTypeRef)?.let {
// Enabling expectedTypeMismatchIsReportedInChecker clarifies error messages: // Enabling expectedTypeMismatchIsReportedInChecker clarifies error messages:
// It will be reported single ARGUMENT_TYPE_MISMATCH on the array literal in checkApplicabilityForArgumentType // It will be reported single ARGUMENT_TYPE_MISMATCH on the array literal in checkApplicabilityForArgumentType
@@ -774,20 +774,20 @@ class FirCallCompletionResultsWriterTransformer(
return integerLiteralOperatorCall.transformSingle(integerOperatorApproximator, expectedType) return integerLiteralOperatorCall.transformSingle(integerOperatorApproximator, expectedType)
} }
override fun transformArrayOfCall(arrayOfCall: FirArrayOfCall, data: ExpectedArgumentType?): FirStatement { override fun transformArrayLiteral(arrayLiteral: FirArrayLiteral, data: ExpectedArgumentType?): FirStatement {
if (arrayOfCall.typeRef !is FirImplicitTypeRef) return arrayOfCall if (arrayLiteral.typeRef !is FirImplicitTypeRef) return arrayLiteral
val expectedArrayType = data?.getExpectedType(arrayOfCall) val expectedArrayType = data?.getExpectedType(arrayLiteral)
val expectedArrayElementType = expectedArrayType?.arrayElementType() val expectedArrayElementType = expectedArrayType?.arrayElementType()
arrayOfCall.transformChildren(this, expectedArrayElementType?.toExpectedType()) arrayLiteral.transformChildren(this, expectedArrayElementType?.toExpectedType())
val arrayElementType = val arrayElementType =
session.typeContext.commonSuperTypeOrNull(arrayOfCall.arguments.map { it.typeRef.coneType })?.let { session.typeContext.commonSuperTypeOrNull(arrayLiteral.arguments.map { it.typeRef.coneType })?.let {
typeApproximator.approximateToSuperType(it, TypeApproximatorConfiguration.FinalApproximationAfterResolutionAndInference) typeApproximator.approximateToSuperType(it, TypeApproximatorConfiguration.FinalApproximationAfterResolutionAndInference)
?: it ?: it
} ?: expectedArrayElementType ?: session.builtinTypes.nullableAnyType.type } ?: expectedArrayElementType ?: session.builtinTypes.nullableAnyType.type
arrayOfCall.resultType = arrayOfCall.typeRef.resolvedTypeFromPrototype( arrayLiteral.resultType = arrayLiteral.typeRef.resolvedTypeFromPrototype(
arrayElementType.createArrayType(createPrimitiveArrayTypeIfPossible = expectedArrayType?.isPrimitiveArray == true) arrayElementType.createArrayType(createPrimitiveArrayTypeIfPossible = expectedArrayType?.isPrimitiveArray == true)
) )
return arrayOfCall return arrayLiteral
} }
override fun transformVarargArgumentsExpression( override fun transformVarargArgumentsExpression(
@@ -148,14 +148,14 @@ class FirSyntheticCallGenerator(
return elvisExpression.transformCalleeReference(UpdateReference, reference) return elvisExpression.transformCalleeReference(UpdateReference, reference)
} }
fun generateSyntheticIdCall(arrayOfCall: FirExpression, context: ResolutionContext): FirFunctionCall { fun generateSyntheticIdCall(arrayLiteral: FirExpression, context: ResolutionContext): FirFunctionCall {
val argumentList = buildArgumentList { val argumentList = buildArgumentList {
arguments += arrayOfCall arguments += arrayLiteral
} }
return buildFunctionCall { return buildFunctionCall {
this.argumentList = argumentList this.argumentList = argumentList
calleeReference = generateCalleeReferenceWithCandidate( calleeReference = generateCalleeReferenceWithCandidate(
arrayOfCall, arrayLiteral,
idFunction, idFunction,
argumentList, argumentList,
SyntheticCallableId.ID.callableName, SyntheticCallableId.ID.callableName,
@@ -165,22 +165,22 @@ class FirSyntheticCallGenerator(
} }
fun generateSyntheticArrayOfCall( fun generateSyntheticArrayOfCall(
arrayOfCall: FirArrayOfCall, arrayLiteral: FirArrayLiteral,
expectedTypeRef: FirTypeRef, expectedTypeRef: FirTypeRef,
context: ResolutionContext context: ResolutionContext
): FirFunctionCall { ): FirFunctionCall {
val argumentList = arrayOfCall.argumentList val argumentList = arrayLiteral.argumentList
return buildFunctionCall { return buildFunctionCall {
this.argumentList = argumentList this.argumentList = argumentList
calleeReference = generateCalleeReferenceWithCandidate( calleeReference = generateCalleeReferenceWithCandidate(
arrayOfCall, arrayLiteral,
calculateArrayOfSymbol(expectedTypeRef).fir, calculateArrayOfSymbol(expectedTypeRef).fir,
argumentList, argumentList,
ArrayFqNames.ARRAY_OF_FUNCTION, ArrayFqNames.ARRAY_OF_FUNCTION,
callKind = CallKind.Function, callKind = CallKind.Function,
context = context, context = context,
) )
source = arrayOfCall.source source = arrayLiteral.source
} }
} }
@@ -5,12 +5,9 @@
package org.jetbrains.kotlin.fir.resolve.transformers.body.resolve package org.jetbrains.kotlin.fir.resolve.transformers.body.resolve
import org.jetbrains.kotlin.fir.FirElement import org.jetbrains.kotlin.fir.*
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.FirTargetElement
import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.expressions.* import org.jetbrains.kotlin.fir.expressions.*
import org.jetbrains.kotlin.fir.render
import org.jetbrains.kotlin.fir.resolve.ResolutionMode import org.jetbrains.kotlin.fir.resolve.ResolutionMode
import org.jetbrains.kotlin.fir.resolve.ScopeSession import org.jetbrains.kotlin.fir.resolve.ScopeSession
import org.jetbrains.kotlin.fir.resolve.calls.ResolutionContext import org.jetbrains.kotlin.fir.resolve.calls.ResolutionContext
@@ -21,7 +18,6 @@ import org.jetbrains.kotlin.fir.resolve.transformers.ReturnTypeCalculatorForFull
import org.jetbrains.kotlin.fir.resolve.transformers.ScopeClassDeclaration import org.jetbrains.kotlin.fir.resolve.transformers.ScopeClassDeclaration
import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.fir.types.*
import org.jetbrains.kotlin.fir.visitors.FirTransformer import org.jetbrains.kotlin.fir.visitors.FirTransformer
import org.jetbrains.kotlin.fir.withFileAnalysisExceptionWrapping
abstract class FirAbstractBodyResolveTransformerDispatcher( abstract class FirAbstractBodyResolveTransformerDispatcher(
session: FirSession, session: FirSession,
@@ -281,8 +277,8 @@ abstract class FirAbstractBodyResolveTransformerDispatcher(
return expressionsTransformer.transformCheckedSafeCallSubject(checkedSafeCallSubject, data) return expressionsTransformer.transformCheckedSafeCallSubject(checkedSafeCallSubject, data)
} }
override fun transformArrayOfCall(arrayOfCall: FirArrayOfCall, data: ResolutionMode): FirStatement { override fun transformArrayLiteral(arrayLiteral: FirArrayLiteral, data: ResolutionMode): FirStatement {
return expressionsTransformer.transformArrayOfCall(arrayOfCall, data) return expressionsTransformer.transformArrayLiteral(arrayLiteral, data)
} }
override fun transformSmartCastExpression(smartCastExpression: FirSmartCastExpression, data: ResolutionMode): FirStatement { override fun transformSmartCastExpression(smartCastExpression: FirSmartCastExpression, data: ResolutionMode): FirStatement {
@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration
import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction
import org.jetbrains.kotlin.fir.expressions.* import org.jetbrains.kotlin.fir.expressions.*
import org.jetbrains.kotlin.fir.expressions.builder.buildArgumentList import org.jetbrains.kotlin.fir.expressions.builder.buildArgumentList
import org.jetbrains.kotlin.fir.expressions.builder.buildArrayOfCall import org.jetbrains.kotlin.fir.expressions.builder.buildArrayLiteral
import org.jetbrains.kotlin.fir.references.FirResolvedErrorReference import org.jetbrains.kotlin.fir.references.FirResolvedErrorReference
import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
import org.jetbrains.kotlin.fir.references.isError import org.jetbrains.kotlin.fir.references.isError
@@ -26,15 +26,15 @@ import org.jetbrains.kotlin.fir.types.isArrayType
import org.jetbrains.kotlin.fir.visitors.FirDefaultTransformer import org.jetbrains.kotlin.fir.visitors.FirDefaultTransformer
/** /**
* A transformer that converts resolved arrayOf() call to [FirArrayOfCall]. * A transformer that converts resolved arrayOf() call to [FirArrayLiteral].
* *
* Note that arrayOf() calls only in [FirAnnotation] or the default value of annotation constructor are transformed. * Note that arrayOf() calls only in [FirAnnotation] or the default value of annotation constructor are transformed.
*/ */
class FirArrayOfCallTransformer : FirDefaultTransformer<FirSession>() { class FirArrayOfCallTransformer : FirDefaultTransformer<FirSession>() {
private fun toArrayOfCall(functionCall: FirFunctionCall, session: FirSession): FirExpression? { private fun toArrayLiteral(functionCall: FirFunctionCall, session: FirSession): FirExpression? {
if (!functionCall.isArrayOfCall(session)) return null if (!functionCall.isArrayOfCall(session)) return null
if (functionCall.calleeReference !is FirResolvedNamedReference) return null if (functionCall.calleeReference !is FirResolvedNamedReference) return null
val arrayOfCall = buildArrayOfCall { val arrayLiteral = buildArrayLiteral {
source = functionCall.source source = functionCall.source
annotations += functionCall.annotations annotations += functionCall.annotations
// Note that the signature is: arrayOf(vararg element). Hence, unwrapping the original argument list here. // Note that the signature is: arrayOf(vararg element). Hence, unwrapping the original argument list here.
@@ -54,16 +54,16 @@ class FirArrayOfCallTransformer : FirDefaultTransformer<FirSession>() {
buildErrorExpression( buildErrorExpression(
functionCall.source?.fakeElement(KtFakeSourceElementKind.ErrorTypeRef), functionCall.source?.fakeElement(KtFakeSourceElementKind.ErrorTypeRef),
calleeReference.diagnostic, calleeReference.diagnostic,
arrayOfCall arrayLiteral
) )
} else { } else {
arrayOfCall arrayLiteral
} }
} }
override fun transformFunctionCall(functionCall: FirFunctionCall, data: FirSession): FirStatement { override fun transformFunctionCall(functionCall: FirFunctionCall, data: FirSession): FirStatement {
functionCall.transformChildren(this, data) functionCall.transformChildren(this, data)
return toArrayOfCall(functionCall, data) ?: functionCall return toArrayLiteral(functionCall, data) ?: functionCall
} }
override fun <E : FirElement> transformElement(element: E, data: FirSession): E { override fun <E : FirElement> transformElement(element: E, data: FirSession): E {
@@ -1631,28 +1631,28 @@ open class FirExpressionsResolveTransformer(transformer: FirAbstractBodyResolveT
) )
} }
override fun transformArrayLiteral(arrayOfCall: FirArrayOfCall, data: ResolutionMode): FirStatement = override fun transformArrayLiteral(arrayLiteral: FirArrayLiteral, data: ResolutionMode): FirStatement =
whileAnalysing(session, arrayOfCall) { whileAnalysing(session, arrayLiteral) {
when (data) { when (data) {
is ResolutionMode.ContextDependent.Default -> { is ResolutionMode.ContextDependent.Default -> {
// Argument in non-annotation call (unsupported) or if type of array parameter is unresolved. // Argument in non-annotation call (unsupported) or if type of array parameter is unresolved.
arrayOfCall.transformChildren(transformer, data) arrayLiteral.transformChildren(transformer, data)
arrayOfCall arrayLiteral
} }
is ResolutionMode.WithExpectedType -> { is ResolutionMode.WithExpectedType -> {
// Default value of array parameter (Array<T> or primitive array such as IntArray, FloatArray, ...) // Default value of array parameter (Array<T> or primitive array such as IntArray, FloatArray, ...)
// or argument for array parameter in annotation call. // or argument for array parameter in annotation call.
arrayOfCall.transformChildren(transformer, ResolutionMode.ContextDependent) arrayLiteral.transformChildren(transformer, ResolutionMode.ContextDependent)
val call = components.syntheticCallGenerator.generateSyntheticArrayOfCall(arrayOfCall, data.expectedTypeRef, resolutionContext) val call = components.syntheticCallGenerator.generateSyntheticArrayOfCall(arrayLiteral, data.expectedTypeRef, resolutionContext)
callCompleter.completeCall(call, data) callCompleter.completeCall(call, data)
arrayOfCallTransformer.transformFunctionCall(call, session) arrayOfCallTransformer.transformFunctionCall(call, session)
} }
else -> { else -> {
// Other unsupported usage. // Other unsupported usage.
val syntheticIdCall = components.syntheticCallGenerator.generateSyntheticIdCall(arrayOfCall, resolutionContext) val syntheticIdCall = components.syntheticCallGenerator.generateSyntheticIdCall(arrayLiteral, resolutionContext)
arrayOfCall.transformChildren(transformer, ResolutionMode.ContextDependent) arrayLiteral.transformChildren(transformer, ResolutionMode.ContextDependent)
callCompleter.completeCall(syntheticIdCall, data) callCompleter.completeCall(syntheticIdCall, data)
arrayOfCall arrayLiteral
} }
} }
} }
@@ -19,16 +19,12 @@ import org.jetbrains.kotlin.fir.references.builder.buildSimpleNamedReference
import org.jetbrains.kotlin.fir.references.toResolvedBaseSymbol import org.jetbrains.kotlin.fir.references.toResolvedBaseSymbol
import org.jetbrains.kotlin.fir.resolve.ResolutionMode import org.jetbrains.kotlin.fir.resolve.ResolutionMode
import org.jetbrains.kotlin.fir.resolve.ScopeSession import org.jetbrains.kotlin.fir.resolve.ScopeSession
import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeAmbiguouslyResolvedAnnotationArgument
import org.jetbrains.kotlin.fir.resolve.transformers.ReturnTypeCalculator import org.jetbrains.kotlin.fir.resolve.transformers.ReturnTypeCalculator
import org.jetbrains.kotlin.fir.resolve.transformers.ReturnTypeCalculatorForFullBodyResolve import org.jetbrains.kotlin.fir.resolve.transformers.ReturnTypeCalculatorForFullBodyResolve
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.BodyResolveContext import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.*
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirAbstractBodyResolveTransformerDispatcher
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirDeclarationsResolveTransformer
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirExpressionsResolveTransformer
import org.jetbrains.kotlin.fir.visitors.transformSingle
import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeAmbiguouslyResolvedAnnotationArgument
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirResolveContextCollector
import org.jetbrains.kotlin.fir.symbols.impl.FirEnumEntrySymbol import org.jetbrains.kotlin.fir.symbols.impl.FirEnumEntrySymbol
import org.jetbrains.kotlin.fir.visitors.transformSingle
import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.StandardClassIds import org.jetbrains.kotlin.name.StandardClassIds
@@ -275,9 +271,9 @@ abstract class AbstractFirExpressionsResolveTransformerForAnnotations(transforme
return augmentedArraySetCall return augmentedArraySetCall
} }
override fun transformArrayOfCall(arrayOfCall: FirArrayOfCall, data: ResolutionMode): FirStatement { override fun transformArrayLiteral(arrayLiteral: FirArrayLiteral, data: ResolutionMode): FirStatement {
arrayOfCall.transformChildren(transformer, data) arrayLiteral.transformChildren(transformer, data)
return arrayOfCall return arrayLiteral
} }
override fun shouldComputeTypeOfGetClassCallWithNotQualifierInLhs(getClassCall: FirGetClassCall): Boolean { override fun shouldComputeTypeOfGetClassCallWithNotQualifierInLhs(getClassCall: FirGetClassCall): Boolean {
@@ -15,17 +15,17 @@ import org.jetbrains.kotlin.fir.visitors.*
* DO NOT MODIFY IT MANUALLY * DO NOT MODIFY IT MANUALLY
*/ */
abstract class FirArrayOfCall : FirExpression(), FirCall { abstract class FirArrayLiteral : FirExpression(), FirCall {
abstract override val source: KtSourceElement? abstract override val source: KtSourceElement?
abstract override val typeRef: FirTypeRef abstract override val typeRef: FirTypeRef
abstract override val annotations: List<FirAnnotation> abstract override val annotations: List<FirAnnotation>
abstract override val argumentList: FirArgumentList abstract override val argumentList: FirArgumentList
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R = visitor.visitArrayOfCall(this, data) override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R = visitor.visitArrayLiteral(this, data)
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
override fun <E : FirElement, D> transform(transformer: FirTransformer<D>, data: D): E = override fun <E : FirElement, D> transform(transformer: FirTransformer<D>, data: D): E =
transformer.transformArrayOfCall(this, data) as E transformer.transformArrayLiteral(this, data) as E
abstract override fun replaceTypeRef(newTypeRef: FirTypeRef) abstract override fun replaceTypeRef(newTypeRef: FirTypeRef)
@@ -33,5 +33,5 @@ abstract class FirArrayOfCall : FirExpression(), FirCall {
abstract override fun replaceArgumentList(newArgumentList: FirArgumentList) abstract override fun replaceArgumentList(newArgumentList: FirArgumentList)
abstract override fun <D> transformAnnotations(transformer: FirTransformer<D>, data: D): FirArrayOfCall abstract override fun <D> transformAnnotations(transformer: FirTransformer<D>, data: D): FirArrayLiteral
} }
@@ -14,10 +14,10 @@ import org.jetbrains.kotlin.fir.builder.FirBuilderDsl
import org.jetbrains.kotlin.fir.builder.toMutableOrEmpty import org.jetbrains.kotlin.fir.builder.toMutableOrEmpty
import org.jetbrains.kotlin.fir.expressions.FirAnnotation import org.jetbrains.kotlin.fir.expressions.FirAnnotation
import org.jetbrains.kotlin.fir.expressions.FirArgumentList import org.jetbrains.kotlin.fir.expressions.FirArgumentList
import org.jetbrains.kotlin.fir.expressions.FirArrayOfCall import org.jetbrains.kotlin.fir.expressions.FirArrayLiteral
import org.jetbrains.kotlin.fir.expressions.builder.FirCallBuilder import org.jetbrains.kotlin.fir.expressions.builder.FirCallBuilder
import org.jetbrains.kotlin.fir.expressions.builder.FirExpressionBuilder import org.jetbrains.kotlin.fir.expressions.builder.FirExpressionBuilder
import org.jetbrains.kotlin.fir.expressions.impl.FirArrayOfCallImpl import org.jetbrains.kotlin.fir.expressions.impl.FirArrayLiteralImpl
import org.jetbrains.kotlin.fir.types.FirTypeRef import org.jetbrains.kotlin.fir.types.FirTypeRef
import org.jetbrains.kotlin.fir.types.impl.FirImplicitTypeRefImplWithoutSource import org.jetbrains.kotlin.fir.types.impl.FirImplicitTypeRefImplWithoutSource
import org.jetbrains.kotlin.fir.visitors.* import org.jetbrains.kotlin.fir.visitors.*
@@ -28,14 +28,14 @@ import org.jetbrains.kotlin.fir.visitors.*
*/ */
@FirBuilderDsl @FirBuilderDsl
class FirArrayOfCallBuilder : FirCallBuilder, FirAnnotationContainerBuilder, FirExpressionBuilder { class FirArrayLiteralBuilder : FirCallBuilder, FirAnnotationContainerBuilder, FirExpressionBuilder {
override var source: KtSourceElement? = null override var source: KtSourceElement? = null
override var typeRef: FirTypeRef = FirImplicitTypeRefImplWithoutSource override var typeRef: FirTypeRef = FirImplicitTypeRefImplWithoutSource
override val annotations: MutableList<FirAnnotation> = mutableListOf() override val annotations: MutableList<FirAnnotation> = mutableListOf()
override lateinit var argumentList: FirArgumentList override lateinit var argumentList: FirArgumentList
override fun build(): FirArrayOfCall { override fun build(): FirArrayLiteral {
return FirArrayOfCallImpl( return FirArrayLiteralImpl(
source, source,
typeRef, typeRef,
annotations.toMutableOrEmpty(), annotations.toMutableOrEmpty(),
@@ -46,9 +46,9 @@ class FirArrayOfCallBuilder : FirCallBuilder, FirAnnotationContainerBuilder, Fir
} }
@OptIn(ExperimentalContracts::class) @OptIn(ExperimentalContracts::class)
inline fun buildArrayOfCall(init: FirArrayOfCallBuilder.() -> Unit): FirArrayOfCall { inline fun buildArrayLiteral(init: FirArrayLiteralBuilder.() -> Unit): FirArrayLiteral {
contract { contract {
callsInPlace(init, kotlin.contracts.InvocationKind.EXACTLY_ONCE) callsInPlace(init, kotlin.contracts.InvocationKind.EXACTLY_ONCE)
} }
return FirArrayOfCallBuilder().apply(init).build() return FirArrayLiteralBuilder().apply(init).build()
} }
@@ -10,7 +10,7 @@ package org.jetbrains.kotlin.fir.expressions.impl
import org.jetbrains.kotlin.KtSourceElement import org.jetbrains.kotlin.KtSourceElement
import org.jetbrains.kotlin.fir.expressions.FirAnnotation import org.jetbrains.kotlin.fir.expressions.FirAnnotation
import org.jetbrains.kotlin.fir.expressions.FirArgumentList import org.jetbrains.kotlin.fir.expressions.FirArgumentList
import org.jetbrains.kotlin.fir.expressions.FirArrayOfCall import org.jetbrains.kotlin.fir.expressions.FirArrayLiteral
import org.jetbrains.kotlin.fir.types.FirTypeRef import org.jetbrains.kotlin.fir.types.FirTypeRef
import org.jetbrains.kotlin.fir.visitors.* import org.jetbrains.kotlin.fir.visitors.*
import org.jetbrains.kotlin.fir.MutableOrEmptyList import org.jetbrains.kotlin.fir.MutableOrEmptyList
@@ -21,26 +21,26 @@ import org.jetbrains.kotlin.fir.builder.toMutableOrEmpty
* DO NOT MODIFY IT MANUALLY * DO NOT MODIFY IT MANUALLY
*/ */
internal class FirArrayOfCallImpl( internal class FirArrayLiteralImpl(
override val source: KtSourceElement?, override val source: KtSourceElement?,
override var typeRef: FirTypeRef, override var typeRef: FirTypeRef,
override var annotations: MutableOrEmptyList<FirAnnotation>, override var annotations: MutableOrEmptyList<FirAnnotation>,
override var argumentList: FirArgumentList, override var argumentList: FirArgumentList,
) : FirArrayOfCall() { ) : FirArrayLiteral() {
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) { override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
typeRef.accept(visitor, data) typeRef.accept(visitor, data)
annotations.forEach { it.accept(visitor, data) } annotations.forEach { it.accept(visitor, data) }
argumentList.accept(visitor, data) argumentList.accept(visitor, data)
} }
override fun <D> transformChildren(transformer: FirTransformer<D>, data: D): FirArrayOfCallImpl { override fun <D> transformChildren(transformer: FirTransformer<D>, data: D): FirArrayLiteralImpl {
typeRef = typeRef.transform(transformer, data) typeRef = typeRef.transform(transformer, data)
transformAnnotations(transformer, data) transformAnnotations(transformer, data)
argumentList = argumentList.transform(transformer, data) argumentList = argumentList.transform(transformer, data)
return this return this
} }
override fun <D> transformAnnotations(transformer: FirTransformer<D>, data: D): FirArrayOfCallImpl { override fun <D> transformAnnotations(transformer: FirTransformer<D>, data: D): FirArrayLiteralImpl {
annotations.transformInplace(transformer, data) annotations.transformInplace(transformer, data)
return this return this
} }
@@ -94,7 +94,7 @@ import org.jetbrains.kotlin.fir.expressions.FirWhenBranch
import org.jetbrains.kotlin.fir.expressions.FirContextReceiverArgumentListOwner import org.jetbrains.kotlin.fir.expressions.FirContextReceiverArgumentListOwner
import org.jetbrains.kotlin.fir.expressions.FirCheckNotNullCall import org.jetbrains.kotlin.fir.expressions.FirCheckNotNullCall
import org.jetbrains.kotlin.fir.expressions.FirElvisExpression import org.jetbrains.kotlin.fir.expressions.FirElvisExpression
import org.jetbrains.kotlin.fir.expressions.FirArrayOfCall import org.jetbrains.kotlin.fir.expressions.FirArrayLiteral
import org.jetbrains.kotlin.fir.expressions.FirAugmentedArraySetCall import org.jetbrains.kotlin.fir.expressions.FirAugmentedArraySetCall
import org.jetbrains.kotlin.fir.expressions.FirClassReferenceExpression import org.jetbrains.kotlin.fir.expressions.FirClassReferenceExpression
import org.jetbrains.kotlin.fir.expressions.FirErrorExpression import org.jetbrains.kotlin.fir.expressions.FirErrorExpression
@@ -94,7 +94,7 @@ import org.jetbrains.kotlin.fir.expressions.FirWhenBranch
import org.jetbrains.kotlin.fir.expressions.FirContextReceiverArgumentListOwner import org.jetbrains.kotlin.fir.expressions.FirContextReceiverArgumentListOwner
import org.jetbrains.kotlin.fir.expressions.FirCheckNotNullCall import org.jetbrains.kotlin.fir.expressions.FirCheckNotNullCall
import org.jetbrains.kotlin.fir.expressions.FirElvisExpression import org.jetbrains.kotlin.fir.expressions.FirElvisExpression
import org.jetbrains.kotlin.fir.expressions.FirArrayOfCall import org.jetbrains.kotlin.fir.expressions.FirArrayLiteral
import org.jetbrains.kotlin.fir.expressions.FirAugmentedArraySetCall import org.jetbrains.kotlin.fir.expressions.FirAugmentedArraySetCall
import org.jetbrains.kotlin.fir.expressions.FirClassReferenceExpression import org.jetbrains.kotlin.fir.expressions.FirClassReferenceExpression
import org.jetbrains.kotlin.fir.expressions.FirErrorExpression import org.jetbrains.kotlin.fir.expressions.FirErrorExpression
@@ -94,7 +94,7 @@ import org.jetbrains.kotlin.fir.expressions.FirWhenBranch
import org.jetbrains.kotlin.fir.expressions.FirContextReceiverArgumentListOwner import org.jetbrains.kotlin.fir.expressions.FirContextReceiverArgumentListOwner
import org.jetbrains.kotlin.fir.expressions.FirCheckNotNullCall import org.jetbrains.kotlin.fir.expressions.FirCheckNotNullCall
import org.jetbrains.kotlin.fir.expressions.FirElvisExpression import org.jetbrains.kotlin.fir.expressions.FirElvisExpression
import org.jetbrains.kotlin.fir.expressions.FirArrayOfCall import org.jetbrains.kotlin.fir.expressions.FirArrayLiteral
import org.jetbrains.kotlin.fir.expressions.FirAugmentedArraySetCall import org.jetbrains.kotlin.fir.expressions.FirAugmentedArraySetCall
import org.jetbrains.kotlin.fir.expressions.FirClassReferenceExpression import org.jetbrains.kotlin.fir.expressions.FirClassReferenceExpression
import org.jetbrains.kotlin.fir.expressions.FirErrorExpression import org.jetbrains.kotlin.fir.expressions.FirErrorExpression
@@ -522,8 +522,8 @@ abstract class FirTransformer<in D> : FirVisitor<FirElement, D>() {
return transformElement(elvisExpression, data) return transformElement(elvisExpression, data)
} }
open fun transformArrayOfCall(arrayOfCall: FirArrayOfCall, data: D): FirStatement { open fun transformArrayLiteral(arrayLiteral: FirArrayLiteral, data: D): FirStatement {
return transformElement(arrayOfCall, data) return transformElement(arrayLiteral, data)
} }
open fun transformAugmentedArraySetCall(augmentedArraySetCall: FirAugmentedArraySetCall, data: D): FirStatement { open fun transformAugmentedArraySetCall(augmentedArraySetCall: FirAugmentedArraySetCall, data: D): FirStatement {
@@ -1142,8 +1142,8 @@ abstract class FirTransformer<in D> : FirVisitor<FirElement, D>() {
return transformElvisExpression(elvisExpression, data) return transformElvisExpression(elvisExpression, data)
} }
final override fun visitArrayOfCall(arrayOfCall: FirArrayOfCall, data: D): FirStatement { final override fun visitArrayLiteral(arrayLiteral: FirArrayLiteral, data: D): FirStatement {
return transformArrayOfCall(arrayOfCall, data) return transformArrayLiteral(arrayLiteral, data)
} }
final override fun visitAugmentedArraySetCall(augmentedArraySetCall: FirAugmentedArraySetCall, data: D): FirStatement { final override fun visitAugmentedArraySetCall(augmentedArraySetCall: FirAugmentedArraySetCall, data: D): FirStatement {
@@ -94,7 +94,7 @@ import org.jetbrains.kotlin.fir.expressions.FirWhenBranch
import org.jetbrains.kotlin.fir.expressions.FirContextReceiverArgumentListOwner import org.jetbrains.kotlin.fir.expressions.FirContextReceiverArgumentListOwner
import org.jetbrains.kotlin.fir.expressions.FirCheckNotNullCall import org.jetbrains.kotlin.fir.expressions.FirCheckNotNullCall
import org.jetbrains.kotlin.fir.expressions.FirElvisExpression import org.jetbrains.kotlin.fir.expressions.FirElvisExpression
import org.jetbrains.kotlin.fir.expressions.FirArrayOfCall import org.jetbrains.kotlin.fir.expressions.FirArrayLiteral
import org.jetbrains.kotlin.fir.expressions.FirAugmentedArraySetCall import org.jetbrains.kotlin.fir.expressions.FirAugmentedArraySetCall
import org.jetbrains.kotlin.fir.expressions.FirClassReferenceExpression import org.jetbrains.kotlin.fir.expressions.FirClassReferenceExpression
import org.jetbrains.kotlin.fir.expressions.FirErrorExpression import org.jetbrains.kotlin.fir.expressions.FirErrorExpression
@@ -345,7 +345,7 @@ abstract class FirVisitor<out R, in D> {
open fun visitElvisExpression(elvisExpression: FirElvisExpression, data: D): R = visitElement(elvisExpression, data) open fun visitElvisExpression(elvisExpression: FirElvisExpression, data: D): R = visitElement(elvisExpression, data)
open fun visitArrayOfCall(arrayOfCall: FirArrayOfCall, data: D): R = visitElement(arrayOfCall, data) open fun visitArrayLiteral(arrayLiteral: FirArrayLiteral, data: D): R = visitElement(arrayLiteral, data)
open fun visitAugmentedArraySetCall(augmentedArraySetCall: FirAugmentedArraySetCall, data: D): R = visitElement(augmentedArraySetCall, data) open fun visitAugmentedArraySetCall(augmentedArraySetCall: FirAugmentedArraySetCall, data: D): R = visitElement(augmentedArraySetCall, data)
@@ -94,7 +94,7 @@ import org.jetbrains.kotlin.fir.expressions.FirWhenBranch
import org.jetbrains.kotlin.fir.expressions.FirContextReceiverArgumentListOwner import org.jetbrains.kotlin.fir.expressions.FirContextReceiverArgumentListOwner
import org.jetbrains.kotlin.fir.expressions.FirCheckNotNullCall import org.jetbrains.kotlin.fir.expressions.FirCheckNotNullCall
import org.jetbrains.kotlin.fir.expressions.FirElvisExpression import org.jetbrains.kotlin.fir.expressions.FirElvisExpression
import org.jetbrains.kotlin.fir.expressions.FirArrayOfCall import org.jetbrains.kotlin.fir.expressions.FirArrayLiteral
import org.jetbrains.kotlin.fir.expressions.FirAugmentedArraySetCall import org.jetbrains.kotlin.fir.expressions.FirAugmentedArraySetCall
import org.jetbrains.kotlin.fir.expressions.FirClassReferenceExpression import org.jetbrains.kotlin.fir.expressions.FirClassReferenceExpression
import org.jetbrains.kotlin.fir.expressions.FirErrorExpression import org.jetbrains.kotlin.fir.expressions.FirErrorExpression
@@ -521,8 +521,8 @@ abstract class FirVisitorVoid : FirVisitor<Unit, Nothing?>() {
visitElement(elvisExpression) visitElement(elvisExpression)
} }
open fun visitArrayOfCall(arrayOfCall: FirArrayOfCall) { open fun visitArrayLiteral(arrayLiteral: FirArrayLiteral) {
visitElement(arrayOfCall) visitElement(arrayLiteral)
} }
open fun visitAugmentedArraySetCall(augmentedArraySetCall: FirAugmentedArraySetCall) { open fun visitAugmentedArraySetCall(augmentedArraySetCall: FirAugmentedArraySetCall) {
@@ -1141,8 +1141,8 @@ abstract class FirVisitorVoid : FirVisitor<Unit, Nothing?>() {
visitElvisExpression(elvisExpression) visitElvisExpression(elvisExpression)
} }
final override fun visitArrayOfCall(arrayOfCall: FirArrayOfCall, data: Nothing?) { final override fun visitArrayLiteral(arrayLiteral: FirArrayLiteral, data: Nothing?) {
visitArrayOfCall(arrayOfCall) visitArrayLiteral(arrayLiteral)
} }
final override fun visitAugmentedArraySetCall(augmentedArraySetCall: FirAugmentedArraySetCall, data: Nothing?) { final override fun visitAugmentedArraySetCall(augmentedArraySetCall: FirAugmentedArraySetCall, data: Nothing?) {
@@ -130,7 +130,7 @@ fun FirExpression.unwrapAndFlattenArgument(): List<FirExpression> = buildList {
private fun FirExpression.unwrapAndFlattenArgumentTo(list: MutableList<FirExpression>) { private fun FirExpression.unwrapAndFlattenArgumentTo(list: MutableList<FirExpression>) {
when (val unwrapped = unwrapArgument()) { when (val unwrapped = unwrapArgument()) {
is FirArrayOfCall, is FirFunctionCall -> (unwrapped as FirCall).arguments.forEach { it.unwrapAndFlattenArgumentTo(list) } is FirArrayLiteral, is FirFunctionCall -> (unwrapped as FirCall).arguments.forEach { it.unwrapAndFlattenArgumentTo(list) }
is FirVarargArgumentsExpression -> unwrapped.arguments.forEach { it.unwrapAndFlattenArgumentTo(list) } is FirVarargArgumentsExpression -> unwrapped.arguments.forEach { it.unwrapAndFlattenArgumentTo(list) }
else -> list.add(unwrapped) else -> list.add(unwrapped)
} }
@@ -5,8 +5,8 @@
package org.jetbrains.kotlin.fir.renderer package org.jetbrains.kotlin.fir.renderer
import org.jetbrains.kotlin.builtins.functions.FunctionTypeKindExtractor
import org.jetbrains.kotlin.builtins.functions.AllowedToUsedOnlyInK1 import org.jetbrains.kotlin.builtins.functions.AllowedToUsedOnlyInK1
import org.jetbrains.kotlin.builtins.functions.FunctionTypeKindExtractor
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
import org.jetbrains.kotlin.fir.* import org.jetbrains.kotlin.fir.*
import org.jetbrains.kotlin.fir.contracts.FirContractDescription import org.jetbrains.kotlin.fir.contracts.FirContractDescription
@@ -1110,10 +1110,10 @@ class FirRenderer(
print(")") print(")")
} }
override fun visitArrayOfCall(arrayOfCall: FirArrayOfCall) { override fun visitArrayLiteral(arrayLiteral: FirArrayLiteral) {
annotationRenderer?.render(arrayOfCall) annotationRenderer?.render(arrayLiteral)
print("<implicitArrayOf>") print("<implicitArrayOf>")
visitCall(arrayOfCall) visitCall(arrayLiteral)
} }
override fun visitThrowExpression(throwExpression: FirThrowExpression) { override fun visitThrowExpression(throwExpression: FirThrowExpression) {
@@ -151,7 +151,7 @@ object BuilderConfigurator : AbstractBuilderConfigurator<FirTreeBuilder>(FirTree
useTypes(emptyArgumentListType, emptyAnnotationArgumentMappingType, firImplicitTypeWithoutSourceType) useTypes(emptyArgumentListType, emptyAnnotationArgumentMappingType, firImplicitTypeWithoutSourceType)
} }
builder(arrayOfCall) { builder(arrayLiteral) {
parents += callBuilder parents += callBuilder
} }
@@ -418,7 +418,7 @@ object BuilderConfigurator : AbstractBuilderConfigurator<FirTreeBuilder>(FirTree
varargArgumentsExpression, varargArgumentsExpression,
checkedSafeCallSubject, checkedSafeCallSubject,
safeCallExpression, safeCallExpression,
arrayOfCall, arrayLiteral,
classReferenceExpression, classReferenceExpression,
getClassCall getClassCall
) )
@@ -118,7 +118,7 @@ object FirTreeBuilder : AbstractFirTreeBuilder() {
val checkNotNullCall by element(Expression, expression, call, resolvable) val checkNotNullCall by element(Expression, expression, call, resolvable)
val elvisExpression by element(Expression, expression, resolvable) val elvisExpression by element(Expression, expression, resolvable)
val arrayOfCall by element(Expression, expression, call) val arrayLiteral by element(Expression, expression, call)
val augmentedArraySetCall by element(Expression, statement) val augmentedArraySetCall by element(Expression, statement)
val classReferenceExpression by element(Expression, expression) val classReferenceExpression by element(Expression, expression)
val errorExpression by element(Expression, expression, diagnosticHolder) val errorExpression by element(Expression, expression, diagnosticHolder)
@@ -112,7 +112,7 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
} }
} }
impl(arrayOfCall) impl(arrayLiteral)
impl(callableReferenceAccess) impl(callableReferenceAccess)
@@ -666,7 +666,7 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
"FirVarargArgumentsExpressionImpl", "FirVarargArgumentsExpressionImpl",
"FirSafeCallExpressionImpl", "FirSafeCallExpressionImpl",
"FirCheckedSafeCallSubjectImpl", "FirCheckedSafeCallSubjectImpl",
"FirArrayOfCallImpl", "FirArrayLiteralImpl",
"FirIntegerLiteralOperatorCallImpl", "FirIntegerLiteralOperatorCallImpl",
"FirContextReceiverImpl", "FirContextReceiverImpl",
"FirReceiverParameterImpl", "FirReceiverParameterImpl",
@@ -265,7 +265,7 @@ class FirVisualizer(private val firFile: FirFile) : BaseRenderer() {
override fun visitCallExpression(expression: KtCallExpression) { override fun visitCallExpression(expression: KtCallExpression) {
expression.firstOfTypeWithLocalReplace<FirFunctionCall> { this.calleeReference.name.asString() } expression.firstOfTypeWithLocalReplace<FirFunctionCall> { this.calleeReference.name.asString() }
?: expression.firstOfTypeWithRender<FirArrayOfCall>() ?: expression.firstOfTypeWithRender<FirArrayLiteral>()
expression.children.filter { it.node.elementType != KtNodeTypes.REFERENCE_EXPRESSION }.forEach { psi -> expression.children.filter { it.node.elementType != KtNodeTypes.REFERENCE_EXPRESSION }.forEach { psi ->
when (psi) { when (psi) {
is KtLambdaArgument -> { is KtLambdaArgument -> {
@@ -844,9 +844,9 @@ class FirVisualizer(private val firFile: FirFile) : BaseRenderer() {
getClassCall.argument.accept(this, data) getClassCall.argument.accept(this, data)
} }
override fun visitArrayOfCall(arrayOfCall: FirArrayOfCall, data: StringBuilder) { override fun visitArrayLiteral(arrayLiteral: FirArrayLiteral, data: StringBuilder) {
val name = arrayOfCall.typeRef.coneType.classId!!.shortClassName.asString() val name = arrayLiteral.typeRef.coneType.classId!!.shortClassName.asString()
val typeArguments = arrayOfCall.typeRef.coneType.typeArguments val typeArguments = arrayLiteral.typeRef.coneType.typeArguments
val typeParameters = if (typeArguments.isEmpty()) "" else " <T>" val typeParameters = if (typeArguments.isEmpty()) "" else " <T>"
data.append("fun$typeParameters ${name.replaceFirstChar(Char::lowercaseChar)}Of") data.append("fun$typeParameters ${name.replaceFirstChar(Char::lowercaseChar)}Of")
typeArguments.firstOrNull()?.let { typeArguments.firstOrNull()?.let {
@@ -185,12 +185,12 @@ object FirSerializationPluginClassChecker : FirClassChecker() {
else -> { else -> {
val argumentsIfArray1 = when (this) { val argumentsIfArray1 = when (this) {
is FirVarargArgumentsExpression -> arguments is FirVarargArgumentsExpression -> arguments
is FirArrayOfCall -> arguments is FirArrayLiteral -> arguments
else -> return false else -> return false
} }
val argumentsIfArray2 = when (other) { val argumentsIfArray2 = when (other) {
is FirVarargArgumentsExpression -> other.arguments is FirVarargArgumentsExpression -> other.arguments
is FirArrayOfCall -> other.arguments is FirArrayLiteral -> other.arguments
else -> return false else -> return false
} }
argumentsIfArray1.size == argumentsIfArray2.size && argumentsIfArray1.zip(argumentsIfArray2) argumentsIfArray1.size == argumentsIfArray2.size && argumentsIfArray1.zip(argumentsIfArray2)
@@ -67,7 +67,7 @@ class ContextualSerializersProvider(session: FirSession) : FirExtensionSessionCo
annotationClassId, session annotationClassId, session
) ?: return emptyList() ) ?: return emptyList()
val arguments = when (val argument = annotation.argumentMapping.mapping.values.firstOrNull()) { val arguments = when (val argument = annotation.argumentMapping.mapping.values.firstOrNull()) {
is FirArrayOfCall -> argument.arguments is FirArrayLiteral -> argument.arguments
is FirVarargArgumentsExpression -> argument.arguments is FirVarargArgumentsExpression -> argument.arguments
else -> return emptyList() else -> return emptyList()
} }