Skip to content

Commit 0f44972

Browse files
committed
Report about wrong number of type arguments instead of ambiguity
#KT-7975 Fixed #KT-1809 Fixed
1 parent 24f1bbf commit 0f44972

File tree

5 files changed

+31
-2
lines changed

5 files changed

+31
-2
lines changed

compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CandidateResolver.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class CandidateResolver(
136136
val substitutor = TypeSubstitutor.create(SubstitutionFilteringInternalResolveAnnotations(substitution))
137137

138138
if (expectedTypeArgumentCount != ktTypeArguments.size) {
139-
candidateCall.addStatus(OTHER_ERROR)
139+
candidateCall.addStatus(WRONG_NUMBER_OF_TYPE_ARGUMENTS_ERROR)
140140
tracing.wrongNumberOfTypeArguments(trace, expectedTypeArgumentCount, candidateDescriptor)
141141
}
142142
else {

compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/results/ResolutionStatus.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2015 JetBrains s.r.o.
2+
* Copyright 2010-2017 JetBrains s.r.o.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@
2323
public enum ResolutionStatus {
2424
UNKNOWN_STATUS,
2525
UNSAFE_CALL_ERROR,
26+
WRONG_NUMBER_OF_TYPE_ARGUMENTS_ERROR,
2627
OTHER_ERROR,
2728
ARGUMENTS_MAPPING_ERROR,
2829
// '1.foo()' shouldn't be resolved to 'fun String.foo()'
@@ -38,6 +39,7 @@ public enum ResolutionStatus {
3839
@SuppressWarnings("unchecked")
3940
public static final EnumSet<ResolutionStatus>[] SEVERITY_LEVELS = new EnumSet[] {
4041
EnumSet.of(UNSAFE_CALL_ERROR), // weakest
42+
EnumSet.of(WRONG_NUMBER_OF_TYPE_ARGUMENTS_ERROR),
4143
EnumSet.of(OTHER_ERROR),
4244
EnumSet.of(ARGUMENTS_MAPPING_ERROR),
4345
EnumSet.of(RECEIVER_TYPE_ERROR),
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// !DIAGNOSTICS: -UNUSED_PARAMETER, -UNUSED_VARIABLE
2+
3+
fun myFun(i : String) {}
4+
fun myFun(i : Int) {}
5+
6+
fun test1() {
7+
myFun<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!><Int><!>(3)
8+
<!NONE_APPLICABLE!>myFun<!><String>('a')
9+
}
10+
11+
fun test2() {
12+
val m0 = java.util.<!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>HashMap<!>()
13+
val m1 = java.util.HashMap<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!><String, String, String><!>()
14+
val m2 = java.util.HashMap<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!><String><!>()
15+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package
2+
3+
public fun myFun(/*0*/ i: kotlin.Int): kotlin.Unit
4+
public fun myFun(/*0*/ i: kotlin.String): kotlin.Unit
5+
public fun test1(): kotlin.Unit
6+
public fun test2(): kotlin.Unit

compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8692,6 +8692,12 @@ public void testWildcardInValueParameter() throws Exception {
86928692
doTest(fileName);
86938693
}
86948694

8695+
@TestMetadata("wrongNumberOfTypeArgumentsDiagnostic.kt")
8696+
public void testWrongNumberOfTypeArgumentsDiagnostic() throws Exception {
8697+
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/generics/wrongNumberOfTypeArgumentsDiagnostic.kt");
8698+
doTest(fileName);
8699+
}
8700+
86958701
@TestMetadata("compiler/testData/diagnostics/tests/generics/capturedParameters")
86968702
@TestDataPath("$PROJECT_ROOT")
86978703
@RunWith(JUnit3RunnerWithInners.class)

0 commit comments

Comments
 (0)