Report about wrong number of type arguments instead of ambiguity

#KT-7975 Fixed
 #KT-1809 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2017-06-19 20:35:00 +03:00
parent 24f1bbfb46
commit 0f4497256b
5 changed files with 31 additions and 2 deletions
@@ -136,7 +136,7 @@ class CandidateResolver(
val substitutor = TypeSubstitutor.create(SubstitutionFilteringInternalResolveAnnotations(substitution))
if (expectedTypeArgumentCount != ktTypeArguments.size) {
candidateCall.addStatus(OTHER_ERROR)
candidateCall.addStatus(WRONG_NUMBER_OF_TYPE_ARGUMENTS_ERROR)
tracing.wrongNumberOfTypeArguments(trace, expectedTypeArgumentCount, candidateDescriptor)
}
else {
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@ import java.util.EnumSet;
public enum ResolutionStatus {
UNKNOWN_STATUS,
UNSAFE_CALL_ERROR,
WRONG_NUMBER_OF_TYPE_ARGUMENTS_ERROR,
OTHER_ERROR,
ARGUMENTS_MAPPING_ERROR,
// '1.foo()' shouldn't be resolved to 'fun String.foo()'
@@ -38,6 +39,7 @@ public enum ResolutionStatus {
@SuppressWarnings("unchecked")
public static final EnumSet<ResolutionStatus>[] SEVERITY_LEVELS = new EnumSet[] {
EnumSet.of(UNSAFE_CALL_ERROR), // weakest
EnumSet.of(WRONG_NUMBER_OF_TYPE_ARGUMENTS_ERROR),
EnumSet.of(OTHER_ERROR),
EnumSet.of(ARGUMENTS_MAPPING_ERROR),
EnumSet.of(RECEIVER_TYPE_ERROR),
@@ -0,0 +1,15 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER, -UNUSED_VARIABLE
fun myFun(i : String) {}
fun myFun(i : Int) {}
fun test1() {
myFun<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!><Int><!>(3)
<!NONE_APPLICABLE!>myFun<!><String>('a')
}
fun test2() {
val m0 = java.util.<!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>HashMap<!>()
val m1 = java.util.HashMap<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!><String, String, String><!>()
val m2 = java.util.HashMap<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!><String><!>()
}
@@ -0,0 +1,6 @@
package
public fun myFun(/*0*/ i: kotlin.Int): kotlin.Unit
public fun myFun(/*0*/ i: kotlin.String): kotlin.Unit
public fun test1(): kotlin.Unit
public fun test2(): kotlin.Unit
@@ -8692,6 +8692,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("wrongNumberOfTypeArgumentsDiagnostic.kt")
public void testWrongNumberOfTypeArgumentsDiagnostic() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/generics/wrongNumberOfTypeArgumentsDiagnostic.kt");
doTest(fileName);
}
@TestMetadata("compiler/testData/diagnostics/tests/generics/capturedParameters")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)