From 3fd265e34a01d5d9c1c6488a714796c939304004 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Sat, 3 Aug 2013 11:43:25 +0400 Subject: [PATCH] Remove assert about error type for removing type annotation --- .../jet/plugin/intentions/SpecifyTypeExplicitlyAction.java | 4 +++- .../intentions/specifyType/afterRemoveUnresolvedType.kt | 4 ++++ .../intentions/specifyType/beforeRemoveUnresolvedType.kt | 4 ++++ .../jet/plugin/intentions/SpecifyTypeExplicitlyTest.java | 4 ++++ 4 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 idea/testData/intentions/specifyType/afterRemoveUnresolvedType.kt create mode 100644 idea/testData/intentions/specifyType/beforeRemoveUnresolvedType.kt diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/SpecifyTypeExplicitlyAction.java b/idea/src/org/jetbrains/jet/plugin/intentions/SpecifyTypeExplicitlyAction.java index 1010fbcd1bf..dd3783ad95a 100644 --- a/idea/src/org/jetbrains/jet/plugin/intentions/SpecifyTypeExplicitlyAction.java +++ b/idea/src/org/jetbrains/jet/plugin/intentions/SpecifyTypeExplicitlyAction.java @@ -69,7 +69,6 @@ public class SpecifyTypeExplicitlyAction extends PsiElementBaseIntentionAction { } PsiElement parent = element.getParent(); JetType type = getTypeForDeclaration((JetNamedDeclaration) parent); - assert !ErrorUtils.isErrorType(type) : "Unexpected error type: " + element.getText(); if (parent instanceof JetProperty) { JetProperty property = (JetProperty) parent; if (property.getTypeRef() == null) { @@ -109,6 +108,7 @@ public class SpecifyTypeExplicitlyAction extends PsiElementBaseIntentionAction { return false; } JetNamedDeclaration declaration = (JetNamedDeclaration) parent; + if (declaration instanceof JetProperty && !PsiTreeUtil.isAncestor(((JetProperty) declaration).getInitializer(), element, false)) { if (((JetProperty) declaration).getTypeRef() != null) { setText(JetBundle.message("specify.type.explicitly.remove.action.name")); @@ -217,6 +217,8 @@ public class SpecifyTypeExplicitlyAction extends PsiElementBaseIntentionAction { @NotNull PsiElement anchor, @NotNull JetType exprType ) { + assert !ErrorUtils.isErrorType(exprType) : "Unexpected error type: " + namedDeclaration.getText(); + TypeConstructor constructor = exprType.getConstructor(); boolean isAnonymous = DescriptorUtils.isAnonymous(constructor.getDeclarationDescriptor()); diff --git a/idea/testData/intentions/specifyType/afterRemoveUnresolvedType.kt b/idea/testData/intentions/specifyType/afterRemoveUnresolvedType.kt new file mode 100644 index 00000000000..5e39d29ac69 --- /dev/null +++ b/idea/testData/intentions/specifyType/afterRemoveUnresolvedType.kt @@ -0,0 +1,4 @@ +// "Remove explicitly specified type" "true" +package testing + +val a = 12 \ No newline at end of file diff --git a/idea/testData/intentions/specifyType/beforeRemoveUnresolvedType.kt b/idea/testData/intentions/specifyType/beforeRemoveUnresolvedType.kt new file mode 100644 index 00000000000..c46cbc7b442 --- /dev/null +++ b/idea/testData/intentions/specifyType/beforeRemoveUnresolvedType.kt @@ -0,0 +1,4 @@ +// "Remove explicitly specified type" "true" +package testing + +val a: Bad = 12 \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/plugin/intentions/SpecifyTypeExplicitlyTest.java b/idea/tests/org/jetbrains/jet/plugin/intentions/SpecifyTypeExplicitlyTest.java index 4116d50717f..a411b1f992e 100644 --- a/idea/tests/org/jetbrains/jet/plugin/intentions/SpecifyTypeExplicitlyTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/intentions/SpecifyTypeExplicitlyTest.java @@ -61,6 +61,10 @@ public class SpecifyTypeExplicitlyTest extends LightIntentionActionTestCase { doTest(); } + public void testRemoveUnresolvedType() { + doTest(); + } + @Override protected String getTestDataPath() { return PluginTestCaseBase.getTestDataPathBase() + "/intentions/";