Make "type mismatch" quickfixes not available in case of error types
This commit is contained in:
@@ -22,6 +22,7 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiErrorElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -38,6 +39,7 @@ import org.jetbrains.jet.lang.resolve.DescriptorResolver;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
@@ -96,6 +98,11 @@ public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetFunction>
|
||||
return JetBundle.message("change.type.family");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull Project project, @Nullable Editor editor, @Nullable PsiFile file) {
|
||||
return super.isAvailable(project, editor, file) && !ErrorUtils.containsErrorType(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, @Nullable Editor editor, @Nullable JetFile file) throws IncorrectOperationException {
|
||||
if (changeFunctionLiteralReturnTypeFix != null) {
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -32,6 +33,7 @@ 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.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
@@ -45,10 +47,12 @@ import java.util.List;
|
||||
|
||||
public class ChangeVariableTypeFix extends JetIntentionAction<JetVariableDeclaration> {
|
||||
private final String renderedType;
|
||||
private final JetType type;
|
||||
|
||||
public ChangeVariableTypeFix(@NotNull JetVariableDeclaration element, @NotNull JetType type) {
|
||||
super(element);
|
||||
renderedType = DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(type);
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -67,6 +71,11 @@ public class ChangeVariableTypeFix extends JetIntentionAction<JetVariableDeclara
|
||||
return JetBundle.message("change.type.family");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
|
||||
return super.isAvailable(project, editor, file) && !ErrorUtils.containsErrorType(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, JetFile file) throws IncorrectOperationException {
|
||||
SpecifyTypeExplicitlyAction.removeTypeAnnotation(element);
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Change 'B.x' type to '(String) -> [ERROR : Ay]'" "false"
|
||||
// ACTION: Change 'A.x' type to '(Int) -> Int'
|
||||
// ERROR: <html>Return type is '(jet.Int) → jet.Int', which is not a subtype of overridden<br/><b>internal</b> <b>abstract</b> <b>val</b> x: (jet.String) → [ERROR : Ay] <i>defined in</i> A</html>
|
||||
// ERROR: Unresolved reference: Ay
|
||||
trait A {
|
||||
val x: (String) -> Ay
|
||||
}
|
||||
trait B : A {
|
||||
override val x: (Int) -> Int<caret>
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// "Change 'foo' function return type to '([ERROR : NoSuchType]) -> Int'" "false"
|
||||
// ERROR: <html>Type mismatch.<table><tr><td>Required:</td><td>jet.Int</td></tr><tr><td>Found:</td><td>([ERROR : NoSuchType]) → jet.Int</td></tr></table></html>
|
||||
// ERROR: Unresolved reference: NoSuchType
|
||||
fun foo(): Int {
|
||||
return { (x: NoSuchType<caret>) -> 42 }
|
||||
}
|
||||
@@ -1306,6 +1306,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
||||
doTest("idea/testData/quickfix/typeMismatch/beforeCompareToTypeMismatch.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("beforeDontChangeOverriddenPropertyTypeToErrorType.kt")
|
||||
public void testDontChangeOverriddenPropertyTypeToErrorType() throws Exception {
|
||||
doTest("idea/testData/quickfix/typeMismatch/beforeDontChangeOverriddenPropertyTypeToErrorType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("beforeExpectedParameterTypeMismatch.kt")
|
||||
public void testExpectedParameterTypeMismatch() throws Exception {
|
||||
doTest("idea/testData/quickfix/typeMismatch/beforeExpectedParameterTypeMismatch.kt");
|
||||
@@ -1514,6 +1519,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
||||
doTest("idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeChangeFunctionReturnTypeToMatchReturnTypeOfReturnedLiteral.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("beforeDontChangeFunctionReturnTypeToErrorType.kt")
|
||||
public void testDontChangeFunctionReturnTypeToErrorType() throws Exception {
|
||||
doTest("idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeDontChangeFunctionReturnTypeToErrorType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("beforeExpectedTypeMismatch.kt")
|
||||
public void testExpectedTypeMismatch() throws Exception {
|
||||
doTest("idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeExpectedTypeMismatch.kt");
|
||||
|
||||
Reference in New Issue
Block a user