Quick-Fixes: Fix type checking scope for type mismatch in call argument
This commit is contained in:
@@ -42,7 +42,7 @@ public class ChangeParameterTypeFix extends JetIntentionAction<JetParameter> {
|
||||
JetNamedDeclaration declaration = PsiTreeUtil.getParentOfType(element, JetNamedDeclaration.class);
|
||||
isPrimaryConstructorParameter = declaration instanceof JetClass;
|
||||
FqName declarationFQName = declaration == null ? null : declaration.getFqName();
|
||||
containingDeclarationName = declarationFQName == null ? null : declarationFQName.asString();
|
||||
containingDeclarationName = declarationFQName == null ? declaration.getName() : declarationFQName.asString();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-1
@@ -156,7 +156,8 @@ public class QuickFixFactoryForTypeMismatchError extends JetIntentionActionsFact
|
||||
? expressionType
|
||||
: context.get(BindingContext.EXPRESSION_TYPE, valueArgument.getArgumentExpression());
|
||||
if (correspondingParameter != null && valueArgumentType != null) {
|
||||
JetScope scope = JetScopeUtils.getResolutionScope(valueArgument.getArgumentExpression(), context);
|
||||
JetCallableDeclaration callable = PsiTreeUtil.getParentOfType(correspondingParameter, JetCallableDeclaration.class, true);
|
||||
JetScope scope = callable != null ? JetScopeUtils.getResolutionScope(callable, context) : null;
|
||||
JetType typeToInsert = UtilPackage.approximateWithResolvableType(valueArgumentType, scope, true);
|
||||
actions.add(new ChangeParameterTypeFix(correspondingParameter, typeToInsert));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Change parameter 'n' type of function 'foo' to 'T'" "true"
|
||||
fun bar<T>(t: T) {
|
||||
fun foo(n: T) {
|
||||
|
||||
}
|
||||
|
||||
foo(t)
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Change parameter 'n' type of function 'foo' to 'Any?'" "true"
|
||||
fun foo(n: Any?) {
|
||||
|
||||
}
|
||||
|
||||
fun bar<T>(t: T) {
|
||||
foo(t)
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Change parameter 'n' type of function 'foo' to 'T'" "true"
|
||||
fun bar<T>(t: T) {
|
||||
fun foo(n: Int) {
|
||||
|
||||
}
|
||||
|
||||
foo(<caret>t)
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Change parameter 'n' type of function 'foo' to 'Any?'" "true"
|
||||
fun foo(n: Int) {
|
||||
|
||||
}
|
||||
|
||||
fun bar<T>(t: T) {
|
||||
foo(<caret>t)
|
||||
}
|
||||
@@ -4912,6 +4912,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("beforeResolvableTypeParams.kt")
|
||||
public void testResolvableTypeParams() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/typeMismatch/beforeResolvableTypeParams.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("beforeReturnTypeMismatch.kt")
|
||||
public void testReturnTypeMismatch() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/typeMismatch/beforeReturnTypeMismatch.kt");
|
||||
@@ -4924,6 +4930,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("beforeUnresolvableTypeParams.kt")
|
||||
public void testUnresolvableTypeParams() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/typeMismatch/beforeUnresolvableTypeParams.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/quickfix/typeMismatch/casts")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
Reference in New Issue
Block a user