diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CandidateResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CandidateResolver.kt index 93ae3fadb1b..557cf6a2a17 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CandidateResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CandidateResolver.kt @@ -160,7 +160,7 @@ public class CandidateResolver( val argumentMappingStatus = ValueArgumentsToParametersMapper.mapValueArgumentsToParameters( call, tracing, candidateCall, Sets.newLinkedHashSet()) if (!argumentMappingStatus.isSuccess()) { - candidateCall.addStatus(OTHER_ERROR) + candidateCall.addStatus(ARGUMENTS_MAPPING_ERROR) } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/results/ResolutionResultsHandler.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/results/ResolutionResultsHandler.java index 1e446fc8a30..06414a2dcb9 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/results/ResolutionResultsHandler.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/results/ResolutionResultsHandler.java @@ -136,33 +136,36 @@ public class ResolutionResultsHandler { } } if (!thisLevel.isEmpty()) { - OverloadResolutionResultsImpl results = chooseAndReportMaximallySpecific(thisLevel, false); - if (results.isSingleResult()) { - results.getResultingCall().getTrace().moveAllMyDataTo(task.trace); - return OverloadResolutionResultsImpl.singleFailedCandidate(results.getResultingCall()); + if (severityLevel.contains(ARGUMENTS_MAPPING_ERROR)) { + return recordFailedInfo(task, thisLevel); } - - task.tracing.noneApplicable(task.trace, results.getResultingCalls()); - task.tracing.recordAmbiguity(task.trace, results.getResultingCalls()); - return OverloadResolutionResultsImpl.manyFailedCandidates(results.getResultingCalls()); + OverloadResolutionResultsImpl results = chooseAndReportMaximallySpecific(thisLevel, false); + return recordFailedInfo(task, results.getResultingCalls()); } } assert false : "Should not be reachable, cause every status must belong to some level"; Set> noOverrides = OverrideResolver.filterOutOverridden(failedCandidates, MAP_TO_CANDIDATE); - if (noOverrides.size() != 1) { - task.tracing.noneApplicable(task.trace, noOverrides); - task.tracing.recordAmbiguity(task.trace, noOverrides); - return OverloadResolutionResultsImpl.manyFailedCandidates(noOverrides); - } - - failedCandidates = noOverrides; + return recordFailedInfo(task, noOverrides); } - MutableResolvedCall failed = failedCandidates.iterator().next(); - failed.getTrace().moveAllMyDataTo(task.trace); - return OverloadResolutionResultsImpl.singleFailedCandidate(failed); + return recordFailedInfo(task, failedCandidates); + } + + @NotNull + private static OverloadResolutionResultsImpl recordFailedInfo( + @NotNull ResolutionTask task, + @NotNull Collection> candidates + ) { + if (candidates.size() == 1) { + MutableResolvedCall failed = candidates.iterator().next(); + failed.getTrace().moveAllMyDataTo(task.trace); + return OverloadResolutionResultsImpl.singleFailedCandidate(failed); + } + task.tracing.noneApplicable(task.trace, candidates); + task.tracing.recordAmbiguity(task.trace, candidates); + return OverloadResolutionResultsImpl.manyFailedCandidates(candidates); } private static boolean allIncomplete(@NotNull Collection> results) { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/results/ResolutionStatus.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/results/ResolutionStatus.java index 389f754689a..b4c5ec3b981 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/results/ResolutionStatus.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/results/ResolutionStatus.java @@ -31,6 +31,7 @@ public enum ResolutionStatus { // 'a.foo()' shouldn't be resolved to package level non-extension 'fun foo()' // candidates with such error are thrown away completely RECEIVER_PRESENCE_ERROR, + ARGUMENTS_MAPPING_ERROR, INCOMPLETE_TYPE_INFERENCE, SUCCESS(true); @@ -38,6 +39,7 @@ public enum ResolutionStatus { public static final EnumSet[] SEVERITY_LEVELS = new EnumSet[] { EnumSet.of(UNSAFE_CALL_ERROR), // weakest EnumSet.of(OTHER_ERROR), + EnumSet.of(ARGUMENTS_MAPPING_ERROR), EnumSet.of(RECEIVER_TYPE_ERROR), EnumSet.of(RECEIVER_PRESENCE_ERROR), // most severe }; diff --git a/compiler/testData/diagnostics/tests/checkArguments/overloadedFunction.kt b/compiler/testData/diagnostics/tests/checkArguments/overloadedFunction.kt new file mode 100644 index 00000000000..2a52f3b5925 --- /dev/null +++ b/compiler/testData/diagnostics/tests/checkArguments/overloadedFunction.kt @@ -0,0 +1,16 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE + +fun foo() {} +fun foo(s: Int) {} + + +fun bar(a: Any) {} +fun bar(a: Int) {} + +fun test() { + foo(1, 2) + foo("") + + bar(1, 2) + bar() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/checkArguments/overloadedFunction.txt b/compiler/testData/diagnostics/tests/checkArguments/overloadedFunction.txt new file mode 100644 index 00000000000..2a8db88bf61 --- /dev/null +++ b/compiler/testData/diagnostics/tests/checkArguments/overloadedFunction.txt @@ -0,0 +1,7 @@ +package + +internal fun bar(/*0*/ a: kotlin.Any): kotlin.Unit +internal fun bar(/*0*/ a: kotlin.Int): kotlin.Unit +internal fun foo(): kotlin.Unit +internal fun foo(/*0*/ s: kotlin.Int): kotlin.Unit +internal fun test(): kotlin.Unit diff --git a/compiler/testData/diagnostics/tests/inference/completeInferenceIfManyFailed.kt b/compiler/testData/diagnostics/tests/inference/completeInferenceIfManyFailed.kt index e6a4dff7637..8890716f100 100644 --- a/compiler/testData/diagnostics/tests/inference/completeInferenceIfManyFailed.kt +++ b/compiler/testData/diagnostics/tests/inference/completeInferenceIfManyFailed.kt @@ -6,12 +6,11 @@ fun joinT(x: Int, vararg a joinT(x: Any, y: T): T? { +fun joinT(x: Comparable<*>, y: T): T? { return null } fun test() { - val x2 = joinT(*1, "2") + val x2 = joinT(Unit, "2") checkSubtype(x2) -} - +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/completeInferenceIfManyFailed.txt b/compiler/testData/diagnostics/tests/inference/completeInferenceIfManyFailed.txt index 3c4c8086991..f1c0256183d 100644 --- a/compiler/testData/diagnostics/tests/inference/completeInferenceIfManyFailed.txt +++ b/compiler/testData/diagnostics/tests/inference/completeInferenceIfManyFailed.txt @@ -1,7 +1,7 @@ package package d { - internal fun joinT(/*0*/ x: kotlin.Any, /*1*/ y: T): T? + internal fun joinT(/*0*/ x: kotlin.Comparable<*>, /*1*/ y: T): T? internal fun joinT(/*0*/ x: kotlin.Int, /*1*/ vararg a: T /*kotlin.Array*/): T? internal fun test(): kotlin.Unit } diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/passToJava.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/passToJava.kt index 95aa5173dce..33465a257df 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/passToJava.kt +++ b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/passToJava.kt @@ -83,7 +83,7 @@ fun test(n: J?, nn: J) { J(nn, nn, nn) J(platformNN, platformNN, platformNN) - J(n, n, n) - J(platformN, platformN, platformN) + J(n, n, n) + J(platformN, platformN, platformN) J(platformJ, platformJ, platformJ) } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/nestedCalls/twoTypeParameters.kt b/compiler/testData/diagnostics/tests/resolve/nestedCalls/twoTypeParameters.kt index 298efdc4e3d..a6a4d5c7626 100644 --- a/compiler/testData/diagnostics/tests/resolve/nestedCalls/twoTypeParameters.kt +++ b/compiler/testData/diagnostics/tests/resolve/nestedCalls/twoTypeParameters.kt @@ -11,7 +11,6 @@ public class ResolutionTaskHolder { //todo the problem is the type of ResolutionTask is inferred as ResolutionTask too early tasks.bar(ResolutionTask(candidate)) - tasks.add(ResolutionTask(candidate)) + tasks.add(ResolutionTask(candidate)) } -} - +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/kt6993.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/kt6993.kt index 507c3565bd0..16002652544 100644 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/kt6993.kt +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/kt6993.kt @@ -1,4 +1,4 @@ // !DIAGNOSTICS: -UNUSED_PARAMETER class X(val t: T) { - constructor(t: T, i: Int) : this(i) -} + constructor(t: T, i: Int) : this(i) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/arrayList.kt b/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/arrayList.kt index b28f1a8c27e..10dc52d1f23 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/arrayList.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/arrayList.kt @@ -5,8 +5,8 @@ fun bar(): String? = null fun foo() { var x = ArrayList() - x.add(null) - x.add(bar()) + x.add(null) + x.add(bar()) x.add("") x[0] = null @@ -19,4 +19,4 @@ fun foo() { val b4: Collection = x val b6: MutableCollection = x -} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/customClassMutableList.kt b/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/customClassMutableList.kt index 31e3c57ad0f..02e15be9c66 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/customClassMutableList.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/customClassMutableList.kt @@ -22,8 +22,8 @@ fun bar(): String? = null fun foo() { var x = A() - x.add(null) - x.add(bar()) + x.add(null) + x.add(bar()) x.add("") x[0] = null @@ -36,4 +36,4 @@ fun foo() { val b4: Collection = x val b6: MutableCollection = x -} +} \ No newline at end of file diff --git a/compiler/testData/resolve/ResolveOfInfixExpressions.resolve b/compiler/testData/resolve/ResolveOfInfixExpressions.resolve index 37369a4a1ee..8ec9d7f2fdb 100644 --- a/compiler/testData/resolve/ResolveOfInfixExpressions.resolve +++ b/compiler/testData/resolve/ResolveOfInfixExpressions.resolve @@ -60,7 +60,7 @@ fun tt(t : T) : T { val x : ArrayList = 0 x`java::java.util.ArrayList.get()`[1] val foo = `Bar`Bar() - foo`!!`[null, 1] + foo`get2`[null, 1] foo`get2`[1, 1] foo`get1`[1] foo`set1`[1] = "" diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java index 74a2f715ebd..7d4bbd924a5 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java @@ -2370,6 +2370,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest(fileName); } + @TestMetadata("overloadedFunction.kt") + public void testOverloadedFunction() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/checkArguments/overloadedFunction.kt"); + doTest(fileName); + } + @TestMetadata("SpreadVarargs.kt") public void testSpreadVarargs() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/checkArguments/SpreadVarargs.kt"); diff --git a/idea/idea-completion/testData/basic/common/namedArguments/NamedArgumentsFromOverloads.kt b/idea/idea-completion/testData/basic/common/namedArguments/NamedArgumentsFromOverloads.kt index 4deb4f76f59..fdfc904c969 100644 --- a/idea/idea-completion/testData/basic/common/namedArguments/NamedArgumentsFromOverloads.kt +++ b/idea/idea-completion/testData/basic/common/namedArguments/NamedArgumentsFromOverloads.kt @@ -11,10 +11,10 @@ fun other() { } // EXIST: { lookupString:"nFirst", itemText:"nFirst =" } -// EXIST: { lookupString:"nSecond", itemText:"nSecond =" } -// EXIST: { lookupString:"nThird", itemText:"nThird =" } // EXIST: nLocal // todo - should exist // ABSENT: nClassParam +// ABSENT: nSecond +// ABSENT: nThird // ABSENT: nClassField \ No newline at end of file diff --git a/idea/testData/diagnosticMessage/noneApplicable.kt b/idea/testData/diagnosticMessage/noneApplicable.kt index 03448bb6d3e..017bb5f40fe 100644 --- a/idea/testData/diagnosticMessage/noneApplicable.kt +++ b/idea/testData/diagnosticMessage/noneApplicable.kt @@ -3,6 +3,7 @@ // !MESSAGE_TYPE: HTML fun foo(i: Int, s: String, b: Boolean) {} +fun foo(i: Int, s: Int) {} fun foo(b: Boolean, s: String) {} fun foo(i: Int) {} diff --git a/idea/testData/diagnosticMessage/noneApplicable1.html b/idea/testData/diagnosticMessage/noneApplicable1.html index a5ce102451c..9822ffc040d 100644 --- a/idea/testData/diagnosticMessage/noneApplicable1.html +++ b/idea/testData/diagnosticMessage/noneApplicable1.html @@ -3,7 +3,6 @@ None of the following functions can be called with the arguments supplied.
  • foo(Boolean, String) defined in root package
  • -
  • foo(Int) defined in root package
  • -
  • foo(Int, String, Boolean) defined in root package
  • +
  • foo(Int, Int) defined in root package
\ No newline at end of file diff --git a/idea/testData/diagnosticMessage/noneApplicableGeneric1.html b/idea/testData/diagnosticMessage/noneApplicableGeneric1.html index f025734706a..eb44484b372 100644 --- a/idea/testData/diagnosticMessage/noneApplicableGeneric1.html +++ b/idea/testData/diagnosticMessage/noneApplicableGeneric1.html @@ -8,8 +8,5 @@ None of the following functions can be called with the arguments supplied.
  • foo(Int, R, MutableList<`Int>, MutableList<`R>)
    where R cannot be inferred; T = Int for
    fun <`T, R> foo(t: T, r: R, lt: MutableList<`T>, lr: MutableList<`R>): Int defined in p
  • -
  • foo(Int, Any, List<`Int>)
    - where T = Int for
    - fun <`T> foo(t: T, a: Any, l: List<`T>): Int defined in p
  • \ No newline at end of file diff --git a/idea/testData/intentions/convertAssertToIf/inapplicableNoCondition.kt b/idea/testData/intentions/convertAssertToIf/inapplicableNoCondition.kt index 6dc4f21b0bd..23cf6915183 100644 --- a/idea/testData/intentions/convertAssertToIf/inapplicableNoCondition.kt +++ b/idea/testData/intentions/convertAssertToIf/inapplicableNoCondition.kt @@ -1,6 +1,7 @@ // IS_APPLICABLE: false // WITH_RUNTIME -// ERROR: No value passed for parameter value +// ERROR: None of the following functions can be called with the arguments supplied.
    • assert(Boolean, () → Any) defined in kotlin
    • assert(Boolean, Any = ...) defined in kotlin
    + fun foo() { assert { "text" } } \ No newline at end of file diff --git a/j2k/testData/fileOrElement/boxedType/kt-671.kt b/j2k/testData/fileOrElement/boxedType/kt-671.kt index d51c57abb0e..3fe5164ad98 100644 --- a/j2k/testData/fileOrElement/boxedType/kt-671.kt +++ b/j2k/testData/fileOrElement/boxedType/kt-671.kt @@ -1,4 +1,4 @@ -// ERROR: None of the following functions can be called with the arguments supplied: public open fun valueOf(p0: kotlin.Short): kotlin.Short! defined in java.lang.Short public open fun valueOf(p0: kotlin.String!): kotlin.Short! defined in java.lang.Short public open fun valueOf(p0: kotlin.String!, p1: kotlin.Int): kotlin.Short! defined in java.lang.Short +// ERROR: None of the following functions can be called with the arguments supplied: public open fun valueOf(p0: kotlin.Short): kotlin.Short! defined in java.lang.Short public open fun valueOf(p0: kotlin.String!): kotlin.Short! defined in java.lang.Short package demo class Test { diff --git a/j2k/testData/fileOrElement/issues/kt-807.kt b/j2k/testData/fileOrElement/issues/kt-807.kt index 08754035833..674d51a9eef 100644 --- a/j2k/testData/fileOrElement/issues/kt-807.kt +++ b/j2k/testData/fileOrElement/issues/kt-807.kt @@ -1,5 +1,5 @@ // ERROR: None of the following functions can be called with the arguments supplied: public constructor FileInputStream(p0: [ERROR : Unresolved java classifier: FileDescriptor]!) defined in java.io.FileInputStream public constructor FileInputStream(p0: java.io.File!) defined in java.io.FileInputStream public constructor FileInputStream(p0: kotlin.String!) defined in java.io.FileInputStream -// ERROR: None of the following functions can be called with the arguments supplied: public constructor InputStreamReader(p0: java.io.InputStream!) defined in java.io.InputStreamReader public constructor InputStreamReader(p0: java.io.InputStream!, p1: [ERROR : Unresolved java classifier: CharsetDecoder]!) defined in java.io.InputStreamReader public constructor InputStreamReader(p0: java.io.InputStream!, p1: java.nio.charset.Charset!) defined in java.io.InputStreamReader public constructor InputStreamReader(p0: java.io.InputStream!, p1: kotlin.String!) defined in java.io.InputStreamReader +// ERROR: Type mismatch: inferred type is java.io.DataInputStream but java.io.InputStream! was expected // ERROR: Assignments are not expressions, and only expressions are allowed in this context // ERROR: Unresolved reference: close import java.io.* diff --git a/j2k/testData/fileOrElement/list/Lists.kt b/j2k/testData/fileOrElement/list/Lists.kt index c8f66c6c118..eeed46cf148 100644 --- a/j2k/testData/fileOrElement/list/Lists.kt +++ b/j2k/testData/fileOrElement/list/Lists.kt @@ -1,6 +1,6 @@ // ERROR: Unresolved reference: LinkedList -// ERROR: None of the following functions can be called with the arguments supplied: public open fun add(e: kotlin.Any): kotlin.Boolean defined in java.util.ArrayList public open fun add(index: kotlin.Int, element: kotlin.Any): kotlin.Unit defined in java.util.ArrayList -// ERROR: None of the following functions can be called with the arguments supplied: public open fun add(e: kotlin.Any): kotlin.Boolean defined in java.util.ArrayList public open fun add(index: kotlin.Int, element: kotlin.Any): kotlin.Unit defined in java.util.ArrayList +// ERROR: Null can not be a value of a non-null type kotlin.Any +// ERROR: Null can not be a value of a non-null type kotlin.Any import java.util.* public class Lists { diff --git a/j2k/testData/fileOrElement/methodCallExpression/collectionsMethods2.kt b/j2k/testData/fileOrElement/methodCallExpression/collectionsMethods2.kt index 4585f71cd2b..f4e0d0dc11d 100644 --- a/j2k/testData/fileOrElement/methodCallExpression/collectionsMethods2.kt +++ b/j2k/testData/fileOrElement/methodCallExpression/collectionsMethods2.kt @@ -1,5 +1,5 @@ -// ERROR: None of the following functions can be called with the arguments supplied: public fun listOf(): kotlin.List defined in kotlin public fun listOf(vararg values: kotlin.String): kotlin.List defined in kotlin public fun listOf(value: kotlin.String): kotlin.List defined in kotlin -// ERROR: None of the following functions can be called with the arguments supplied: public fun setOf(): kotlin.Set defined in kotlin public fun setOf(vararg values: kotlin.String): kotlin.Set defined in kotlin public fun setOf(value: kotlin.String): kotlin.Set defined in kotlin +// ERROR: Null can not be a value of a non-null type kotlin.String +// ERROR: Null can not be a value of a non-null type kotlin.String import java.util.* class A {