diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixFactoryForTypeMismatchError.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixFactoryForTypeMismatchError.kt index cae099a1a27..0a6fdd5cc3a 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixFactoryForTypeMismatchError.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixFactoryForTypeMismatchError.kt @@ -28,6 +28,7 @@ import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade import org.jetbrains.kotlin.idea.core.quickfix.QuickFixUtil import org.jetbrains.kotlin.idea.util.approximateWithResolvableType import org.jetbrains.kotlin.idea.util.getResolutionScope +import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.getQualifiedExpressionForSelectorOrThis import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType @@ -38,6 +39,7 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.getParentResolvedCall import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall import org.jetbrains.kotlin.resolve.calls.callUtil.getValueArgumentForExpression import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall +import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.typeUtil.isInterface import org.jetbrains.kotlin.types.typeUtil.isPrimitiveNumberType @@ -101,8 +103,7 @@ class QuickFixFactoryForTypeMismatchError : KotlinIntentionActionsFactory() { actions.add(NumberConversionFix(diagnosticElement, expectedType, wrongPrimitiveLiteralFix)) } - if (KotlinBuiltIns.isCharSequenceOrNullableCharSequence(expectedType) - || KotlinBuiltIns.isStringOrNullableString(expectedType)) { + if (KotlinBuiltIns.isCharSequenceOrNullableCharSequence(expectedType) || KotlinBuiltIns.isStringOrNullableString(expectedType)) { actions.add(AddToStringFix(diagnosticElement, false)) if (expectedType.isMarkedNullable && expressionType.isMarkedNullable) { actions.add(AddToStringFix(diagnosticElement, true)) @@ -146,7 +147,9 @@ class QuickFixFactoryForTypeMismatchError : KotlinIntentionActionsFactory() { if (property != null) { val getter = property.getter val initializer = property.initializer - if (QuickFixUtil.canEvaluateTo(initializer, diagnosticElement) || getter != null && QuickFixUtil.canFunctionOrGetterReturnExpression(getter, diagnosticElement)) { + if (QuickFixUtil.canEvaluateTo(initializer, diagnosticElement) + || getter != null && QuickFixUtil.canFunctionOrGetterReturnExpression(getter, diagnosticElement) + ) { val scope = property.getResolutionScope(context, property.getResolutionFacade()) val typeToInsert = expressionType.approximateWithResolvableType(scope, false) actions.add(ChangeVariableTypeFix(property, typeToInsert)) @@ -192,7 +195,9 @@ class QuickFixFactoryForTypeMismatchError : KotlinIntentionActionsFactory() { // KT-10063: arrayOf() bounding single array element val annotationEntry = PsiTreeUtil.getParentOfType(diagnosticElement, KtAnnotationEntry::class.java) if (annotationEntry != null) { - if (KotlinBuiltIns.isArray(expectedType) && expressionType.isSubtypeOf(expectedType.arguments[0].type) || KotlinBuiltIns.isPrimitiveArray(expectedType)) { + if (KotlinBuiltIns.isArray(expectedType) && expressionType.isSubtypeOf(expectedType.arguments[0].type) + || KotlinBuiltIns.isPrimitiveArray(expectedType) + ) { actions.add(AddArrayOfTypeFix(diagnosticElement, expectedType)) } } @@ -225,10 +230,12 @@ class QuickFixFactoryForTypeMismatchError : KotlinIntentionActionsFactory() { val typeToInsert = valueArgumentType.approximateWithResolvableType(scope, true) actions.add(ChangeParameterTypeFix(correspondingParameter, typeToInsert)) } - if (correspondingParameterDescriptor?.varargElementType != null + val parameterVarargType = correspondingParameterDescriptor?.varargElementType + if ((parameterVarargType != null || resolvedCall.resultingDescriptor.fqNameSafe == FqName("kotlin.collections.mapOf")) && KotlinBuiltIns.isArray(valueArgumentType) && expressionType.arguments.isNotEmpty() - && expressionType.arguments[0].type.constructor == expectedType.constructor) { + && expressionType.arguments[0].type.constructor == expectedType.constructor + ) { actions.add(ChangeToUseSpreadOperatorFix(diagnosticElement)) } } diff --git a/idea/testData/quickfix/changeToUseSpreadOperator/mapOfBug.kt b/idea/testData/quickfix/changeToUseSpreadOperator/mapOfBug.kt deleted file mode 100644 index af15d6b0b29..00000000000 --- a/idea/testData/quickfix/changeToUseSpreadOperator/mapOfBug.kt +++ /dev/null @@ -1,11 +0,0 @@ -// "Change 'pairs' to '*pairs'" "false" -// WITH_RUNTIME -// ACTION: Create function 'mapOf' -// ERROR: Type inference failed: fun mapOf(pair: Pair): Map
cannot be applied to
(Array>)
-// ERROR: Type mismatch: inferred type is Array> but Pair was expected - - -fun myMapOf(vararg pairs: Pair) { - // Does not work due to KT-15593 - val myMap = mapOf(pairs) -} \ No newline at end of file diff --git a/idea/testData/quickfix/changeToUseSpreadOperator/stdlibMapOf.kt b/idea/testData/quickfix/changeToUseSpreadOperator/stdlibMapOf.kt new file mode 100644 index 00000000000..4549e8fc397 --- /dev/null +++ b/idea/testData/quickfix/changeToUseSpreadOperator/stdlibMapOf.kt @@ -0,0 +1,6 @@ +// "Change 'pairs' to '*pairs'" "true" +// WITH_RUNTIME + +fun myMapOf(vararg pairs: Pair) { + val myMap = mapOf(pairs) +} \ No newline at end of file diff --git a/idea/testData/quickfix/changeToUseSpreadOperator/stdlibMapOf.kt.after b/idea/testData/quickfix/changeToUseSpreadOperator/stdlibMapOf.kt.after new file mode 100644 index 00000000000..1bea4728770 --- /dev/null +++ b/idea/testData/quickfix/changeToUseSpreadOperator/stdlibMapOf.kt.after @@ -0,0 +1,6 @@ +// "Change 'pairs' to '*pairs'" "true" +// WITH_RUNTIME + +fun myMapOf(vararg pairs: Pair) { + val myMap = mapOf(*pairs) +} \ 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 06768984177..e26dd226963 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java @@ -1717,11 +1717,6 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { runTest("idea/testData/quickfix/changeToUseSpreadOperator/mapOf.kt"); } - @TestMetadata("mapOfBug.kt") - public void testMapOfBug() throws Exception { - runTest("idea/testData/quickfix/changeToUseSpreadOperator/mapOfBug.kt"); - } - @TestMetadata("multipleParams.kt") public void testMultipleParams() throws Exception { runTest("idea/testData/quickfix/changeToUseSpreadOperator/multipleParams.kt"); @@ -1742,6 +1737,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { runTest("idea/testData/quickfix/changeToUseSpreadOperator/normal.kt"); } + @TestMetadata("stdlibMapOf.kt") + public void testStdlibMapOf() throws Exception { + runTest("idea/testData/quickfix/changeToUseSpreadOperator/stdlibMapOf.kt"); + } + @TestMetadata("vararg.kt") public void testVararg() throws Exception { runTest("idea/testData/quickfix/changeToUseSpreadOperator/vararg.kt");