Introduce inapplicable wrong receiver status to improve diagnostics

#KT-10754 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2017-07-10 05:19:19 +03:00
parent 79ee8f452c
commit 178bb900b4
7 changed files with 34 additions and 8 deletions
@@ -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)
@@ -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)
@@ -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,
@@ -0,0 +1,8 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
class A
fun A.fn(b: Int): Nothing = TODO()
fun A.run() {
"".apply { fn(<!TYPE_MISMATCH!>""<!>) }
}
@@ -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
}
@@ -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)
}
}
}
@@ -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")