[FIR] Fix for CanBeReplacedWithOperatorAssignment Checker
This commit is contained in:
+4
@@ -0,0 +1,4 @@
|
||||
fun foo(something: Boolean) {
|
||||
var res = false
|
||||
res = res and something
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
FILE: logicOperators.kt
|
||||
public final fun foo(something: R|kotlin/Boolean|): R|kotlin/Unit| {
|
||||
lvar res: R|kotlin/Boolean| = Boolean(false)
|
||||
R|<local>/res| = R|<local>/res|.R|kotlin/Boolean.and|(R|<local>/something|)
|
||||
}
|
||||
Generated
+5
@@ -115,6 +115,11 @@ public class ExtendedFirDiagnosticsTestGenerated extends AbstractExtendedFirDiag
|
||||
runTest("compiler/fir/analysis-tests/testData/extendedCheckers/canBeReplacedWithOperatorAssignment/list.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("logicOperators.kt")
|
||||
public void testLogicOperators() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/extendedCheckers/canBeReplacedWithOperatorAssignment/logicOperators.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("multipleOperators.kt")
|
||||
public void testMultipleOperators() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/extendedCheckers/canBeReplacedWithOperatorAssignment/multipleOperators.kt");
|
||||
|
||||
+7
@@ -46,6 +46,7 @@ object CanBeReplacedWithOperatorAssignmentChecker : FirExpressionChecker<FirVari
|
||||
}
|
||||
|
||||
fun KtBinaryExpression.matcher(variable: KtNameReferenceExpression): Boolean {
|
||||
if (!canBeAugmented()) return false
|
||||
if ((left as? KtNameReferenceExpression)?.getReferencedName() == variable.getReferencedName()) return true
|
||||
if ((right as? KtNameReferenceExpression)?.getReferencedName() == variable.getReferencedName() && isCommutative()) return true
|
||||
|
||||
@@ -68,5 +69,11 @@ object CanBeReplacedWithOperatorAssignmentChecker : FirExpressionChecker<FirVari
|
||||
|
||||
private fun KtBinaryExpression.isCommutative() = this.operationToken == KtTokens.PLUS || this.operationToken == KtTokens.MUL
|
||||
|
||||
private fun KtBinaryExpression.canBeAugmented() = this.operationToken == KtTokens.PLUS
|
||||
|| this.operationToken == KtTokens.MUL
|
||||
|| this.operationToken == KtTokens.MINUS
|
||||
|| this.operationToken == KtTokens.DIV
|
||||
|| this.operationToken == KtTokens.PERC
|
||||
|
||||
private fun isHierarchicallyTrue(currentOperation: IElementType, nextOperation: IElementType?) = currentOperation == nextOperation
|
||||
}
|
||||
Reference in New Issue
Block a user