Support "Change parameter type" for parameters with type-mismatched default value
#KT-15627 Fixed
This commit is contained in:
@@ -721,6 +721,7 @@ These artifacts include extensions for the types available in the latter JDKs, s
|
||||
- Implement quickfix which enables/disables coroutine support in module or project
|
||||
- [`KT-15056`](https://youtrack.jetbrains.com/issue/KT-15056) Implement intention which converts object literal to class
|
||||
- [`KT-8855`](https://youtrack.jetbrains.com/issue/KT-8855) Implement "Create label" quick fix
|
||||
- [`KT-15627`](https://youtrack.jetbrains.com/issue/KT-15627) Support "Change parameter type" for parameters with type-mismatched default value
|
||||
|
||||
## 1.0.6
|
||||
|
||||
|
||||
@@ -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