From 6fbf6b0a93800d2a57eab3a0ff592faf2856c224 Mon Sep 17 00:00:00 2001 From: Toshiaki Kameyama Date: Fri, 10 Aug 2018 05:40:00 +0300 Subject: [PATCH] "Let type implement interface": don't suggest same type #KT-25928 Fixed --- .../idea/quickfix/QuickFixFactoryForTypeMismatchError.kt | 5 ++++- idea/testData/quickfix/typeMismatch/kt25928.kt | 9 +++++++++ .../kotlin/idea/quickfix/QuickFixTestGenerated.java | 5 +++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 idea/testData/quickfix/typeMismatch/kt25928.kt diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixFactoryForTypeMismatchError.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixFactoryForTypeMismatchError.kt index e7e2cc8b02d..7f395cd2988 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixFactoryForTypeMismatchError.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixFactoryForTypeMismatchError.kt @@ -44,6 +44,7 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.KotlinTypeFactory +import org.jetbrains.kotlin.types.TypeUtils import org.jetbrains.kotlin.types.typeUtil.* import java.util.* @@ -120,7 +121,9 @@ class QuickFixFactoryForTypeMismatchError : KotlinIntentionActionsFactory() { val expressionTypeDeclaration = expressionType.constructor.declarationDescriptor?.let { DescriptorToSourceUtils.descriptorToDeclaration(it) } as? KtClassOrObject - expressionTypeDeclaration?.let { actions.add(LetImplementInterfaceFix(it, expectedType, expressionType)) } + if (expressionTypeDeclaration != null && expectedType != TypeUtils.makeNotNullable(expressionType)) { + actions.add(LetImplementInterfaceFix(expressionTypeDeclaration, expectedType, expressionType)) + } } diff --git a/idea/testData/quickfix/typeMismatch/kt25928.kt b/idea/testData/quickfix/typeMismatch/kt25928.kt new file mode 100644 index 00000000000..044711b11f6 --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/kt25928.kt @@ -0,0 +1,9 @@ +// "Let 'Foo?' extend interface 'Foo'" "false" +// ACTION: Add non-null asserted (!!) call +// ACTION: Change type of 'x' to 'Foo?' +// ERROR: Type mismatch: inferred type is Foo? but Foo was expected +interface Foo + +fun test(foo: Foo?) { + val x: Foo = foo +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java index ca01170999a..17909b639d2 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java @@ -11331,6 +11331,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { runTest("idea/testData/quickfix/typeMismatch/kt17404.kt"); } + @TestMetadata("kt25928.kt") + public void testKt25928() throws Exception { + runTest("idea/testData/quickfix/typeMismatch/kt25928.kt"); + } + @TestMetadata("letClassImplementAdditionalInterface.kt") public void testLetClassImplementAdditionalInterface() throws Exception { runTest("idea/testData/quickfix/typeMismatch/letClassImplementAdditionalInterface.kt");