diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyInitializerToGetterIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyInitializerToGetterIntention.kt index c1653429ccd..2b6c829aaf2 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyInitializerToGetterIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyInitializerToGetterIntention.kt @@ -26,6 +26,7 @@ import org.jetbrains.kotlin.psi.KtDeclaration import org.jetbrains.kotlin.psi.KtProperty import org.jetbrains.kotlin.psi.KtPsiFactory import org.jetbrains.kotlin.psi.psiUtil.isExtensionDeclaration +import org.jetbrains.kotlin.types.isError class ConvertPropertyInitializerToGetterIntention : SelfTargetingRangeIntention(KtProperty::class.java, "Convert property initializer to getter") { @@ -53,7 +54,9 @@ class ConvertPropertyInitializerToGetterIntention : SelfTargetingRangeIntention< fun convertPropertyInitializerToGetter(property: KtProperty, editor: Editor?) { val type = SpecifyTypeExplicitlyIntention.getTypeForDeclaration(property) - SpecifyTypeExplicitlyIntention.addTypeAnnotation(editor, property, type) + if (!type.isError) { + SpecifyTypeExplicitlyIntention.addTypeAnnotation(editor, property, type) + } val initializer = property.initializer!! val getter = KtPsiFactory(property).createPropertyGetter(initializer) diff --git a/idea/testData/intentions/convertPropertyInitializerToGetter/errorType.kt b/idea/testData/intentions/convertPropertyInitializerToGetter/errorType.kt new file mode 100644 index 00000000000..3e5a3da6aa7 --- /dev/null +++ b/idea/testData/intentions/convertPropertyInitializerToGetter/errorType.kt @@ -0,0 +1,8 @@ +// SKIP_ERRORS_BEFORE +// SKIP_ERRORS_AFTER + +class Some + +class Other { + val x = Some +} \ No newline at end of file diff --git a/idea/testData/intentions/convertPropertyInitializerToGetter/errorType.kt.after b/idea/testData/intentions/convertPropertyInitializerToGetter/errorType.kt.after new file mode 100644 index 00000000000..a9e5b8a158b --- /dev/null +++ b/idea/testData/intentions/convertPropertyInitializerToGetter/errorType.kt.after @@ -0,0 +1,9 @@ +// SKIP_ERRORS_BEFORE +// SKIP_ERRORS_AFTER + +class Some + +class Other { + val x + get() = Some +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java index 8db25439860..fc68bb4602d 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -5651,6 +5651,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/intentions/convertPropertyInitializerToGetter"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), TargetBackend.ANY, true); } + @TestMetadata("errorType.kt") + public void testErrorType() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertPropertyInitializerToGetter/errorType.kt"); + doTest(fileName); + } + @TestMetadata("inapplicableIfExtensionProperty.kt") public void testInapplicableIfExtensionProperty() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertPropertyInitializerToGetter/inapplicableIfExtensionProperty.kt");