Introduce helper FirExpression.unwrapArgument() in fir:tree
This commit is contained in:
+2
-2
@@ -10,13 +10,13 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
|
|||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirWrappedArgumentExpression
|
import org.jetbrains.kotlin.fir.expressions.unwrapArgument
|
||||||
|
|
||||||
object FirAnnotationUsedAsAnnotationArgumentChecker : FirAnnotationCallChecker() {
|
object FirAnnotationUsedAsAnnotationArgumentChecker : FirAnnotationCallChecker() {
|
||||||
override fun check(expression: FirAnnotationCall, context: CheckerContext, reporter: DiagnosticReporter) {
|
override fun check(expression: FirAnnotationCall, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||||
val args = expression.argumentList.arguments
|
val args = expression.argumentList.arguments
|
||||||
for (arg in args) {
|
for (arg in args) {
|
||||||
for (ann in ((arg as? FirWrappedArgumentExpression)?.expression ?: arg).annotations) {
|
for (ann in arg.unwrapArgument().annotations) {
|
||||||
reporter.reportOn(ann.source, FirErrors.ANNOTATION_USED_AS_ANNOTATION_ARGUMENT, context)
|
reporter.reportOn(ann.source, FirErrors.ANNOTATION_USED_AS_ANNOTATION_ARGUMENT, context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -459,11 +459,7 @@ class Fir2IrVisitor(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
val unwrappedExpression = if (expression is FirWrappedArgumentExpression) {
|
val unwrappedExpression = expression.unwrapArgument()
|
||||||
expression.expression
|
|
||||||
} else {
|
|
||||||
expression
|
|
||||||
}
|
|
||||||
if (annotationMode && unwrappedExpression is FirFunctionCall) {
|
if (annotationMode && unwrappedExpression is FirFunctionCall) {
|
||||||
convertToIrCall(unwrappedExpression, annotationMode)
|
convertToIrCall(unwrappedExpression, annotationMode)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -494,7 +494,7 @@ fun FirExpression.isFunctional(
|
|||||||
scopeSession: ScopeSession,
|
scopeSession: ScopeSession,
|
||||||
expectedFunctionType: ConeKotlinType?,
|
expectedFunctionType: ConeKotlinType?,
|
||||||
): Boolean {
|
): Boolean {
|
||||||
when ((this as? FirWrappedArgumentExpression)?.expression ?: this) {
|
when (unwrapArgument()) {
|
||||||
is FirAnonymousFunction, is FirCallableReferenceAccess -> return true
|
is FirAnonymousFunction, is FirCallableReferenceAccess -> return true
|
||||||
else -> {
|
else -> {
|
||||||
// Either a functional type or a subtype of a class that has a contributed `invoke`.
|
// Either a functional type or a subtype of a class that has a contributed `invoke`.
|
||||||
|
|||||||
+1
-2
@@ -103,7 +103,7 @@ fun createArgumentsMapping(qualifiedAccess: FirQualifiedAccess): Map<Int, FirExp
|
|||||||
val parameterToIndex = function.valueParameters.mapIndexed { index, parameter -> parameter to index }.toMap()
|
val parameterToIndex = function.valueParameters.mapIndexed { index, parameter -> parameter to index }.toMap()
|
||||||
val callArgumentMapping = qualifiedAccess.argumentMapping ?: return null
|
val callArgumentMapping = qualifiedAccess.argumentMapping ?: return null
|
||||||
for (argument in qualifiedAccess.arguments) {
|
for (argument in qualifiedAccess.arguments) {
|
||||||
argumentsMapping[parameterToIndex.getValue(callArgumentMapping.getValue(argument))] = argument.unwrap()
|
argumentsMapping[parameterToIndex.getValue(callArgumentMapping.getValue(argument))] = argument.unwrapArgument()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is FirVariableAssignment -> {
|
is FirVariableAssignment -> {
|
||||||
@@ -113,4 +113,3 @@ fun createArgumentsMapping(qualifiedAccess: FirQualifiedAccess): Map<Int, FirExp
|
|||||||
return argumentsMapping
|
return argumentsMapping
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun FirExpression.unwrap(): FirExpression = if (this is FirWrappedArgumentExpression) expression else this
|
|
||||||
|
|||||||
-5
@@ -755,11 +755,6 @@ private fun ExpectedArgumentType.getExpectedType(argument: FirExpression): ConeK
|
|||||||
|
|
||||||
fun ConeKotlinType.toExpectedType(): ExpectedArgumentType = ExpectedArgumentType.ExpectedType(this)
|
fun ConeKotlinType.toExpectedType(): ExpectedArgumentType = ExpectedArgumentType.ExpectedType(this)
|
||||||
|
|
||||||
private fun FirExpression.unwrapArgument(): FirExpression = when (this) {
|
|
||||||
is FirWrappedArgumentExpression -> expression
|
|
||||||
else -> this
|
|
||||||
}
|
|
||||||
|
|
||||||
class FirDeclarationCompletionResultsWriter(private val finalSubstitutor: ConeSubstitutor) : FirDefaultTransformer<Any?>() {
|
class FirDeclarationCompletionResultsWriter(private val finalSubstitutor: ConeSubstitutor) : FirDefaultTransformer<Any?>() {
|
||||||
override fun <E : FirElement> transformElement(element: E, data: Any?): E {
|
override fun <E : FirElement> transformElement(element: E, data: Any?): E {
|
||||||
return element
|
return element
|
||||||
|
|||||||
@@ -108,3 +108,5 @@ fun FirBlock.replaceFirstStatement(statement: FirStatement): FirStatement {
|
|||||||
statements[0] = statement
|
statements[0] = statement
|
||||||
return existed
|
return existed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun FirExpression.unwrapArgument(): FirExpression = (this as? FirWrappedArgumentExpression)?.expression ?: this
|
||||||
Reference in New Issue
Block a user