[FIR] Report VARIABLE_EXPECTED on assign to this
This commit is contained in:
committed by
Space Team
parent
9ccbf8639d
commit
e87a064cdd
+12
@@ -18,6 +18,7 @@ import org.jetbrains.kotlin.fir.expressions.FirSmartCastExpression
|
||||
import org.jetbrains.kotlin.fir.expressions.FirVariableAssignment
|
||||
import org.jetbrains.kotlin.fir.originalForSubstitutionOverride
|
||||
import org.jetbrains.kotlin.fir.references.FirBackingFieldReference
|
||||
import org.jetbrains.kotlin.fir.references.FirThisReference
|
||||
import org.jetbrains.kotlin.fir.references.toResolvedCallableSymbol
|
||||
import org.jetbrains.kotlin.fir.references.toResolvedValueParameterSymbol
|
||||
import org.jetbrains.kotlin.fir.resolve.calls.ExpressionReceiverValue
|
||||
@@ -30,6 +31,7 @@ object FirReassignmentAndInvisibleSetterChecker : FirVariableAssignmentChecker()
|
||||
checkInvisibleSetter(expression, context, reporter)
|
||||
checkValReassignmentViaBackingField(expression, context, reporter)
|
||||
checkValReassignmentOnValueParameter(expression, context, reporter)
|
||||
checkAssignmentToThis(expression, context, reporter)
|
||||
}
|
||||
|
||||
private fun checkInvisibleSetter(
|
||||
@@ -102,4 +104,14 @@ object FirReassignmentAndInvisibleSetterChecker : FirVariableAssignmentChecker()
|
||||
val valueParameter = expression.lValue.toResolvedValueParameterSymbol() ?: return
|
||||
reporter.reportOn(expression.lValue.source, FirErrors.VAL_REASSIGNMENT, valueParameter, context)
|
||||
}
|
||||
|
||||
private fun checkAssignmentToThis(
|
||||
expression: FirVariableAssignment,
|
||||
context: CheckerContext,
|
||||
reporter: DiagnosticReporter
|
||||
) {
|
||||
if (expression.lValue is FirThisReference) {
|
||||
reporter.reportOn(expression.lValue.source, FirErrors.VARIABLE_EXPECTED, context)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ class C() : B() {
|
||||
}
|
||||
|
||||
fun bar(c: C) {
|
||||
this = c //should be an error
|
||||
<!VARIABLE_EXPECTED!>this<!> = c //should be an error
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ fun getInt() = 0
|
||||
class D() {
|
||||
inner class B() {
|
||||
fun foo() {
|
||||
this@D = D()
|
||||
<!VARIABLE_EXPECTED!>this@D<!> = D()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -93,7 +93,7 @@ class Test() {
|
||||
++<!VARIABLE_EXPECTED!>2<!>
|
||||
--(r@ <!VARIABLE_EXPECTED!>2<!>)
|
||||
|
||||
this<!UNRESOLVED_REFERENCE!>++<!>
|
||||
<!VARIABLE_EXPECTED!>this<!><!UNRESOLVED_REFERENCE!>++<!>
|
||||
|
||||
var s : String = "r"
|
||||
s += "ss"
|
||||
|
||||
Reference in New Issue
Block a user