From da1178fe0c959bbac54184410d5cadca8668bf92 Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Tue, 4 Oct 2016 16:23:36 +0300 Subject: [PATCH] Create from Usages: Do not suggest on type-mismatched expressions which are not call arguments #KT-14143 Fixed --- ChangeLog.md | 1 + .../CreateCallableFromCallActionFactory.kt | 4 +--- .../createFunction/call/notExactArgument.kt | 11 +++++++++++ .../kotlin/idea/quickfix/QuickFixTestGenerated.java | 6 ++++++ 4 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 idea/testData/quickfix/createFromUsage/createFunction/call/notExactArgument.kt diff --git a/ChangeLog.md b/ChangeLog.md index d95c8358da5..bb21d220e9a 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -211,6 +211,7 @@ These artifacts include extensions for the types available in the latter JDKs, s - [`KT-13933`](https://youtrack.jetbrains.com/issue/KT-13933) Convert Parameter to Receiver: Do not qualify companion members with labeled 'this' - [`KT-13942`](https://youtrack.jetbrains.com/issue/KT-13942) Redundant 'toString()' in String Template: Disable for qualified expressions with 'super' receiver - [`KT-13878`](https://youtrack.jetbrains.com/issue/KT-13878) Remove Redundant Receiver Parameter: Fix exception receiver removal +- [`KT-14143`](https://youtrack.jetbrains.com/issue/KT-14143) Create from Usages: Do not suggest on type-mismatched expressions which are not call arguments ##### New features diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateCallableFromCallActionFactory.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateCallableFromCallActionFactory.kt index 8676a2b674a..3c5532adc44 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateCallableFromCallActionFactory.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateCallableFromCallActionFactory.kt @@ -75,9 +75,7 @@ sealed class CreateCallableFromCallActionFactory( Errors.TOO_MANY_ARGUMENTS, Errors.NONE_APPLICABLE -> diagElement.getNonStrictParentOfType() - Errors.TYPE_MISMATCH -> diagElement - .getParentOfTypeAndBranch { getArgumentExpression() } - ?.getStrictParentOfType() + Errors.TYPE_MISMATCH -> (diagElement.parent as? KtValueArgument)?.getStrictParentOfType() else -> throw AssertionError("Unexpected diagnostic: ${diagnostic.factory}") } as? KtExpression diff --git a/idea/testData/quickfix/createFromUsage/createFunction/call/notExactArgument.kt b/idea/testData/quickfix/createFromUsage/createFunction/call/notExactArgument.kt new file mode 100644 index 00000000000..bec3f3d6ec4 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createFunction/call/notExactArgument.kt @@ -0,0 +1,11 @@ +// "Create function 'synchronized'" "false" +// ACTION: Convert expression to 'Int' +// ERROR: Type mismatch: inferred type is Float but Int was expected +// WITH_RUNTIME + +fun test() { + var value = 0 + synchronized(value) { + value = 10 / 1f + } +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java index f94e028c0e9..d346d229e7d 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java @@ -2277,6 +2277,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { doTest(fileName); } + @TestMetadata("notExactArgument.kt") + public void testNotExactArgument() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createFunction/call/notExactArgument.kt"); + doTest(fileName); + } + @TestMetadata("objectMemberFunNoReceiver.kt") public void testObjectMemberFunNoReceiver() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createFunction/call/objectMemberFunNoReceiver.kt");