Replace with binary operator: don't highlight when receiver is dynamic type
#KT-28773 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
2010b1756e
commit
f389c31d8e
+10
-1
@@ -34,6 +34,8 @@ import org.jetbrains.kotlin.idea.intentions.isOperatorOrCompatible
|
||||
import org.jetbrains.kotlin.idea.intentions.isReceiverExpressionWithValue
|
||||
import org.jetbrains.kotlin.idea.intentions.toResolvedCall
|
||||
import org.jetbrains.kotlin.idea.project.languageVersionSettings
|
||||
import org.jetbrains.kotlin.idea.project.platform
|
||||
import org.jetbrains.kotlin.js.resolve.JsPlatform
|
||||
import org.jetbrains.kotlin.lexer.KtSingleValueToken
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
@@ -41,6 +43,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getLastParentOfTypeInRow
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getFirstArgumentExpression
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getReceiverExpression
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getType
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ArgumentMatch
|
||||
import org.jetbrains.kotlin.resolve.calls.model.isReallySuccess
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory
|
||||
@@ -48,6 +51,7 @@ import org.jetbrains.kotlin.resolve.calls.smartcasts.getKotlinTypeWithPossibleSm
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||
import org.jetbrains.kotlin.types.isDynamic
|
||||
import org.jetbrains.kotlin.types.typeUtil.*
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
|
||||
@@ -83,8 +87,13 @@ class ReplaceCallWithBinaryOperatorInspection : AbstractApplicabilityBasedInspec
|
||||
override fun inspectionHighlightType(element: KtDotQualifiedExpression): ProblemHighlightType {
|
||||
val calleeExpression = element.callExpression?.calleeExpression as? KtSimpleNameExpression
|
||||
val identifier = calleeExpression?.getReferencedNameAsName()
|
||||
if (element.platform == JsPlatform && identifier == OperatorNameConventions.EQUALS) {
|
||||
val context = element.analyze(BodyResolveMode.PARTIAL)
|
||||
if (element.receiverExpression.getType(context)?.isDynamic() == true) {
|
||||
return ProblemHighlightType.INFORMATION
|
||||
}
|
||||
}
|
||||
val isFloatingPointNumberEquals = calleeExpression?.isFloatingPointNumberEquals() ?: false
|
||||
|
||||
return if (isFloatingPointNumberEquals) {
|
||||
ProblemHighlightType.INFORMATION
|
||||
} else if (identifier == OperatorNameConventions.EQUALS || identifier == OperatorNameConventions.COMPARE_TO) {
|
||||
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
// JS
|
||||
// HIGHLIGHT: INFORMATION
|
||||
fun foo(a: dynamic, b: String): Boolean {
|
||||
return a.<caret>equals(b)
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// JS
|
||||
// HIGHLIGHT: INFORMATION
|
||||
fun foo(a: dynamic, b: String): Boolean {
|
||||
return a == b
|
||||
}
|
||||
+5
@@ -1654,6 +1654,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
|
||||
runTest("idea/testData/inspectionsLocal/conventionNameCalls/replaceCallWithBinaryOperator/divSanityTest.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("dynamicEquals.kt")
|
||||
public void testDynamicEquals() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/conventionNameCalls/replaceCallWithBinaryOperator/dynamicEquals.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("equals.kt")
|
||||
public void testEquals() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/conventionNameCalls/replaceCallWithBinaryOperator/equals.kt");
|
||||
|
||||
Reference in New Issue
Block a user