Fixed the call completer

to update the type of the argument expression correctly
This commit is contained in:
Svetlana Isakova
2015-10-21 14:42:39 +03:00
parent 06e90cf6a1
commit 9877fe1a26
4 changed files with 30 additions and 4 deletions
@@ -149,7 +149,7 @@ public class ArgumentTypeResolver {
private void checkArgumentTypeWithNoCallee(CallResolutionContext<?> context, KtExpression argumentExpression) {
expressionTypingServices.getTypeInfo(argumentExpression, context.replaceExpectedType(NO_EXPECTED_TYPE));
updateResultArgumentTypeIfNotDenotable(context, argumentExpression);
updateResultArgumentTypeIfNotDenotable(context, argumentExpression, null);
}
public static boolean isFunctionLiteralArgument(
@@ -349,9 +349,10 @@ public class ArgumentTypeResolver {
@Nullable
public KotlinType updateResultArgumentTypeIfNotDenotable(
@NotNull ResolutionContext context,
@NotNull KtExpression expression
@NotNull KtExpression expression,
@Nullable KotlinType argumentType
) {
KotlinType type = context.trace.getType(expression);
KotlinType type = (argumentType != null) ? argumentType : context.trace.getType(expression);
if (type != null && !type.getConstructor().isDenotable()) {
if (type.getConstructor() instanceof IntegerValueTypeConstructor) {
IntegerValueTypeConstructor constructor = (IntegerValueTypeConstructor) type.getConstructor();
@@ -251,7 +251,7 @@ public class CallCompleter(
// For the cases like 'foo(1)' the type of '1' depends on expected type (it can be Int, Byte, etc.),
// so while the expected type is not known, it's IntegerValueType(1), and should be updated when the expected type is known.
if (recordedType != null && !recordedType.getConstructor().isDenotable()) {
updatedType = argumentTypeResolver.updateResultArgumentTypeIfNotDenotable(context, expression)
updatedType = argumentTypeResolver.updateResultArgumentTypeIfNotDenotable(context, expression, updatedType)
}
updatedType = updateRecordedTypeForArgument(updatedType, recordedType, expression, context.trace)
@@ -0,0 +1,19 @@
interface PsiElement {
fun <T: PsiElement> findChildByType(i: Int): T? =
if (i == 42) JetOperationReferenceExpression() as T else throw Exception()
}
interface JetSimpleNameExpression : PsiElement {
fun getReferencedNameElement(): PsiElement
}
class JetOperationReferenceExpression : JetSimpleNameExpression {
override fun getReferencedNameElement() = this
}
class JetLabelReferenceExpression : JetSimpleNameExpression {
public override fun getReferencedNameElement(): PsiElement =
findChildByType(42) ?: this
}
fun box(): String {
val element = JetLabelReferenceExpression().getReferencedNameElement()
return if (element is JetOperationReferenceExpression) "OK" else "fail"
}
@@ -3367,6 +3367,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
doTest(fileName);
}
@TestMetadata("kt6694ExactAnnotationForElvis.kt")
public void testKt6694ExactAnnotationForElvis() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/elvis/kt6694ExactAnnotationForElvis.kt");
doTest(fileName);
}
@TestMetadata("primitive.kt")
public void testPrimitive() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/elvis/primitive.kt");