[NI] Check for maximally specific candidate chosen with factory resolution
This commit is contained in:
+10
@@ -1805,6 +1805,16 @@ public class FirOldFrontendDiagnosticsTestWithStdlibGenerated extends AbstractFi
|
|||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/factoryPattern/independentResolutionInLambda.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/factoryPattern/independentResolutionInLambda.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("multipleOverloads_1.kt")
|
||||||
|
public void testMultipleOverloads_1() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/factoryPattern/multipleOverloads_1.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("multipleOverloads_2.kt")
|
||||||
|
public void testMultipleOverloads_2() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/factoryPattern/multipleOverloads_2.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("overloadByLambdaReturnType_disabled.kt")
|
@TestMetadata("overloadByLambdaReturnType_disabled.kt")
|
||||||
public void testOverloadByLambdaReturnType_disabled() throws Exception {
|
public void testOverloadByLambdaReturnType_disabled() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/factoryPattern/overloadByLambdaReturnType_disabled.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/factoryPattern/overloadByLambdaReturnType_disabled.kt");
|
||||||
|
|||||||
@@ -144,11 +144,17 @@ class KotlinCallResolver(
|
|||||||
candidates.all { resolutionCallbacks.inferenceSession.shouldRunCompletion(it) }
|
candidates.all { resolutionCallbacks.inferenceSession.shouldRunCompletion(it) }
|
||||||
) {
|
) {
|
||||||
val candidatesWithAnnotation =
|
val candidatesWithAnnotation =
|
||||||
candidates.filter { it.resolvedCall.candidateDescriptor.annotations.hasAnnotation(OVERLOAD_RESOLUTION_BY_LAMBDA_ANNOTATION) }
|
candidates.filterTo(mutableSetOf()) { it.resolvedCall.candidateDescriptor.annotations.hasAnnotation(OVERLOAD_RESOLUTION_BY_LAMBDA_ANNOTATION) }
|
||||||
if (candidatesWithAnnotation.isNotEmpty()) {
|
if (candidatesWithAnnotation.isNotEmpty()) {
|
||||||
maximallySpecificCandidates = kotlinCallCompleter.chooseCandidateRegardingFactoryPatternResolution(maximallySpecificCandidates, resolutionCallbacks)
|
val newCandidates = kotlinCallCompleter.chooseCandidateRegardingFactoryPatternResolution(maximallySpecificCandidates, resolutionCallbacks)
|
||||||
|
maximallySpecificCandidates = overloadingConflictResolver.chooseMaximallySpecificCandidates(
|
||||||
|
newCandidates,
|
||||||
|
CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS,
|
||||||
|
discriminateGenerics = true
|
||||||
|
)
|
||||||
|
|
||||||
if (maximallySpecificCandidates.size > 1) {
|
if (maximallySpecificCandidates.size > 1) {
|
||||||
maximallySpecificCandidates = candidatesWithAnnotation.toSet() // or revert to original list?
|
maximallySpecificCandidates = candidatesWithAnnotation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -118,9 +118,11 @@ class KotlinCallCompleter(
|
|||||||
diagnosticHolderForLambda,
|
diagnosticHolderForLambda,
|
||||||
shouldRunInIndependentContext = true
|
shouldRunInIndependentContext = true
|
||||||
)
|
)
|
||||||
lambdas.getValue(firstCandidate).setAnalyzedResults(results.returnArgumentsInfo, listOf(firstAtom))
|
|
||||||
|
|
||||||
val lambdaReturnType = results.lambdaReturnType ?: return candidates
|
val lambdaReturnType = results.lambdaReturnType ?: return candidates
|
||||||
|
lambdas.getValue(firstCandidate).setAnalyzedResults(results.returnArgumentsInfo, listOf(firstAtom))
|
||||||
|
firstCandidate.csBuilder.addSubtypeConstraint(lambdaReturnType, firstAtom.returnType, LambdaArgumentConstraintPosition(firstAtom))
|
||||||
|
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
val (candidate, atom) = iterator.next()
|
val (candidate, atom) = iterator.next()
|
||||||
atom.setAnalyzedResults(results.returnArgumentsInfo, firstAtom.subResolvedAtoms!!)
|
atom.setAnalyzedResults(results.returnArgumentsInfo, firstAtom.subResolvedAtoms!!)
|
||||||
|
|||||||
+35
@@ -0,0 +1,35 @@
|
|||||||
|
// !LANGUAGE: +NewInference +FactoryPatternResolution
|
||||||
|
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE -UNUSED_EXPRESSION -EXPERIMENTAL_API_USAGE -EXPERIMENTAL_UNSIGNED_LITERALS
|
||||||
|
// ISSUE: KT-11265
|
||||||
|
|
||||||
|
// FILE: FactoryPattern.kt
|
||||||
|
|
||||||
|
package annotations
|
||||||
|
|
||||||
|
annotation class FactoryPattern
|
||||||
|
|
||||||
|
// FILE: main.kt
|
||||||
|
|
||||||
|
import annotations.FactoryPattern
|
||||||
|
|
||||||
|
@FactoryPattern
|
||||||
|
fun <R> UByteArray.fooMap(t: (UByte) -> Iterable<R>): List<R> {
|
||||||
|
TODO("ub.fm")
|
||||||
|
}
|
||||||
|
|
||||||
|
@FactoryPattern
|
||||||
|
fun <T, R> Iterable<T>.fooMap(t: (T) -> Iterable<R>): List<R> {
|
||||||
|
TODO("i.fm(i)")
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmName("fooMapSeq")
|
||||||
|
fun <T, R> Iterable<T>.fooMap(t: (T) -> Sequence<R>): List<R> {
|
||||||
|
TODO("i.fm(s)")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
val list = ubyteArrayOf(0u).<!AMBIGUITY!>fooMap<!> { <!INAPPLICABLE_CANDIDATE!>listOf<!>(<!UNRESOLVED_REFERENCE!>it<!>) }
|
||||||
|
takeUByteList(list)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun takeUByteList(list: List<UByte>) {}
|
||||||
+35
@@ -0,0 +1,35 @@
|
|||||||
|
// !LANGUAGE: +NewInference +FactoryPatternResolution
|
||||||
|
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE -UNUSED_EXPRESSION -EXPERIMENTAL_API_USAGE -EXPERIMENTAL_UNSIGNED_LITERALS
|
||||||
|
// ISSUE: KT-11265
|
||||||
|
|
||||||
|
// FILE: FactoryPattern.kt
|
||||||
|
|
||||||
|
package annotations
|
||||||
|
|
||||||
|
annotation class FactoryPattern
|
||||||
|
|
||||||
|
// FILE: main.kt
|
||||||
|
|
||||||
|
import annotations.FactoryPattern
|
||||||
|
|
||||||
|
@FactoryPattern
|
||||||
|
fun <R> UByteArray.fooMap(t: (UByte) -> Iterable<R>): List<R> {
|
||||||
|
TODO("ub.fm")
|
||||||
|
}
|
||||||
|
|
||||||
|
@FactoryPattern
|
||||||
|
fun <T, R> Iterable<T>.fooMap(t: (T) -> Iterable<R>): List<R> {
|
||||||
|
TODO("i.fm(i)")
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmName("fooMapSeq")
|
||||||
|
fun <T, R> Iterable<T>.fooMap(t: (T) -> Sequence<R>): List<R> {
|
||||||
|
TODO("i.fm(s)")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
val list = ubyteArrayOf(0u).fooMap { listOf(it) }
|
||||||
|
takeUByteList(list)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun takeUByteList(list: List<UByte>) {}
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public fun takeUByteList(/*0*/ list: kotlin.collections.List<kotlin.UByte>): kotlin.Unit
|
||||||
|
public fun test(): kotlin.Unit
|
||||||
|
@annotations.FactoryPattern public fun </*0*/ R> kotlin.UByteArray.fooMap(/*0*/ t: (kotlin.UByte) -> kotlin.collections.Iterable<R>): kotlin.collections.List<R>
|
||||||
|
@annotations.FactoryPattern public fun </*0*/ T, /*1*/ R> kotlin.collections.Iterable<T>.fooMap(/*0*/ t: (T) -> kotlin.collections.Iterable<R>): kotlin.collections.List<R>
|
||||||
|
@kotlin.jvm.JvmName(name = "fooMapSeq") public fun </*0*/ T, /*1*/ R> kotlin.collections.Iterable<T>.fooMap(/*0*/ t: (T) -> kotlin.sequences.Sequence<R>): kotlin.collections.List<R>
|
||||||
|
|
||||||
|
package annotations {
|
||||||
|
|
||||||
|
public final annotation class FactoryPattern : kotlin.Annotation {
|
||||||
|
public constructor FactoryPattern()
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
+29
@@ -0,0 +1,29 @@
|
|||||||
|
// !LANGUAGE: +NewInference +FactoryPatternResolution
|
||||||
|
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE -UNUSED_EXPRESSION -EXPERIMENTAL_API_USAGE -EXPERIMENTAL_UNSIGNED_LITERALS
|
||||||
|
// ISSUE: KT-11265
|
||||||
|
|
||||||
|
// FILE: FactoryPattern.kt
|
||||||
|
|
||||||
|
package annotations
|
||||||
|
|
||||||
|
annotation class FactoryPattern
|
||||||
|
|
||||||
|
// FILE: main.kt
|
||||||
|
|
||||||
|
import annotations.FactoryPattern
|
||||||
|
|
||||||
|
@FactoryPattern
|
||||||
|
fun <T, R : Comparable<R>> Iterable<T>.myMaxOf(selector: (T) -> R): R = TODO()
|
||||||
|
@FactoryPattern
|
||||||
|
fun <T> Iterable<T>.myMaxOf(selector: (T) -> Double): Double = TODO()
|
||||||
|
@FactoryPattern
|
||||||
|
fun <T> Iterable<T>.myMaxOf(selector: (T) -> Float): Float = TODO()
|
||||||
|
|
||||||
|
fun Double.pow(v: Int): Double = this
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
val value = listOf(1, 2, 3, 4, 5, 6).<!AMBIGUITY!>myMaxOf<!> { -2.0.pow(<!UNRESOLVED_REFERENCE!>it<!>) }
|
||||||
|
takeDouble(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun takeDouble(value: Double) {}
|
||||||
+29
@@ -0,0 +1,29 @@
|
|||||||
|
// !LANGUAGE: +NewInference +FactoryPatternResolution
|
||||||
|
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE -UNUSED_EXPRESSION -EXPERIMENTAL_API_USAGE -EXPERIMENTAL_UNSIGNED_LITERALS
|
||||||
|
// ISSUE: KT-11265
|
||||||
|
|
||||||
|
// FILE: FactoryPattern.kt
|
||||||
|
|
||||||
|
package annotations
|
||||||
|
|
||||||
|
annotation class FactoryPattern
|
||||||
|
|
||||||
|
// FILE: main.kt
|
||||||
|
|
||||||
|
import annotations.FactoryPattern
|
||||||
|
|
||||||
|
@FactoryPattern
|
||||||
|
fun <T, R : Comparable<R>> Iterable<T>.myMaxOf(selector: (T) -> R): R = TODO()
|
||||||
|
@FactoryPattern
|
||||||
|
fun <T> Iterable<T>.myMaxOf(selector: (T) -> Double): Double = TODO()
|
||||||
|
@FactoryPattern
|
||||||
|
fun <T> Iterable<T>.myMaxOf(selector: (T) -> Float): Float = TODO()
|
||||||
|
|
||||||
|
fun Double.pow(v: Int): Double = this
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
val value = listOf(1, 2, 3, 4, 5, 6).myMaxOf { -2.0.pow(it) }
|
||||||
|
takeDouble(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun takeDouble(value: Double) {}
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public fun takeDouble(/*0*/ value: kotlin.Double): kotlin.Unit
|
||||||
|
public fun test(): kotlin.Unit
|
||||||
|
@annotations.FactoryPattern public fun </*0*/ T, /*1*/ R : kotlin.Comparable<R>> kotlin.collections.Iterable<T>.myMaxOf(/*0*/ selector: (T) -> R): R
|
||||||
|
@annotations.FactoryPattern public fun </*0*/ T> kotlin.collections.Iterable<T>.myMaxOf(/*0*/ selector: (T) -> kotlin.Double): kotlin.Double
|
||||||
|
@annotations.FactoryPattern public fun </*0*/ T> kotlin.collections.Iterable<T>.myMaxOf(/*0*/ selector: (T) -> kotlin.Float): kotlin.Float
|
||||||
|
public fun kotlin.Double.pow(/*0*/ v: kotlin.Int): kotlin.Double
|
||||||
|
|
||||||
|
package annotations {
|
||||||
|
|
||||||
|
public final annotation class FactoryPattern : kotlin.Annotation {
|
||||||
|
public constructor FactoryPattern()
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+1
-1
@@ -30,7 +30,7 @@ fun test_2() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun test_3() {
|
fun test_3() {
|
||||||
val x = <!NONE_APPLICABLE!>create<!> { 1.0 }
|
val x = create { <!CONSTANT_EXPECTED_TYPE_MISMATCH, CONSTANT_EXPECTED_TYPE_MISMATCH!>1.0<!> }
|
||||||
}
|
}
|
||||||
|
|
||||||
@FactoryPattern
|
@FactoryPattern
|
||||||
|
|||||||
+10
@@ -2820,6 +2820,16 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW
|
|||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/factoryPattern/independentResolutionInLambda.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/factoryPattern/independentResolutionInLambda.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("multipleOverloads_1.kt")
|
||||||
|
public void testMultipleOverloads_1() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/factoryPattern/multipleOverloads_1.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("multipleOverloads_2.kt")
|
||||||
|
public void testMultipleOverloads_2() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/factoryPattern/multipleOverloads_2.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("overloadByLambdaReturnType_disabled.kt")
|
@TestMetadata("overloadByLambdaReturnType_disabled.kt")
|
||||||
public void testOverloadByLambdaReturnType_disabled() throws Exception {
|
public void testOverloadByLambdaReturnType_disabled() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/factoryPattern/overloadByLambdaReturnType_disabled.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/factoryPattern/overloadByLambdaReturnType_disabled.kt");
|
||||||
|
|||||||
compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java
Generated
+10
@@ -2820,6 +2820,16 @@ public class DiagnosticsTestWithStdLibUsingJavacGenerated extends AbstractDiagno
|
|||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/factoryPattern/independentResolutionInLambda.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/factoryPattern/independentResolutionInLambda.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("multipleOverloads_1.kt")
|
||||||
|
public void testMultipleOverloads_1() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/factoryPattern/multipleOverloads_1.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("multipleOverloads_2.kt")
|
||||||
|
public void testMultipleOverloads_2() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/factoryPattern/multipleOverloads_2.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("overloadByLambdaReturnType_disabled.kt")
|
@TestMetadata("overloadByLambdaReturnType_disabled.kt")
|
||||||
public void testOverloadByLambdaReturnType_disabled() throws Exception {
|
public void testOverloadByLambdaReturnType_disabled() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/factoryPattern/overloadByLambdaReturnType_disabled.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/factoryPattern/overloadByLambdaReturnType_disabled.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user