diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirValReassignmentChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirValReassignmentChecker.kt index fd63dcf3248..f36a52d19f4 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirValReassignmentChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirValReassignmentChecker.kt @@ -12,13 +12,16 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn import org.jetbrains.kotlin.fir.declarations.FirPropertyAccessor +import org.jetbrains.kotlin.fir.declarations.FirValueParameter import org.jetbrains.kotlin.fir.expressions.FirVariableAssignment import org.jetbrains.kotlin.fir.languageVersionSettings import org.jetbrains.kotlin.fir.references.FirBackingFieldReference +import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference object FirValReassignmentChecker : FirVariableAssignmentChecker() { override fun check(expression: FirVariableAssignment, context: CheckerContext, reporter: DiagnosticReporter) { checkValReassignmentViaBackingField(expression, context, reporter) + checkValReassignmentOnValueParameter(expression, context, reporter) } private fun checkValReassignmentViaBackingField( @@ -40,4 +43,13 @@ object FirValReassignmentChecker : FirVariableAssignmentChecker() { } } } + + private fun checkValReassignmentOnValueParameter( + expression: FirVariableAssignment, + context: CheckerContext, + reporter: DiagnosticReporter + ) { + val valueParameter = (expression.lValue as? FirResolvedNamedReference)?.resolvedSymbol?.fir as? FirValueParameter ?: return + reporter.reportOn(expression.lValue.source, FirErrors.VAL_REASSIGNMENT, valueParameter.symbol, context) + } } diff --git a/compiler/testData/diagnostics/tests/LValueAssignment.fir.kt b/compiler/testData/diagnostics/tests/LValueAssignment.fir.kt index 0126256aa7c..66d2a62cf01 100644 --- a/compiler/testData/diagnostics/tests/LValueAssignment.fir.kt +++ b/compiler/testData/diagnostics/tests/LValueAssignment.fir.kt @@ -59,7 +59,7 @@ fun canBe(i0: Int, j: Int) { var i = i0 (label@ i) = 34 - (label@ j) = 34 //repeat for j + (label@ j) = 34 //repeat for j val a = A() (l@ a.a) = 3894 @@ -69,7 +69,7 @@ fun canBe(i0: Int, j: Int) { } fun canBe2(j: Int) { - (label@ j) = 34 + (label@ j) = 34 } class A() { diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/UninitializedOrReassignedVariables.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/UninitializedOrReassignedVariables.fir.kt index 9d8041460cc..c1bae7ff55e 100644 --- a/compiler/testData/diagnostics/tests/controlFlowAnalysis/UninitializedOrReassignedVariables.fir.kt +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/UninitializedOrReassignedVariables.fir.kt @@ -54,7 +54,7 @@ fun t2() { class A() {} fun t4(a: A) { - a = A() + a = A() } // ------------------------------------------------ @@ -188,7 +188,7 @@ class AnonymousInitializers(var a: String, val b: String) { } fun reassignFunParams(a: Int) { - a = 1 + a = 1 } open class Open(a: Int, w: Int) {} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInUnaryExpr.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInUnaryExpr.fir.kt index 1f14c0fe2c9..6b80750ba54 100644 --- a/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInUnaryExpr.fir.kt +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInUnaryExpr.fir.kt @@ -5,7 +5,7 @@ fun testPrefix() { fun testPostfixWithCall(n: Nothing) { operator fun Nothing.inc(): Nothing = this - n++ + n++ } fun testPostfixSpecial() { diff --git a/compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnClass.fir.kt b/compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnClass.fir.kt deleted file mode 100644 index ee06a9d6554..00000000000 --- a/compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnClass.fir.kt +++ /dev/null @@ -1,7 +0,0 @@ -@Suppress("warnings") -class C { - fun foo(p: String??) { - // Make sure errors are not suppressed: - p = "" - } -} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnClass.kt b/compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnClass.kt index 0cf408cfd46..e0ab8e5b1e2 100644 --- a/compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnClass.kt +++ b/compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnClass.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL @Suppress("warnings") class C { fun foo(p: String??) { diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/13.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/13.fir.kt index 678c046f809..8ac004ec9d6 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/13.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/13.fir.kt @@ -5,7 +5,7 @@ // TESTCASE NUMBER: 1 fun case_1(x: Class?) { x!! - x[if (true) {x=null;0} else 0] += x[0] + x[if (true) {x=null;0} else 0] += x[0] x x[0].inv() }