diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/OperatorToFunctionIntention.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/OperatorToFunctionIntention.kt index 99eca9a9d2a..039c51e05a9 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/OperatorToFunctionIntention.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/OperatorToFunctionIntention.kt @@ -40,6 +40,7 @@ class OperatorToFunctionIntention : SelfTargetingIntention(KtExpression::class.java, "Replace overloaded operator with function call") { companion object { private fun isApplicableUnary(element: KtUnaryExpression, caretOffset: Int): Boolean { + if (element.baseExpression == null) return false val opRef = element.operationReference if (!opRef.textRange.containsOffset(caretOffset)) return false return when (opRef.getReferencedNameElementType()) { @@ -63,6 +64,7 @@ class OperatorToFunctionIntention : } private fun isApplicableBinary(element: KtBinaryExpression, caretOffset: Int): Boolean { + if (element.left == null || element.right == null) return false val opRef = element.operationReference if (!opRef.textRange.containsOffset(caretOffset)) return false return when (opRef.getReferencedNameElementType()) { diff --git a/idea/testData/intentions/operatorToFunction/incompleteBinaryExpression.kt b/idea/testData/intentions/operatorToFunction/incompleteBinaryExpression.kt new file mode 100644 index 00000000000..dca172d87d4 --- /dev/null +++ b/idea/testData/intentions/operatorToFunction/incompleteBinaryExpression.kt @@ -0,0 +1,4 @@ +// DISABLE-ERRORS +// IS_APPLICABLE: false + +val x: Int = 1 + \ No newline at end of file diff --git a/idea/testData/intentions/operatorToFunction/incompleteUnaryExpression.kt b/idea/testData/intentions/operatorToFunction/incompleteUnaryExpression.kt new file mode 100644 index 00000000000..0910ca16b53 --- /dev/null +++ b/idea/testData/intentions/operatorToFunction/incompleteUnaryExpression.kt @@ -0,0 +1,3 @@ +// IS_APPLICABLE: false + +val x = + \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java index b884b84f510..b3035594b1b 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -12492,6 +12492,16 @@ public class IntentionTestGenerated extends AbstractIntentionTest { runTest("idea/testData/intentions/operatorToFunction/inRightSideOfAssignment.kt"); } + @TestMetadata("incompleteBinaryExpression.kt") + public void testIncompleteBinaryExpression() throws Exception { + runTest("idea/testData/intentions/operatorToFunction/incompleteBinaryExpression.kt"); + } + + @TestMetadata("incompleteUnaryExpression.kt") + public void testIncompleteUnaryExpression() throws Exception { + runTest("idea/testData/intentions/operatorToFunction/incompleteUnaryExpression.kt"); + } + @TestMetadata("keepComments.kt") public void testKeepComments() throws Exception { runTest("idea/testData/intentions/operatorToFunction/keepComments.kt");