[NI] Fix overload resolution ambiguity for incorrect provideDelegate

#KT-25810
This commit is contained in:
Mikhail Zarechenskiy
2018-08-27 10:49:27 +03:00
parent ae4ff45750
commit 4067d6b196
6 changed files with 64 additions and 3 deletions
@@ -247,7 +247,11 @@ class PSICallResolver(
tracingStrategy: TracingStrategy,
trace: BindingTrace
): ManyCandidates<D> {
val resolvedCalls = diagnostic.candidates.map { kotlinToResolvedCallTransformer.onlyTransform<D>(it.resolvedCall, emptyList()) }
val resolvedCalls = diagnostic.candidates.map {
kotlinToResolvedCallTransformer.onlyTransform<D>(
it.resolvedCall, it.diagnosticsFromResolutionParts + it.getSystem().diagnostics
)
}
if (diagnostic.candidates.areAllFailed()) {
if (diagnostic.candidates.areAllFailedWithInapplicableWrongReceiver()) {
@@ -0,0 +1,19 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_VARIABLE
import kotlin.reflect.KProperty
object Foo
object Bar
object Baz
operator fun Foo.provideDelegate(receiver: Any?, property: KProperty<*>) = this
operator fun Bar.provideDelegate(receiver: Any?, property: KProperty<*>) = this
operator fun Foo.getValue(nothing: Any?, property: KProperty<*>): Any = TODO()
operator fun Bar.getValue(nothing: Any?, property: KProperty<*>): Any = TODO()
operator fun Baz.getValue(nothing: Any?, property: KProperty<*>): Any = TODO()
fun test() {
val bar by Baz
}
@@ -0,0 +1,29 @@
package
public fun test(): kotlin.Unit
public operator fun Bar.getValue(/*0*/ nothing: kotlin.Any?, /*1*/ property: kotlin.reflect.KProperty<*>): kotlin.Any
public operator fun Baz.getValue(/*0*/ nothing: kotlin.Any?, /*1*/ property: kotlin.reflect.KProperty<*>): kotlin.Any
public operator fun Foo.getValue(/*0*/ nothing: kotlin.Any?, /*1*/ property: kotlin.reflect.KProperty<*>): kotlin.Any
public operator fun Bar.provideDelegate(/*0*/ receiver: kotlin.Any?, /*1*/ property: kotlin.reflect.KProperty<*>): Bar
public operator fun Foo.provideDelegate(/*0*/ receiver: kotlin.Any?, /*1*/ property: kotlin.reflect.KProperty<*>): Foo
public object Bar {
private constructor Bar()
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
}
public object Baz {
private constructor Baz()
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
}
public object Foo {
private constructor Foo()
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
}
@@ -1,10 +1,9 @@
// !WITH_NEW_INFERENCE
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
class A {
val c: Int by <!NI;DELEGATE_SPECIAL_FUNCTION_AMBIGUITY, OI;DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!>Delegate()<!>
val c: Int by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!>Delegate()<!>
}
class Delegate {
@@ -5683,6 +5683,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
runTest("compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/noOperatorModifierOnProvideDelegate.kt");
}
@TestMetadata("overloadResolutionForSeveralProvideDelegates.kt")
public void testOverloadResolutionForSeveralProvideDelegates() throws Exception {
runTest("compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/overloadResolutionForSeveralProvideDelegates.kt");
}
@TestMetadata("provideDelegateOperatorDeclaration.kt")
public void testProvideDelegateOperatorDeclaration() throws Exception {
runTest("compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/provideDelegateOperatorDeclaration.kt");
@@ -5683,6 +5683,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
runTest("compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/noOperatorModifierOnProvideDelegate.kt");
}
@TestMetadata("overloadResolutionForSeveralProvideDelegates.kt")
public void testOverloadResolutionForSeveralProvideDelegates() throws Exception {
runTest("compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/overloadResolutionForSeveralProvideDelegates.kt");
}
@TestMetadata("provideDelegateOperatorDeclaration.kt")
public void testProvideDelegateOperatorDeclaration() throws Exception {
runTest("compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/provideDelegateOperatorDeclaration.kt");