Support "Change parameter type" for parameters with type-mismatched default value
#KT-15627 Fixed
This commit is contained in:
@@ -29,6 +29,7 @@ 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.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||
import org.jetbrains.kotlin.resolve.bindingContextUtil.getTargetFunction
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getParameterForArgument
|
||||
@@ -182,6 +183,12 @@ class QuickFixFactoryForTypeMismatchError : KotlinIntentionActionsFactory() {
|
||||
}
|
||||
}
|
||||
|
||||
diagnosticElement.getStrictParentOfType<KtParameter>()?.let {
|
||||
if (it.defaultValue == diagnosticElement) {
|
||||
actions.add(ChangeParameterTypeFix(it, expressionType))
|
||||
}
|
||||
}
|
||||
|
||||
val resolvedCall = diagnosticElement.getParentResolvedCall(context, true)
|
||||
if (resolvedCall != null) {
|
||||
// to fix 'type mismatch' on 'if' branches
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
// "Change parameter 's' type of function 'foo' to 'Int'" "true"
|
||||
val ONE = 1
|
||||
|
||||
fun foo(s: String = <caret>ONE + 1) {}
|
||||
@@ -0,0 +1,4 @@
|
||||
// "Change parameter 's' type of function 'foo' to 'Int'" "true"
|
||||
val ONE = 1
|
||||
|
||||
fun foo(s: Int = <caret>ONE + 1) {}
|
||||
@@ -9555,6 +9555,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("parameterDefaultValue.kt")
|
||||
public void testParameterDefaultValue() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/typeMismatch/parameterDefaultValue.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("propertyTypeMismatch.kt")
|
||||
public void testPropertyTypeMismatch() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/typeMismatch/propertyTypeMismatch.kt");
|
||||
|
||||
Reference in New Issue
Block a user