"Add type" quick fix incorrectly processes vararg modifier with primitive type array initializer #KT-21544 Fixed
This commit is contained in:
committed by
Dmitry Jemerov
parent
846e50dcaa
commit
4563cf250d
@@ -41,9 +41,12 @@ class AddTypeAnnotationToValueParameterFix(element: KtParameter) : KotlinQuickFi
|
||||
init {
|
||||
val defaultValue = element.defaultValue
|
||||
var type = defaultValue?.getType(defaultValue.analyze(BodyResolveMode.PARTIAL))
|
||||
if (type != null && KotlinBuiltIns.isArray(type)) {
|
||||
if (type != null && KotlinBuiltIns.isArrayOrPrimitiveArray(type)) {
|
||||
if (element.hasModifier(KtTokens.VARARG_KEYWORD)) {
|
||||
type = type.arguments.singleOrNull()?.type
|
||||
type = if (KotlinBuiltIns.isPrimitiveArray(type))
|
||||
element.builtIns.getArrayElementType(type)
|
||||
else
|
||||
type.arguments.singleOrNull()?.type
|
||||
}
|
||||
else if (defaultValue is KtCollectionLiteralExpression) {
|
||||
val builtIns = element.builtIns
|
||||
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
// "Add type 'Double' to parameter 'value'" "true"
|
||||
|
||||
class CollectionDefault(vararg val value = doubleArrayOf(1.0, 2.2)<caret>)
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
// "Add type 'Double' to parameter 'value'" "true"
|
||||
|
||||
class CollectionDefault(vararg val value: Double = doubleArrayOf(1.0, 2.2))
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
// "Add type 'Int' to parameter 'value'" "true"
|
||||
|
||||
class CollectionDefault(vararg val value = intArrayOf(1, 2)<caret>)
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
// "Add type 'Int' to parameter 'value'" "true"
|
||||
|
||||
class CollectionDefault(vararg val value: Int = intArrayOf(1, 2))
|
||||
@@ -1043,6 +1043,18 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("annotationWithVarargDoubleArray.kt")
|
||||
public void testAnnotationWithVarargDoubleArray() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/addTypeAnnotationToValueParameter/annotationWithVarargDoubleArray.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("annotationWithVarargIntArray.kt")
|
||||
public void testAnnotationWithVarargIntArray() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/addTypeAnnotationToValueParameter/annotationWithVarargIntArray.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("noDefaultValue.kt")
|
||||
public void testNoDefaultValue() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/addTypeAnnotationToValueParameter/noDefaultValue.kt");
|
||||
|
||||
Reference in New Issue
Block a user