QuickFix: change property type to match it's initializer type
This commit is contained in:
@@ -50,6 +50,12 @@ public class QuickFixFactoryForTypeMismatchError implements JetIntentionActionsF
|
||||
actions.add(new CastExpressionFix(expression, expectedType));
|
||||
}
|
||||
|
||||
// Property initializer type mismatch property type:
|
||||
JetProperty property = PsiTreeUtil.getParentOfType(expression, JetProperty.class);
|
||||
if (property != null && QuickFixUtil.canEvaluateTo(property.getInitializer(), expression)) {
|
||||
actions.add(new ChangeVariableTypeFix(property, expressionType));
|
||||
}
|
||||
|
||||
// Mismatch in returned expression:
|
||||
JetFunction function = PsiTreeUtil.getParentOfType(expression, JetFunction.class, true);
|
||||
if (function != null && QuickFixUtil.canFunctionReturnExpression(function, expression)) {
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
// "Change 'f' type to '(Long) -> Unit'" "true"
|
||||
fun foo() {
|
||||
var f: (Long) -> Unit = if (true) { (x: Long) -> }<caret> else { (x: Long) -> }
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
// "Change 'f' type to '(Long) -> Unit'" "true"
|
||||
fun foo() {
|
||||
var f: Int = if (true) { (x: Long) -> }<caret> else { (x: Long) -> }
|
||||
}
|
||||
@@ -1286,6 +1286,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
||||
doTest("idea/testData/quickfix/typeMismatch/beforeNoReturnInFunctionWithBlockBody.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("beforePropertyTypeMismatch.kt")
|
||||
public void testPropertyTypeMismatch() throws Exception {
|
||||
doTest("idea/testData/quickfix/typeMismatch/beforePropertyTypeMismatch.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("beforeReturnTypeMismatch.kt")
|
||||
public void testReturnTypeMismatch() throws Exception {
|
||||
doTest("idea/testData/quickfix/typeMismatch/beforeReturnTypeMismatch.kt");
|
||||
|
||||
Reference in New Issue
Block a user