[NI] Properly detecting suitability of candidate for builder inference

#KT-41430 Fixed
This commit is contained in:
Dmitriy Novozhilov
2020-08-27 17:13:20 +03:00
parent b2d9e5be91
commit f247cc3165
7 changed files with 85 additions and 9 deletions
@@ -1737,6 +1737,11 @@ public class FirOldFrontendDiagnosticsTestWithStdlibGenerated extends AbstractFi
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/kt38179.kt");
}
@TestMetadata("kt41430.kt")
public void testKt41430() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/kt41430.kt");
}
@TestMetadata("lambdaExpectedType.kt")
public void testLambdaExpectedType() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/lambdaExpectedType.kt");
@@ -90,15 +90,9 @@ class CoroutineInferenceSession(
val dispatchReceiver = resolvedCall.dispatchReceiverArgument
return when {
extensionReceiver == null && dispatchReceiver == null -> false
extensionReceiver == null -> true
extensionReceiver.receiver.stableType.containsStubType() -> resolvedCall.candidateDescriptor.hasBuilderInferenceAnnotation()
else -> true
}
}
private fun KotlinType.containsNotFixedTypeVariable(storage: ConstraintStorage): Boolean {
return this.contains {
it.constructor in storage.notFixedTypeVariables
dispatchReceiver?.receiver?.stableType?.containsStubType() == true -> true
extensionReceiver?.receiver?.stableType?.containsStubType() == true -> resolvedCall.candidateDescriptor.hasBuilderInferenceAnnotation()
else -> false
}
}
@@ -0,0 +1,27 @@
// ISSUE: KT-41430
class A
fun test_1(list: List<Set<A>>) {
list.<!AMBIGUITY!>flatMapTo<!>(mutableSetOf()) { <!UNRESOLVED_REFERENCE!>it<!> }
}
fun test_2(list: List<Set<A>>) {
sequence<A> {
<!DEBUG_INFO_EXPRESSION_TYPE("ERROR CLASS: Ambiguity: flatMapTo, [kotlin/collections/flatMapTo, kotlin/collections/flatMapTo]")!>list.<!AMBIGUITY!>flatMapTo<!>(mutableSetOf()) { <!UNRESOLVED_REFERENCE!>it<!> }<!>
}
}
fun test_3(list: List<Set<A>>) {
sequence {
list.<!AMBIGUITY!>flatMapTo<!>(mutableSetOf()) { <!UNRESOLVED_REFERENCE!>it<!> }
yield(A())
}
}
fun test_4(list: List<Set<A>>) {
sequence {
yield(A())
list.<!AMBIGUITY!>flatMapTo<!>(mutableSetOf()) { <!UNRESOLVED_REFERENCE!>it<!> }
}
}
@@ -0,0 +1,27 @@
// ISSUE: KT-41430
class A
fun test_1(list: List<Set<A>>) {
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.MutableSet<A>")!>list.flatMapTo(mutableSetOf()) { it }<!>
}
fun test_2(list: List<Set<A>>) {
sequence<A> {
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.MutableSet<A>")!>list.flatMapTo(mutableSetOf()) { it }<!>
}
}
fun test_3(list: List<Set<A>>) {
sequence {
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.MutableSet<A>")!>list.flatMapTo(mutableSetOf()) { it }<!>
yield(A())
}
}
fun test_4(list: List<Set<A>>) {
sequence {
yield(A())
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.MutableSet<A>")!>list.flatMapTo(mutableSetOf()) { it }<!>
}
}
@@ -0,0 +1,13 @@
package
public fun test_1(/*0*/ list: kotlin.collections.List<kotlin.collections.Set<A>>): kotlin.Unit
public fun test_2(/*0*/ list: kotlin.collections.List<kotlin.collections.Set<A>>): kotlin.Unit
public fun test_3(/*0*/ list: kotlin.collections.List<kotlin.collections.Set<A>>): kotlin.Unit
public fun test_4(/*0*/ list: kotlin.collections.List<kotlin.collections.Set<A>>): 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
}
@@ -1737,6 +1737,11 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/kt38179.kt");
}
@TestMetadata("kt41430.kt")
public void testKt41430() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/kt41430.kt");
}
@TestMetadata("lambdaExpectedType.kt")
public void testLambdaExpectedType() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/lambdaExpectedType.kt");
@@ -1737,6 +1737,11 @@ public class DiagnosticsTestWithStdLibUsingJavacGenerated extends AbstractDiagno
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/kt38179.kt");
}
@TestMetadata("kt41430.kt")
public void testKt41430() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/kt41430.kt");
}
@TestMetadata("lambdaExpectedType.kt")
public void testLambdaExpectedType() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/lambdaExpectedType.kt");