diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixFactoryForTypeMismatchError.java b/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixFactoryForTypeMismatchError.java index 623e0c49c2e..617ee4ef412 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixFactoryForTypeMismatchError.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixFactoryForTypeMismatchError.java @@ -26,7 +26,6 @@ import org.jetbrains.jet.lang.diagnostics.DiagnosticWithParameters2; import org.jetbrains.jet.lang.diagnostics.Errors; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.BindingContext; -import org.jetbrains.jet.lang.resolve.BindingContextUtils; import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall; import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage; @@ -34,6 +33,7 @@ import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage; import java.util.LinkedList; import java.util.List; +//TODO: should use change signature to deal with cases of multiple overridden descriptors public class QuickFixFactoryForTypeMismatchError implements JetIntentionActionsFactory { @NotNull @Override @@ -132,14 +132,9 @@ public class QuickFixFactoryForTypeMismatchError implements JetIntentionActionsF @Nullable private static JetFunction getFunctionDeclaration(@NotNull BindingContext context, @NotNull ResolvedCall resolvedCall) { - List declarations = BindingContextUtils.descriptorToDeclarations(context, resolvedCall.getResultingDescriptor()); - //do not create fix if descriptor has more than one overridden declarations - //TODO: use change signature to deal with this case correctly - if (declarations.size() == 1) { - PsiElement result = declarations.iterator().next(); - if (result instanceof JetFunction) { - return (JetFunction) result; - } + PsiElement result = QuickFixUtil.safeGetDeclaration(context, resolvedCall); + if (result instanceof JetFunction) { + return (JetFunction) result; } return null; } diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixUtil.java b/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixUtil.java index 5d8052847ad..b807f17be18 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixUtil.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixUtil.java @@ -109,7 +109,7 @@ public class QuickFixUtil { BindingContext context = ResolvePackage.getBindingContext(callExpression.getContainingJetFile()); ResolvedCall resolvedCall = context.get(BindingContext.RESOLVED_CALL, callExpression.getCalleeExpression()); if (resolvedCall == null) return null; - PsiElement declaration = BindingContextUtils.descriptorToDeclaration(context, resolvedCall.getCandidateDescriptor()); + PsiElement declaration = safeGetDeclaration(context, resolvedCall); if (declaration instanceof JetFunction) { return ((JetFunction) declaration).getValueParameterList(); } @@ -119,6 +119,16 @@ public class QuickFixUtil { return null; } + @Nullable + public static PsiElement safeGetDeclaration(@NotNull BindingContext context, @NotNull ResolvedCall resolvedCall) { + List declarations = BindingContextUtils.descriptorToDeclarations(context, resolvedCall.getResultingDescriptor()); + //do not create fix if descriptor has more than one overridden declaration + if (declarations.size() == 1) { + return declarations.iterator().next(); + } + return null; + } + @Nullable public static JetParameter getParameterCorrespondingToFunctionLiteralPassedOutsideArgumentList(@NotNull JetFunctionLiteralExpression functionLiteralExpression) { if (!(functionLiteralExpression.getParent() instanceof JetCallExpression)) { diff --git a/idea/testData/quickfix/typeMismatch/parameterTypeMismatch/beforeMultiFakeOverride.kt b/idea/testData/quickfix/typeMismatch/parameterTypeMismatch/beforeMultiFakeOverride.kt new file mode 100644 index 00000000000..9d033b6e447 --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/parameterTypeMismatch/beforeMultiFakeOverride.kt @@ -0,0 +1,13 @@ +// "class org.jetbrains.jet.plugin.quickfix.ChangeParameterTypeFix" "false" +// ERROR: Type mismatch.
Required:kotlin.Int
Found:kotlin.String
+trait A { + fun f(i: Int): Boolean +} + +open class AA { + fun f(i: Int) = true +} + +class AAA: AA(), A + +val c = AAA().f("") \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/plugin/quickfix/QuickFixTestGenerated.java b/idea/tests/org/jetbrains/jet/plugin/quickfix/QuickFixTestGenerated.java index 657e6dffeb0..63155eca981 100644 --- a/idea/tests/org/jetbrains/jet/plugin/quickfix/QuickFixTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/plugin/quickfix/QuickFixTestGenerated.java @@ -2263,6 +2263,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { doTest("idea/testData/quickfix/typeMismatch/parameterTypeMismatch/beforeChangePrimaryConstructorParameterType.kt"); } + @TestMetadata("beforeMultiFakeOverride.kt") + public void testMultiFakeOverride() throws Exception { + doTest("idea/testData/quickfix/typeMismatch/parameterTypeMismatch/beforeMultiFakeOverride.kt"); + } + } @TestMetadata("idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression")