Fix failing assertion in ChangeFunctionTypeFix

This commit is contained in:
Wojciech Lopata
2013-04-17 09:22:33 +02:00
parent 1d08bf7895
commit 0543b73099
6 changed files with 27 additions and 4 deletions
@@ -164,7 +164,7 @@ public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetFunction>
@Override
public IntentionAction createAction(Diagnostic diagnostic) {
JetFunction function = QuickFixUtil.getParentElementOfType(diagnostic, JetFunction.class);
assert function != null : "RETURN_TYPE_MISMATCH_ON_OVERRIDE reported on element that is not within any function";
if (function == null) return null;
BindingContext context = KotlinCacheManagerUtil.getDeclarationsBindingContext(function);
JetType matchingReturnType = QuickFixUtil.findLowerBoundOfOverriddenCallablesReturnTypes(context, function);
return matchingReturnType == null ? null : new ChangeFunctionReturnTypeFix(function, matchingReturnType);
@@ -85,13 +85,13 @@ public class ChangeVariableTypeFix extends JetIntentionAction<JetVariableDeclara
}
@NotNull
public static JetIntentionActionFactory createFactoryForPropertyTypeMismatchOnOverride() {
public static JetIntentionActionFactory createFactoryForPropertyOrReturnTypeMismatchOnOverride() {
return new JetIntentionActionFactory() {
@Nullable
@Override
public IntentionAction createAction(Diagnostic diagnostic) {
JetProperty property = QuickFixUtil.getParentElementOfType(diagnostic, JetProperty.class);
assert property != null : "PROPERTY_TYPE_MISMATCH_ON_OVERRIDE reported on element that is not within any property";
if (property == null) return null;
BindingContext context = KotlinCacheManagerUtil.getDeclarationsBindingContext(property);
JetType type = QuickFixUtil.findLowerBoundOfOverriddenCallablesReturnTypes(context, property);
return type == null ? null : new ChangeVariableTypeFix(property, type);
@@ -210,7 +210,9 @@ public class QuickFixes {
factories.put(DANGLING_FUNCTION_LITERAL_ARGUMENT_SUSPECTED, AddSemicolonAfterFunctionCallFix.createFactory());
factories.put(PROPERTY_TYPE_MISMATCH_ON_OVERRIDE, ChangeVariableTypeFix.createFactoryForPropertyTypeMismatchOnOverride());
JetIntentionActionFactory changeVariableTypeFix = ChangeVariableTypeFix.createFactoryForPropertyOrReturnTypeMismatchOnOverride();
factories.put(RETURN_TYPE_MISMATCH_ON_OVERRIDE, changeVariableTypeFix);
factories.put(PROPERTY_TYPE_MISMATCH_ON_OVERRIDE, changeVariableTypeFix);
factories.put(COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH, ChangeVariableTypeFix.createFactoryForComponentFunctionReturnTypeMismatch());
factories.put(RETURN_TYPE_MISMATCH_ON_OVERRIDE, ChangeFunctionReturnTypeFix.createFactoryForReturnTypeMismatchOnOverride());
@@ -0,0 +1,8 @@
// "Change 'x' type to 'Int'" "true"
trait X {
val x: Int
}
class A : X {
override val x: Int = 42
}
@@ -0,0 +1,8 @@
// "Change 'x' type to 'Int'" "true"
trait X {
val x: Int
}
class A : X {
override val x: Number<caret> = 42
}
@@ -782,6 +782,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/quickfix/override/typeMismatchOnOverride"), Pattern.compile("^before(\\w+)\\.kt$"), true);
}
@TestMetadata("beforePropertyReturnTypeMismatchOnOverride.kt")
public void testPropertyReturnTypeMismatchOnOverride() throws Exception {
doTest("idea/testData/quickfix/override/typeMismatchOnOverride/beforePropertyReturnTypeMismatchOnOverride.kt");
}
@TestMetadata("beforePropertyTypeMismatchOnOverrideIntLong.kt")
public void testPropertyTypeMismatchOnOverrideIntLong() throws Exception {
doTest("idea/testData/quickfix/override/typeMismatchOnOverride/beforePropertyTypeMismatchOnOverrideIntLong.kt");