[NI] Check for maximally specific candidate chosen with factory resolution

This commit is contained in:
Dmitriy Novozhilov
2020-04-27 10:48:17 +03:00
parent e7869bd9d4
commit e1418a5540
12 changed files with 206 additions and 5 deletions
@@ -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>) {}
@@ -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>) {}
@@ -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
}
}
@@ -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) {}
@@ -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) {}
@@ -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
}
}
@@ -30,7 +30,7 @@ fun test_2() {
}
fun test_3() {
val x = <!NONE_APPLICABLE!>create<!> { 1.0 }
val x = create { <!CONSTANT_EXPECTED_TYPE_MISMATCH, CONSTANT_EXPECTED_TYPE_MISMATCH!>1.0<!> }
}
@FactoryPattern