QuickFix: change function return type to match expexted type of call
This commit is contained in:
@@ -91,6 +91,18 @@ public class QuickFixFactoryForTypeMismatchError implements JetIntentionActionsF
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Change function return type when TYPE_MISMATCH is reported on call expression:
|
||||||
|
if (expression instanceof JetCallExpression) {
|
||||||
|
ResolvedCall<? extends CallableDescriptor> resolvedCall =
|
||||||
|
context.get(BindingContext.RESOLVED_CALL, ((JetCallExpression) expression).getCalleeExpression());
|
||||||
|
if (resolvedCall != null) {
|
||||||
|
PsiElement declaration = BindingContextUtils.descriptorToDeclaration(context, resolvedCall.getResultingDescriptor());
|
||||||
|
if (declaration instanceof JetFunction) {
|
||||||
|
actions.add(new ChangeFunctionReturnTypeFix((JetFunction) declaration, expectedType));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Change type of a function parameter in case TYPE_MISMATCH is reported on expression passed as value argument of call.
|
// Change type of a function parameter in case TYPE_MISMATCH is reported on expression passed as value argument of call.
|
||||||
// 1) When an argument is a dangling function literal:
|
// 1) When an argument is a dangling function literal:
|
||||||
JetFunctionLiteralExpression functionLiteralExpression =
|
JetFunctionLiteralExpression functionLiteralExpression =
|
||||||
|
|||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
// "Change 'bar' function return type to 'String'" "true"
|
||||||
|
fun bar(): String = ""
|
||||||
|
fun foo(): String = bar(<caret>)
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
// "Change 'bar' function return type to 'String'" "true"
|
||||||
|
fun bar(): Any = ""
|
||||||
|
fun foo(): String = bar(<caret>)
|
||||||
@@ -1251,6 +1251,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
|||||||
doTest("idea/testData/quickfix/typeMismatch/beforeChangeFunctionLiteralParameterTypeToFunctionType.kt");
|
doTest("idea/testData/quickfix/typeMismatch/beforeChangeFunctionLiteralParameterTypeToFunctionType.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("beforeChangeFunctionReturnTypeToMatchExpectedTypeOfCall.kt")
|
||||||
|
public void testChangeFunctionReturnTypeToMatchExpectedTypeOfCall() throws Exception {
|
||||||
|
doTest("idea/testData/quickfix/typeMismatch/beforeChangeFunctionReturnTypeToMatchExpectedTypeOfCall.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("beforeChangeReturnTypeWhenFunctionNameIsMissing.kt")
|
@TestMetadata("beforeChangeReturnTypeWhenFunctionNameIsMissing.kt")
|
||||||
public void testChangeReturnTypeWhenFunctionNameIsMissing() throws Exception {
|
public void testChangeReturnTypeWhenFunctionNameIsMissing() throws Exception {
|
||||||
doTest("idea/testData/quickfix/typeMismatch/beforeChangeReturnTypeWhenFunctionNameIsMissing.kt");
|
doTest("idea/testData/quickfix/typeMismatch/beforeChangeReturnTypeWhenFunctionNameIsMissing.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user