Fix for EA-81477 : correct handling of a property without initializer (but with e.g. getter)
(cherry picked from commit 4e2d35a)
This commit is contained in:
committed by
Mikhail Glukhikh
parent
5b328e9042
commit
b44c94a887
@@ -64,7 +64,9 @@ class ChangeFunctionLiteralReturnTypeFix(
|
|||||||
val eventualFunctionLiteralType = TypeUtils.substituteParameters(functionClass, functionClassTypeParameters)
|
val eventualFunctionLiteralType = TypeUtils.substituteParameters(functionClass, functionClassTypeParameters)
|
||||||
|
|
||||||
val correspondingProperty = PsiTreeUtil.getParentOfType(functionLiteralExpression, KtProperty::class.java)
|
val correspondingProperty = PsiTreeUtil.getParentOfType(functionLiteralExpression, KtProperty::class.java)
|
||||||
if (correspondingProperty != null && QuickFixUtil.canEvaluateTo(correspondingProperty.initializer!!, functionLiteralExpression)) {
|
if (correspondingProperty != null &&
|
||||||
|
correspondingProperty.initializer?.let { QuickFixUtil.canEvaluateTo(it, functionLiteralExpression) } ?: true
|
||||||
|
) {
|
||||||
val correspondingPropertyTypeRef = correspondingProperty.typeReference
|
val correspondingPropertyTypeRef = correspondingProperty.typeReference
|
||||||
val propertyType = context.get(BindingContext.TYPE, correspondingPropertyTypeRef)
|
val propertyType = context.get(BindingContext.TYPE, correspondingPropertyTypeRef)
|
||||||
return if (propertyType != null && !KotlinTypeChecker.DEFAULT.isSubtypeOf(eventualFunctionLiteralType, propertyType))
|
return if (propertyType != null && !KotlinTypeChecker.DEFAULT.isSubtypeOf(eventualFunctionLiteralType, propertyType))
|
||||||
|
|||||||
Vendored
+4
@@ -0,0 +1,4 @@
|
|||||||
|
// "Change 'complex' type to '(Int) -> Long'" "true"
|
||||||
|
|
||||||
|
val complex: (Int) -> String
|
||||||
|
get() = { it.toLong()<caret> }
|
||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
// "Change 'complex' type to '(Int) -> Long'" "true"
|
||||||
|
|
||||||
|
val complex: (Int) -> Long
|
||||||
|
get() = { it.toLong() }
|
||||||
@@ -8370,6 +8370,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("literalPropertyWithGetter.kt")
|
||||||
|
public void testLiteralPropertyWithGetter() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/literalPropertyWithGetter.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("multiFakeOverride.kt")
|
@TestMetadata("multiFakeOverride.kt")
|
||||||
public void testMultiFakeOverride() throws Exception {
|
public void testMultiFakeOverride() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/multiFakeOverride.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/multiFakeOverride.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user