From 5d16753285e87a6821785852ac94e6b44d4c405b Mon Sep 17 00:00:00 2001 From: Dmitry Gridin Date: Wed, 23 Oct 2019 19:58:43 +0700 Subject: [PATCH] ImportFix: add support for `WRONG_NUMBER_OF_TYPE_ARGUMENTS` #KT-23834 Fixed --- .../kotlin/idea/quickfix/ImportFix.kt | 3 +- .../kotlin/idea/quickfix/QuickFixRegistrar.kt | 1 + .../extensionWrongTypeParam.test | 42 +++++++++++++++++++ .../QuickFixMultiFileTestGenerated.java | 5 +++ 4 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 idea/testData/quickfix/autoImports/mismatchingArgs/extensionWrongTypeParam.test diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/ImportFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/ImportFix.kt index 9086db34352..010e96af435 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/ImportFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/ImportFix.kt @@ -567,7 +567,8 @@ internal class ImportForMismatchingArgumentsFix( callExpression.valueArguments.mapNotNull { it.getArgumentName()?.referenceExpression } + listOfNotNull( callExpression.valueArgumentList, - callExpression.referenceExpression() + callExpression.referenceExpression(), + callExpression.typeArgumentList ) } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt index 90d787c5444..6637eba9740 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt @@ -165,6 +165,7 @@ class QuickFixRegistrar : QuickFixContributor { CONSTANT_EXPECTED_TYPE_MISMATCH.registerFactory(ImportForMismatchingArgumentsFix) NAMED_PARAMETER_NOT_FOUND.registerFactory(ImportForMismatchingArgumentsFix) NONE_APPLICABLE.registerFactory(ImportForMismatchingArgumentsFix) + WRONG_NUMBER_OF_TYPE_ARGUMENTS.registerFactory(ImportForMismatchingArgumentsFix) UNRESOLVED_REFERENCE_WRONG_RECEIVER.registerFactory(ImportFix) diff --git a/idea/testData/quickfix/autoImports/mismatchingArgs/extensionWrongTypeParam.test b/idea/testData/quickfix/autoImports/mismatchingArgs/extensionWrongTypeParam.test new file mode 100644 index 00000000000..61fb734ade7 --- /dev/null +++ b/idea/testData/quickfix/autoImports/mismatchingArgs/extensionWrongTypeParam.test @@ -0,0 +1,42 @@ +// FILE: first.before.kt +// "Import" "true" +// ERROR: No type arguments expected for fun shade(): Unit +// ACTION: Create type parameter in function 'shade' +// COMPILER_ARGUMENTS: -XXLanguage:-NewInference + +package pack_one + +class Shadow { + fun shade() {} +} + +fun main() { + Shadow().shade() +} + +// FILE: second.kt +package pack_one.sub + +import pack_one.Shadow + +fun Shadow.shade() {} + + +// FILE: first.after.kt +// "Import" "true" +// ERROR: No type arguments expected for fun shade(): Unit +// ACTION: Create type parameter in function 'shade' +// COMPILER_ARGUMENTS: -XXLanguage:-NewInference + +package pack_one + +import pack_one.sub.shade + +class Shadow { + fun shade() {} +} + +fun main() { + Shadow().shade() +} + diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java index 15121e5b9da..2145ee4ee19 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java @@ -1115,6 +1115,11 @@ public class QuickFixMultiFileTestGenerated extends AbstractQuickFixMultiFileTes runTest("idea/testData/quickfix/autoImports/mismatchingArgs/extensionWrongReceiver.test"); } + @TestMetadata("extensionWrongTypeParam.test") + public void testExtensionWrongTypeParam() throws Exception { + runTest("idea/testData/quickfix/autoImports/mismatchingArgs/extensionWrongTypeParam.test"); + } + @TestMetadata("ignoreErrorsOutsideCall.test") public void testIgnoreErrorsOutsideCall() throws Exception { runTest("idea/testData/quickfix/autoImports/mismatchingArgs/ignoreErrorsOutsideCall.test");