diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolutionOldInference.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolutionOldInference.kt index 2d23b9a8755..4a1052664f3 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolutionOldInference.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolutionOldInference.kt @@ -173,9 +173,7 @@ class NewResolutionOldInference( // Temporary hack to resolve 'rem' as 'mod' if the first is do not present val emptyOrInapplicableCandidates = candidates.isEmpty() || - candidates.all { - it.candidateStatus.resultingApplicability == ResolutionCandidateApplicability.INAPPLICABLE - } + candidates.all { it.candidateStatus.resultingApplicability.isInapplicable } if (isBinaryRemOperator && shouldUseOperatorRem && emptyOrInapplicableCandidates) { val deprecatedName = OperatorConventions.REM_TO_MOD_OPERATION_NAMES[name] val processorForDeprecatedName = kind.createTowerProcessor(this, deprecatedName!!, tracing, scopeTower, detailedReceiver, context) @@ -471,6 +469,7 @@ internal fun createPreviousResolveError(status: ResolutionStatus): PreviousResol val level = when (status) { ResolutionStatus.SUCCESS, ResolutionStatus.INCOMPLETE_TYPE_INFERENCE -> return null ResolutionStatus.UNSAFE_CALL_ERROR -> ResolutionCandidateApplicability.MAY_THROW_RUNTIME_ERROR + ResolutionStatus.RECEIVER_TYPE_ERROR -> ResolutionCandidateApplicability.INAPPLICABLE_WRONG_RECEIVER else -> ResolutionCandidateApplicability.INAPPLICABLE } return PreviousResolutionError(level) diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/ImplicitScopeTower.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/ImplicitScopeTower.kt index c88c0698f2a..0fc50f5ed27 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/ImplicitScopeTower.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/ImplicitScopeTower.kt @@ -72,8 +72,8 @@ enum class ResolutionCandidateApplicability { RUNTIME_ERROR, // problems with visibility IMPOSSIBLE_TO_GENERATE, // access to outer class from nested INAPPLICABLE, // arguments not matched + INAPPLICABLE_WRONG_RECEIVER, // receiver not matched HIDDEN, // removed from resolve - // todo wrong receiver } abstract class ResolutionDiagnostic(val candidateLevel: ResolutionCandidateApplicability) diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/TowerUtils.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/TowerUtils.kt index 5a020ba139a..55744cc41d5 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/TowerUtils.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/TowerUtils.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2016 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. @@ -29,6 +29,9 @@ val CallableDescriptor.isSynthesized: Boolean val CandidateWithBoundDispatchReceiver.requiresExtensionReceiver: Boolean get() = descriptor.extensionReceiverParameter != null +val ResolutionCandidateApplicability.isInapplicable: Boolean + get() = this == ResolutionCandidateApplicability.INAPPLICABLE || this == ResolutionCandidateApplicability.INAPPLICABLE_WRONG_RECEIVER + internal class CandidateWithBoundDispatchReceiverImpl( override val dispatchReceiver: ReceiverValueWithSmartCastInfo?, override val descriptor: CallableDescriptor, diff --git a/compiler/testData/diagnostics/tests/inference/reportingImprovements/wrongArgumentExtensionFunction.kt b/compiler/testData/diagnostics/tests/inference/reportingImprovements/wrongArgumentExtensionFunction.kt new file mode 100644 index 00000000000..d2f52c51911 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/reportingImprovements/wrongArgumentExtensionFunction.kt @@ -0,0 +1,8 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class A +fun A.fn(b: Int): Nothing = TODO() + +fun A.run() { + "".apply { fn("") } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/reportingImprovements/wrongArgumentExtensionFunction.txt b/compiler/testData/diagnostics/tests/inference/reportingImprovements/wrongArgumentExtensionFunction.txt new file mode 100644 index 00000000000..327ad8a4fa6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/reportingImprovements/wrongArgumentExtensionFunction.txt @@ -0,0 +1,11 @@ +package + +public fun A.fn(/*0*/ b: kotlin.Int): kotlin.Nothing +public fun A.run(): kotlin.Unit + +public final class A { + public constructor A() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/resolve/candidatesPriority/wrongReceiverVsOtherError.resolve b/compiler/testData/resolve/candidatesPriority/wrongReceiverVsOtherError.resolve index fab90bc42b9..26936c6b3a7 100644 --- a/compiler/testData/resolve/candidatesPriority/wrongReceiverVsOtherError.resolve +++ b/compiler/testData/resolve/candidatesPriority/wrongReceiverVsOtherError.resolve @@ -8,9 +8,8 @@ open class B {} fun test(a: A, b: B) { with (a) { with (b) { - // candidates with errors for receiver b going before candidates with errors for receiver a - // resolved to Int.foo with error: UNRESOLVED_REFERENCE_WRONG_RECEIVER - `!`foo(1.0) + // resolved to A.foo with error: CONSTANT_EXPECTED_TYPE_MISMATCH + foo(1.0) } } } diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index eaeb60e6b3a..f489adab3a8 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -10925,6 +10925,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/reportingImprovements/subtypeForInvariantWithErrorGenerics.kt"); doTest(fileName); } + + @TestMetadata("wrongArgumentExtensionFunction.kt") + public void testWrongArgumentExtensionFunction() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/reportingImprovements/wrongArgumentExtensionFunction.kt"); + doTest(fileName); + } } @TestMetadata("compiler/testData/diagnostics/tests/inference/substitutions")