Skip to content

Commit 8f98190

Browse files
GrigoriiSolnyshkinSpace Team
authored andcommitted
[FIR] Change the positioning of the REDUNDANT_SPREAD warning to (*)
^KT-81525 Fixed This automatically fixes a bug where `REDUNDANT_SPREAD_OPERATOR_IN_NAMED_FORM` was reported on a PSI element with an incorrect type (`KtValueArgument` instead of `KtExpression` when the argument expression is missing).
1 parent d376156 commit 8f98190

File tree

17 files changed

+84
-27
lines changed

17 files changed

+84
-27
lines changed

analysis/analysis-api-fir/gen/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KaFirDiagnostics.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,11 +1647,11 @@ sealed interface KaFirDiagnostic<PSI : PsiElement> : KaDiagnosticWithPsi<PSI> {
16471647
override val diagnosticClass get() = AssigningSingleElementToVarargInNamedFormAnnotationWarning::class
16481648
}
16491649

1650-
interface RedundantSpreadOperatorInNamedFormInFunction : KaFirDiagnostic<KtExpression> {
1650+
interface RedundantSpreadOperatorInNamedFormInFunction : KaFirDiagnostic<KtElement> {
16511651
override val diagnosticClass get() = RedundantSpreadOperatorInNamedFormInFunction::class
16521652
}
16531653

1654-
interface RedundantSpreadOperatorInNamedFormInAnnotation : KaFirDiagnostic<KtExpression> {
1654+
interface RedundantSpreadOperatorInNamedFormInAnnotation : KaFirDiagnostic<KtElement> {
16551655
override val diagnosticClass get() = RedundantSpreadOperatorInNamedFormInAnnotation::class
16561656
}
16571657

analysis/analysis-api-fir/gen/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KaFirDiagnosticsImpl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1981,12 +1981,12 @@ internal class AssigningSingleElementToVarargInNamedFormAnnotationWarningImpl(
19811981
internal class RedundantSpreadOperatorInNamedFormInFunctionImpl(
19821982
firDiagnostic: KtPsiDiagnostic,
19831983
token: KaLifetimeToken,
1984-
) : KaAbstractFirDiagnostic<KtExpression>(firDiagnostic, token), KaFirDiagnostic.RedundantSpreadOperatorInNamedFormInFunction
1984+
) : KaAbstractFirDiagnostic<KtElement>(firDiagnostic, token), KaFirDiagnostic.RedundantSpreadOperatorInNamedFormInFunction
19851985

19861986
internal class RedundantSpreadOperatorInNamedFormInAnnotationImpl(
19871987
firDiagnostic: KtPsiDiagnostic,
19881988
token: KaLifetimeToken,
1989-
) : KaAbstractFirDiagnostic<KtExpression>(firDiagnostic, token), KaFirDiagnostic.RedundantSpreadOperatorInNamedFormInAnnotation
1989+
) : KaAbstractFirDiagnostic<KtElement>(firDiagnostic, token), KaFirDiagnostic.RedundantSpreadOperatorInNamedFormInAnnotation
19901990

19911991
internal class IllegalTypeArgumentForVarargParameterWarningImpl(
19921992
override val type: KaType,

compiler/fir/analysis-tests/testData/resolve/arguments/vararg.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fun test() {
1111
foo(<!ARGUMENT_TYPE_MISMATCH!>""<!>)
1212
foo(1, <!ARGUMENT_TYPE_MISMATCH!>2<!>)
1313

14-
bar(1, z = true, y = *<!REDUNDANT_SPREAD_OPERATOR_IN_NAMED_FORM_IN_FUNCTION!>arrayOf("my", "yours")<!>)
14+
bar(1, z = true, y = <!REDUNDANT_SPREAD_OPERATOR_IN_NAMED_FORM_IN_FUNCTION!>*<!>arrayOf("my", "yours"))
1515

1616
bar(0, z = false, y = <!ARGUMENT_TYPE_MISMATCH, ASSIGNING_SINGLE_ELEMENT_TO_VARARG_IN_NAMED_FORM_FUNCTION_ERROR!>""<!>, <!ARGUMENT_PASSED_TWICE!>y<!> = "other")
1717
bar(0, "", <!NO_VALUE_FOR_PARAMETER!><!ARGUMENT_TYPE_MISMATCH!>true<!>)<!>

compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -726,8 +726,8 @@ object DIAGNOSTICS_LIST : DiagnosticList("FirErrors") {
726726
parameter<ConeKotlinType>("expectedArrayType")
727727
}
728728
val ASSIGNING_SINGLE_ELEMENT_TO_VARARG_IN_NAMED_FORM_ANNOTATION by deprecationError<KtExpression>(LanguageFeature.ProhibitAssigningSingleElementsToVarargsInNamedForm)
729-
val REDUNDANT_SPREAD_OPERATOR_IN_NAMED_FORM_IN_FUNCTION by warning<KtExpression>()
730-
val REDUNDANT_SPREAD_OPERATOR_IN_NAMED_FORM_IN_ANNOTATION by warning<KtExpression>()
729+
val REDUNDANT_SPREAD_OPERATOR_IN_NAMED_FORM_IN_FUNCTION by warning<KtElement>(PositioningStrategy.SPREAD_OPERATOR)
730+
val REDUNDANT_SPREAD_OPERATOR_IN_NAMED_FORM_IN_ANNOTATION by warning<KtElement>(PositioningStrategy.SPREAD_OPERATOR)
731731

732732
val ILLEGAL_TYPE_ARGUMENT_FOR_VARARG_PARAMETER_WARNING by warning<KtElement>(PositioningStrategy.REFERENCE_BY_QUALIFIED) {
733733
parameter<ConeKotlinType>("type")

compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,8 @@ object FirErrors : KtDiagnosticsContainer() {
468468
val MANY_LAMBDA_EXPRESSION_ARGUMENTS: KtDiagnosticFactory0 = KtDiagnosticFactory0("MANY_LAMBDA_EXPRESSION_ARGUMENTS", ERROR, SourceElementPositioningStrategies.DEFAULT, KtLambdaExpression::class, getRendererFactory())
469469
val ASSIGNING_SINGLE_ELEMENT_TO_VARARG_IN_NAMED_FORM_FUNCTION: KtDiagnosticFactoryForDeprecation1<ConeKotlinType> = KtDiagnosticFactoryForDeprecation1("ASSIGNING_SINGLE_ELEMENT_TO_VARARG_IN_NAMED_FORM_FUNCTION", ProhibitAssigningSingleElementsToVarargsInNamedForm, SourceElementPositioningStrategies.DEFAULT, KtExpression::class, getRendererFactory())
470470
val ASSIGNING_SINGLE_ELEMENT_TO_VARARG_IN_NAMED_FORM_ANNOTATION: KtDiagnosticFactoryForDeprecation0 = KtDiagnosticFactoryForDeprecation0("ASSIGNING_SINGLE_ELEMENT_TO_VARARG_IN_NAMED_FORM_ANNOTATION", ProhibitAssigningSingleElementsToVarargsInNamedForm, SourceElementPositioningStrategies.DEFAULT, KtExpression::class, getRendererFactory())
471-
val REDUNDANT_SPREAD_OPERATOR_IN_NAMED_FORM_IN_FUNCTION: KtDiagnosticFactory0 = KtDiagnosticFactory0("REDUNDANT_SPREAD_OPERATOR_IN_NAMED_FORM_IN_FUNCTION", WARNING, SourceElementPositioningStrategies.DEFAULT, KtExpression::class, getRendererFactory())
472-
val REDUNDANT_SPREAD_OPERATOR_IN_NAMED_FORM_IN_ANNOTATION: KtDiagnosticFactory0 = KtDiagnosticFactory0("REDUNDANT_SPREAD_OPERATOR_IN_NAMED_FORM_IN_ANNOTATION", WARNING, SourceElementPositioningStrategies.DEFAULT, KtExpression::class, getRendererFactory())
471+
val REDUNDANT_SPREAD_OPERATOR_IN_NAMED_FORM_IN_FUNCTION: KtDiagnosticFactory0 = KtDiagnosticFactory0("REDUNDANT_SPREAD_OPERATOR_IN_NAMED_FORM_IN_FUNCTION", WARNING, SourceElementPositioningStrategies.SPREAD_OPERATOR, KtElement::class, getRendererFactory())
472+
val REDUNDANT_SPREAD_OPERATOR_IN_NAMED_FORM_IN_ANNOTATION: KtDiagnosticFactory0 = KtDiagnosticFactory0("REDUNDANT_SPREAD_OPERATOR_IN_NAMED_FORM_IN_ANNOTATION", WARNING, SourceElementPositioningStrategies.SPREAD_OPERATOR, KtElement::class, getRendererFactory())
473473
val ILLEGAL_TYPE_ARGUMENT_FOR_VARARG_PARAMETER_WARNING: KtDiagnosticFactory1<ConeKotlinType> = KtDiagnosticFactory1("ILLEGAL_TYPE_ARGUMENT_FOR_VARARG_PARAMETER_WARNING", WARNING, SourceElementPositioningStrategies.REFERENCE_BY_QUALIFIED, KtElement::class, getRendererFactory())
474474
val NESTED_CLASS_ACCESSED_VIA_INSTANCE_REFERENCE: KtDiagnosticFactory1<FirClassLikeSymbol<*>> = KtDiagnosticFactory1("NESTED_CLASS_ACCESSED_VIA_INSTANCE_REFERENCE", ERROR, SourceElementPositioningStrategies.DEFAULT, PsiElement::class, getRendererFactory())
475475

compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirNamedVarargChecker.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ object FirNamedVarargChecker : FirCallChecker(MppCheckerKind.Common) {
3838
if (!isNamedSpread(argument)) return
3939
if (!argument.isFakeSpread && argument.isNamed) {
4040
if (isVararg && (expression as? FirResolvable)?.calleeReference !is FirResolvedErrorReference) {
41-
reporter.reportOn(argument.expression.source, redundantSpreadWarningFactory)
41+
reporter.reportOn(argument.source, redundantSpreadWarningFactory)
4242
}
4343
return
4444
}

compiler/frontend.common-psi/src/org/jetbrains/kotlin/diagnostics/PositioningStrategies.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,7 @@ object PositioningStrategies {
10361036
}
10371037
}
10381038

1039+
@JvmField
10391040
val SPREAD_OPERATOR: PositioningStrategy<PsiElement> = object : PositioningStrategy<PsiElement>() {
10401041
override fun mark(element: PsiElement): List<TextRange> {
10411042
return super.mark((element as? KtValueArgument)?.getSpreadElement()?.node?.psi ?: element)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// RUN_PIPELINE_TILL: BACKEND
2+
// DIAGNOSTICS: -UNUSED_PARAMETER
3+
// LANGUAGE: +UseCorrectExecutionOrderForVarargArguments
4+
// WITH_STDLIB
5+
6+
fun foo(vararg x: Unit, y: Any) {}
7+
8+
fun main() {
9+
foo({ }(), y = { }())
10+
foo(x = <!REDUNDANT_SPREAD_OPERATOR_IN_NAMED_FORM_IN_FUNCTION!>*<!>arrayOf({ }()), y = { }())
11+
foo(x = arrayOf({ }()), y = { }())
12+
foo(*arrayOf({ }()), y = { }())
13+
}
14+
15+
fun foo2(vararg x: Unit, y: Any, z: Any) {}
16+
17+
fun main2() {
18+
foo2(y = { }(), x = arrayOf({ }()), z = { }())
19+
}
20+
21+
fun foo3(vararg x: Unit, y: Any, z: Any = { }()) {}
22+
23+
fun main3() {
24+
// no warning, execution order is already right
25+
foo3(y = { }(), x = arrayOf({ }()))
26+
}
27+
28+
/* GENERATED_FIR_TAGS: functionDeclaration, lambdaLiteral, vararg */

compiler/testData/diagnostics/tests/checkArguments/kt17691WithEnabledFeature.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// RUN_PIPELINE_TILL: BACKEND
2-
// FIR_IDENTICAL
32
// DIAGNOSTICS: -UNUSED_PARAMETER
43
// LANGUAGE: +UseCorrectExecutionOrderForVarargArguments
54
// WITH_STDLIB

compiler/testData/diagnostics/tests/collectionLiterals/collectionLiteralsWithVarargs.fir.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fun test1_2() {}
2323
@Ann2(*[])
2424
fun test2() {}
2525

26-
@Ann3(a = *<!REDUNDANT_SPREAD_OPERATOR_IN_NAMED_FORM_IN_ANNOTATION!>[0f, <!DIVISION_BY_ZERO!>1 / 0f<!>]<!>)
26+
@Ann3(a = <!REDUNDANT_SPREAD_OPERATOR_IN_NAMED_FORM_IN_ANNOTATION!>*<!>[0f, <!DIVISION_BY_ZERO!>1 / 0f<!>])
2727
fun test3() {}
2828

2929
@Ann5(Ann4(*["/"]))

0 commit comments

Comments
 (0)