"Let type implement interface": don't suggest same type #KT-25928 Fixed

This commit is contained in:
Toshiaki Kameyama
2018-08-10 05:40:00 +03:00
committed by Mikhail Glukhikh
parent 2d2f1125a9
commit 6fbf6b0a93
3 changed files with 18 additions and 1 deletions
@@ -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))
}
}
+9
View File
@@ -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<caret>
}
@@ -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");