diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/WrapWithCollectionLiteralCallFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/WrapWithCollectionLiteralCallFix.kt index 81c4b83e62c..aa60886172c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/WrapWithCollectionLiteralCallFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/WrapWithCollectionLiteralCallFix.kt @@ -9,11 +9,9 @@ import com.intellij.openapi.editor.Editor import com.intellij.openapi.project.Project import org.jetbrains.kotlin.idea.core.replaced import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isNullExpression -import org.jetbrains.kotlin.psi.KtExpression -import org.jetbrains.kotlin.psi.KtFile -import org.jetbrains.kotlin.psi.KtPsiFactory -import org.jetbrains.kotlin.psi.createExpressionByPattern +import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.endOffset +import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.Variance import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf @@ -46,6 +44,8 @@ class WrapWithCollectionLiteralCallFix private constructor( companion object { fun create(expectedType: KotlinType, expressionType: KotlinType, element: KtExpression): List { + if (element.getStrictParentOfType() != null) return emptyList() + val collectionType = with(ConvertCollectionFix) { expectedType.getCollectionType(acceptNullableTypes = true) diff --git a/idea/testData/quickfix/typeMismatch/wrapWithCollectionLiteral/inAnnotation.kt b/idea/testData/quickfix/typeMismatch/wrapWithCollectionLiteral/inAnnotation.kt new file mode 100644 index 00000000000..aa6cc360e98 --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/wrapWithCollectionLiteral/inAnnotation.kt @@ -0,0 +1,14 @@ +// "Wrap element with 'arrayOf' call" "false" +// ERROR: Type mismatch: inferred type is String but Array was expected +// ACTION: Add arrayOf wrapper +// ACTION: Change parameter 'value' type of primary constructor of class 'Foo' to 'String' +// ACTION: Create test +// ACTION: Make internal +// ACTION: Make private +// ACTION: To raw string literal +// ACTION: Wrap with [] + +annotation class Foo(val value: Array) + +@Foo(value = "abc") +class Bar \ 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 9bb25d89bda..ff4a96b52ce 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java @@ -12810,6 +12810,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/typeMismatch/wrapWithCollectionLiteral"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), TargetBackend.ANY, true); } + @TestMetadata("inAnnotation.kt") + public void testInAnnotation() throws Exception { + runTest("idea/testData/quickfix/typeMismatch/wrapWithCollectionLiteral/inAnnotation.kt"); + } + @TestMetadata("noMutableList.kt") public void testNoMutableList() throws Exception { runTest("idea/testData/quickfix/typeMismatch/wrapWithCollectionLiteral/noMutableList.kt");