Introduce inapplicable wrong receiver status to improve diagnostics
#KT-10754 Fixed
This commit is contained in:
+2
-3
@@ -173,9 +173,7 @@ class NewResolutionOldInference(
|
|||||||
|
|
||||||
// Temporary hack to resolve 'rem' as 'mod' if the first is do not present
|
// Temporary hack to resolve 'rem' as 'mod' if the first is do not present
|
||||||
val emptyOrInapplicableCandidates = candidates.isEmpty() ||
|
val emptyOrInapplicableCandidates = candidates.isEmpty() ||
|
||||||
candidates.all {
|
candidates.all { it.candidateStatus.resultingApplicability.isInapplicable }
|
||||||
it.candidateStatus.resultingApplicability == ResolutionCandidateApplicability.INAPPLICABLE
|
|
||||||
}
|
|
||||||
if (isBinaryRemOperator && shouldUseOperatorRem && emptyOrInapplicableCandidates) {
|
if (isBinaryRemOperator && shouldUseOperatorRem && emptyOrInapplicableCandidates) {
|
||||||
val deprecatedName = OperatorConventions.REM_TO_MOD_OPERATION_NAMES[name]
|
val deprecatedName = OperatorConventions.REM_TO_MOD_OPERATION_NAMES[name]
|
||||||
val processorForDeprecatedName = kind.createTowerProcessor(this, deprecatedName!!, tracing, scopeTower, detailedReceiver, context)
|
val processorForDeprecatedName = kind.createTowerProcessor(this, deprecatedName!!, tracing, scopeTower, detailedReceiver, context)
|
||||||
@@ -471,6 +469,7 @@ internal fun createPreviousResolveError(status: ResolutionStatus): PreviousResol
|
|||||||
val level = when (status) {
|
val level = when (status) {
|
||||||
ResolutionStatus.SUCCESS, ResolutionStatus.INCOMPLETE_TYPE_INFERENCE -> return null
|
ResolutionStatus.SUCCESS, ResolutionStatus.INCOMPLETE_TYPE_INFERENCE -> return null
|
||||||
ResolutionStatus.UNSAFE_CALL_ERROR -> ResolutionCandidateApplicability.MAY_THROW_RUNTIME_ERROR
|
ResolutionStatus.UNSAFE_CALL_ERROR -> ResolutionCandidateApplicability.MAY_THROW_RUNTIME_ERROR
|
||||||
|
ResolutionStatus.RECEIVER_TYPE_ERROR -> ResolutionCandidateApplicability.INAPPLICABLE_WRONG_RECEIVER
|
||||||
else -> ResolutionCandidateApplicability.INAPPLICABLE
|
else -> ResolutionCandidateApplicability.INAPPLICABLE
|
||||||
}
|
}
|
||||||
return PreviousResolutionError(level)
|
return PreviousResolutionError(level)
|
||||||
|
|||||||
+1
-1
@@ -72,8 +72,8 @@ enum class ResolutionCandidateApplicability {
|
|||||||
RUNTIME_ERROR, // problems with visibility
|
RUNTIME_ERROR, // problems with visibility
|
||||||
IMPOSSIBLE_TO_GENERATE, // access to outer class from nested
|
IMPOSSIBLE_TO_GENERATE, // access to outer class from nested
|
||||||
INAPPLICABLE, // arguments not matched
|
INAPPLICABLE, // arguments not matched
|
||||||
|
INAPPLICABLE_WRONG_RECEIVER, // receiver not matched
|
||||||
HIDDEN, // removed from resolve
|
HIDDEN, // removed from resolve
|
||||||
// todo wrong receiver
|
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class ResolutionDiagnostic(val candidateLevel: ResolutionCandidateApplicability)
|
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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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
|
val CandidateWithBoundDispatchReceiver.requiresExtensionReceiver: Boolean
|
||||||
get() = descriptor.extensionReceiverParameter != null
|
get() = descriptor.extensionReceiverParameter != null
|
||||||
|
|
||||||
|
val ResolutionCandidateApplicability.isInapplicable: Boolean
|
||||||
|
get() = this == ResolutionCandidateApplicability.INAPPLICABLE || this == ResolutionCandidateApplicability.INAPPLICABLE_WRONG_RECEIVER
|
||||||
|
|
||||||
internal class CandidateWithBoundDispatchReceiverImpl(
|
internal class CandidateWithBoundDispatchReceiverImpl(
|
||||||
override val dispatchReceiver: ReceiverValueWithSmartCastInfo?,
|
override val dispatchReceiver: ReceiverValueWithSmartCastInfo?,
|
||||||
override val descriptor: CallableDescriptor,
|
override val descriptor: CallableDescriptor,
|
||||||
|
|||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||||
|
|
||||||
|
class A
|
||||||
|
fun A.fn(b: Int): Nothing = TODO()
|
||||||
|
|
||||||
|
fun A.run() {
|
||||||
|
"".apply { fn(<!TYPE_MISMATCH!>""<!>) }
|
||||||
|
}
|
||||||
+11
@@ -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
|
||||||
|
}
|
||||||
+2
-3
@@ -8,9 +8,8 @@ open class B {}
|
|||||||
fun test(a: A, b: B) {
|
fun test(a: A, b: B) {
|
||||||
with (a) {
|
with (a) {
|
||||||
with (b) {
|
with (b) {
|
||||||
// candidates with errors for receiver b going before candidates with errors for receiver a
|
// resolved to A.foo with error: CONSTANT_EXPECTED_TYPE_MISMATCH
|
||||||
// resolved to Int.foo with error: UNRESOLVED_REFERENCE_WRONG_RECEIVER
|
foo(1.0)
|
||||||
`!`foo(1.0)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10925,6 +10925,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
|||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/reportingImprovements/subtypeForInvariantWithErrorGenerics.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/reportingImprovements/subtypeForInvariantWithErrorGenerics.kt");
|
||||||
doTest(fileName);
|
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")
|
@TestMetadata("compiler/testData/diagnostics/tests/inference/substitutions")
|
||||||
|
|||||||
Reference in New Issue
Block a user