Create from Usage: Infer expected type from base declarations

#KT-17480 Fixed
This commit is contained in:
Alexey Sedunov
2017-07-19 16:13:49 +03:00
parent 3b4891279e
commit 78117b3e7b
4 changed files with 35 additions and 1 deletions
@@ -222,7 +222,13 @@ fun KtExpression.guessTypes(
parent is KtNamedFunction && parent.name == null -> parent
else -> null
}
if (functionalExpression == null) return arrayOf()
if (functionalExpression == null) {
functionDescriptor.overriddenDescriptors
.mapNotNull { it.returnType }
.firstOrNull { isAcceptable(it) }
?.let { return arrayOf(it) }
return arrayOf()
}
val lambdaTypes = functionalExpression.guessTypes(context, module, pseudocode?.parent, coerceUnusedToUnit)
lambdaTypes.mapNotNull { it.getFunctionType()?.arguments?.lastOrNull()?.type }.toTypedArray()
}
@@ -0,0 +1,9 @@
// "Create class 'XImpl'" "true"
interface X
interface A {
fun f(): X
}
class B : A {
override fun f() = <caret>XImpl()
}
@@ -0,0 +1,13 @@
// "Create class 'XImpl'" "true"
interface X
interface A {
fun f(): X
}
class B : A {
override fun f() = XImpl()
}
class XImpl : X {
}
@@ -1647,6 +1647,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
doTest(fileName);
}
@TestMetadata("expectedTypeBySuperFunction.kt")
public void testExpectedTypeBySuperFunction() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/expectedTypeBySuperFunction.kt");
doTest(fileName);
}
@TestMetadata("quotedName.kt")
public void testQuotedName() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/quotedName.kt");