Fix rewrite at slice exception for callable references inside flatMap

#KT-40254 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2020-07-13 15:45:50 +03:00
parent 1e4c554bcd
commit 09b44b3189
7 changed files with 48 additions and 5 deletions
@@ -2803,6 +2803,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
runTest("compiler/testData/diagnostics/tests/callableReference/resolve/resolveReferenceAgainstKFunctionAndKPrpoerty.kt");
}
@TestMetadata("resolveTwoReferencesAgainstGenerics.kt")
public void testResolveTwoReferencesAgainstGenerics() throws Exception {
runTest("compiler/testData/diagnostics/tests/callableReference/resolve/resolveTwoReferencesAgainstGenerics.kt");
}
@TestMetadata("valVsFun.kt")
public void testValVsFun() throws Exception {
runTest("compiler/testData/diagnostics/tests/callableReference/resolve/valVsFun.kt");
@@ -101,11 +101,8 @@ class KotlinCallCompleter(
return candidates
}
val newAtoms = mutableMapOf<KotlinResolutionCandidate, ResolvedLambdaAtom>()
for ((candidate, atom) in lambdas.entries) {
val newAtom = kotlinConstraintSystemCompleter.prepareLambdaAtomForFactoryPattern(atom, candidate, candidate)
newAtoms[candidate] = newAtom
candidate.addResolvedKtPrimitive(newAtom)
val newAtoms = lambdas.mapValues { (candidate, atom) ->
kotlinConstraintSystemCompleter.prepareLambdaAtomForFactoryPattern(atom, candidate, candidate)
}
val diagnosticHolderForLambda = KotlinDiagnosticsHolder.SimpleHolder()
@@ -0,0 +1,10 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
// WITH_RUNTIME
fun <T> List<Option<T>>.flatten(): List<T> = <!AMBIGUITY!>flatMap<!> { <!UNRESOLVED_REFERENCE!>it<!>.<!INAPPLICABLE_CANDIDATE!>fold<!>(::emptyList, <!UNRESOLVED_REFERENCE!>::listOf<!>) }
class Option<out T> {
fun <R> fold(ifEmpty: () -> R, ifSome: (T) -> R): R = TODO()
}
@@ -0,0 +1,10 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
// WITH_RUNTIME
fun <T> List<Option<T>>.flatten(): List<T> = flatMap { it.fold(::emptyList, ::listOf) }
class Option<out T> {
fun <R> fold(ifEmpty: () -> R, ifSome: (T) -> R): R = TODO()
}
@@ -0,0 +1,11 @@
package
public fun </*0*/ T> kotlin.collections.List<Option<T>>.flatten(): kotlin.collections.List<T>
public final class Option</*0*/ out T> {
public constructor Option</*0*/ out T>()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final fun </*0*/ R> fold(/*0*/ ifEmpty: () -> R, /*1*/ ifSome: (T) -> R): R
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -2810,6 +2810,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTestWithFirVali
runTest("compiler/testData/diagnostics/tests/callableReference/resolve/resolveReferenceAgainstKFunctionAndKPrpoerty.kt");
}
@TestMetadata("resolveTwoReferencesAgainstGenerics.kt")
public void testResolveTwoReferencesAgainstGenerics() throws Exception {
runTest("compiler/testData/diagnostics/tests/callableReference/resolve/resolveTwoReferencesAgainstGenerics.kt");
}
@TestMetadata("valVsFun.kt")
public void testValVsFun() throws Exception {
runTest("compiler/testData/diagnostics/tests/callableReference/resolve/valVsFun.kt");
@@ -2805,6 +2805,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
runTest("compiler/testData/diagnostics/tests/callableReference/resolve/resolveReferenceAgainstKFunctionAndKPrpoerty.kt");
}
@TestMetadata("resolveTwoReferencesAgainstGenerics.kt")
public void testResolveTwoReferencesAgainstGenerics() throws Exception {
runTest("compiler/testData/diagnostics/tests/callableReference/resolve/resolveTwoReferencesAgainstGenerics.kt");
}
@TestMetadata("valVsFun.kt")
public void testValVsFun() throws Exception {
runTest("compiler/testData/diagnostics/tests/callableReference/resolve/valVsFun.kt");