Added diagnostic tests for inference and incorporation
This commit is contained in:
+6
@@ -0,0 +1,6 @@
|
||||
fun <T: Any> test(f: (T) -> T?) {
|
||||
doFun(f.ext())
|
||||
}
|
||||
|
||||
fun <E : Any> Function1<E, E?>.ext(): Function0<E?> = throw Exception()
|
||||
fun <R : Any> doFun(f: () -> R?) = f
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package
|
||||
|
||||
internal fun </*0*/ R : kotlin.Any> doFun(/*0*/ f: () -> R?): () -> R?
|
||||
internal fun </*0*/ T : kotlin.Any> test(/*0*/ f: (T) -> T?): kotlin.Unit
|
||||
internal fun </*0*/ E : kotlin.Any> ((E) -> E?).ext(): () -> E?
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
import java.util.*
|
||||
|
||||
fun test(list: ArrayList<Int>, comparatorFun: (Int, Int) -> Int) {
|
||||
sort(list, Comparator(comparatorFun))
|
||||
}
|
||||
|
||||
|
||||
public fun <E> sort(list: List<E>, c: Comparator<in E>) {
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package
|
||||
|
||||
public fun </*0*/ E> sort(/*0*/ list: kotlin.List<E>, /*1*/ c: java.util.Comparator<in E>): kotlin.Unit
|
||||
internal fun test(/*0*/ list: java.util.ArrayList<kotlin.Int>, /*1*/ comparatorFun: (kotlin.Int, kotlin.Int) -> kotlin.Int): kotlin.Unit
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
class GenericClass<out T>
|
||||
|
||||
public fun <K, V> GenericClass<Map<K, V>>.foo() {}
|
||||
|
||||
public fun bar<T>(t: T, ext: GenericClass<T>.() -> Unit) {}
|
||||
|
||||
fun test() {
|
||||
bar(mapOf(2 to 3)) { foo() }
|
||||
}
|
||||
|
||||
// from library
|
||||
class Pair<out A, out B>
|
||||
fun <K, V> mapOf(keyValuePair: Pair<K, V>): Map<K, V> = throw Exception()
|
||||
fun <A, B> A.to(that: B): Pair<A, B> = throw Exception()
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package
|
||||
|
||||
public fun </*0*/ T> bar(/*0*/ t: T, /*1*/ ext: GenericClass<T>.() -> kotlin.Unit): kotlin.Unit
|
||||
internal fun </*0*/ K, /*1*/ V> mapOf(/*0*/ keyValuePair: Pair<K, V>): kotlin.Map<K, V>
|
||||
internal fun test(): kotlin.Unit
|
||||
public fun </*0*/ K, /*1*/ V> GenericClass<kotlin.Map<K, V>>.foo(): kotlin.Unit
|
||||
internal fun </*0*/ A, /*1*/ B> A.to(/*0*/ that: B): Pair<A, B>
|
||||
|
||||
internal final class GenericClass</*0*/ out T> {
|
||||
public constructor GenericClass</*0*/ out T>()
|
||||
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
|
||||
}
|
||||
|
||||
internal final class Pair</*0*/ out A, /*1*/ out B> {
|
||||
public constructor Pair</*0*/ out A, /*1*/ out B>()
|
||||
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
+9
@@ -0,0 +1,9 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
class GenericClass<out T>(val value: T) {
|
||||
public fun foo<P>(extension: T.() -> P) {}
|
||||
}
|
||||
|
||||
public fun <E> GenericClass<List<E>>.bar() {
|
||||
foo( { listIterator() })
|
||||
}
|
||||
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
package
|
||||
|
||||
public fun </*0*/ E> GenericClass<kotlin.List<E>>.bar(): kotlin.Unit
|
||||
|
||||
internal final class GenericClass</*0*/ out T> {
|
||||
public constructor GenericClass</*0*/ out T>(/*0*/ value: T)
|
||||
internal final val value: T
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public final fun </*0*/ P> foo(/*0*/ extension: T.() -> P): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
import java.util.*
|
||||
|
||||
interface Foo
|
||||
class Bar<B : Foo>(val list: MutableList<B>) {}
|
||||
|
||||
fun <F : Foo> test(map: MutableMap<String, Bar<F>>) {
|
||||
|
||||
map.getOrPut1("", { Bar(ArrayList()) })
|
||||
}
|
||||
|
||||
fun <K, V> MutableMap<K, V>.getOrPut1(key: K, defaultValue: () -> V): V = throw Exception()
|
||||
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
package
|
||||
|
||||
internal fun </*0*/ F : Foo> test(/*0*/ map: kotlin.MutableMap<kotlin.String, Bar<F>>): kotlin.Unit
|
||||
internal fun </*0*/ K, /*1*/ V> kotlin.MutableMap<K, V>.getOrPut1(/*0*/ key: K, /*1*/ defaultValue: () -> V): V
|
||||
|
||||
internal final class Bar</*0*/ B : Foo> {
|
||||
public constructor Bar</*0*/ B : Foo>(/*0*/ list: kotlin.MutableList<B>)
|
||||
internal final val list: kotlin.MutableList<B>
|
||||
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
|
||||
}
|
||||
|
||||
internal interface 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
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
// !CHECK_TYPE
|
||||
// KT-3372 Use upper bound in type argument inference
|
||||
|
||||
import java.util.HashSet
|
||||
|
||||
fun <T, C: MutableCollection<T>> Iterable<T>.toCollection(result: C) : C = throw Exception()
|
||||
|
||||
fun test(list: List<Int>) {
|
||||
val set = list.toCollection(HashSet())
|
||||
set checkType { _<HashSet<Int>>() }
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package
|
||||
|
||||
internal fun test(/*0*/ list: kotlin.List<kotlin.Int>): kotlin.Unit
|
||||
internal fun </*0*/ T, /*1*/ C : kotlin.MutableCollection<T>> kotlin.Iterable<T>.toCollection(/*0*/ result: C): C
|
||||
@@ -0,0 +1,10 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
// !CHECK_TYPE
|
||||
|
||||
fun <T, R> Collection<T>.map(transform : (T) -> R) : List<R> = throw Exception()
|
||||
|
||||
fun test(list: List<List<Int>>) {
|
||||
|
||||
val list1 = list.map { it.map { "$it" } }
|
||||
list1 checkType { _<List<List<String>>>() }
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package
|
||||
|
||||
internal fun test(/*0*/ list: kotlin.List<kotlin.List<kotlin.Int>>): kotlin.Unit
|
||||
internal fun </*0*/ T, /*1*/ R> kotlin.Collection<T>.map(/*0*/ transform: (T) -> R): kotlin.List<R>
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
fun <T> arrayOf(vararg t : T) : Array<T> = t as Array<T>
|
||||
|
||||
fun test() {
|
||||
val array = arrayOf(arrayOf(1))
|
||||
array checkType { _<Array<Array<Int>>>() }
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package
|
||||
|
||||
internal fun </*0*/ T> arrayOf(/*0*/ vararg t: T /*kotlin.Array<out T>*/): kotlin.Array<T>
|
||||
internal fun test(): kotlin.Unit
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
fun foo(a: Any, f: ()->Int) = f()
|
||||
fun foo(a: Any, f: (Any)->Int) = f(a)
|
||||
fun foo(i: Int, f: Int.()->Int) = i.f()
|
||||
|
||||
fun test1() {
|
||||
<!OVERLOAD_RESOLUTION_AMBIGUITY!>foo<!>(1) { ->
|
||||
<!NO_THIS!>this<!>
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package
|
||||
|
||||
internal fun foo(/*0*/ a: kotlin.Any, /*1*/ f: () -> kotlin.Int): kotlin.Int
|
||||
internal fun foo(/*0*/ a: kotlin.Any, /*1*/ f: (kotlin.Any) -> kotlin.Int): kotlin.Int
|
||||
internal fun foo(/*0*/ i: kotlin.Int, /*1*/ f: kotlin.Int.() -> kotlin.Int): kotlin.Int
|
||||
internal fun test1(): kotlin.Unit
|
||||
@@ -0,0 +1,8 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
// !CHECK_TYPE
|
||||
|
||||
fun <T, R> foo(first: () -> T, second: (T) -> R): R = throw Exception()
|
||||
fun test() {
|
||||
val r = foo( { 4 }, { "${it + 1}" } )
|
||||
r checkType { _<String>() }
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package
|
||||
|
||||
internal fun </*0*/ T, /*1*/ R> foo(/*0*/ first: () -> T, /*1*/ second: (T) -> R): R
|
||||
internal fun test(): kotlin.Unit
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
fun <T> foo(f: () -> Collection<T>, p: (T) -> Boolean): Collection<T> = throw Exception()
|
||||
|
||||
fun emptyList<T>(): List<T> = throw Exception()
|
||||
|
||||
fun test(): Collection<Int> = foo({ emptyList<Int>() }, { x -> x > 0 })
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
package
|
||||
|
||||
internal fun </*0*/ T> emptyList(): kotlin.List<T>
|
||||
internal fun </*0*/ T> foo(/*0*/ f: () -> kotlin.Collection<T>, /*1*/ p: (T) -> kotlin.Boolean): kotlin.Collection<T>
|
||||
internal fun test(): kotlin.Collection<kotlin.Int>
|
||||
+17
-17
@@ -10,26 +10,26 @@ fun foo(s: String, a: Any) = s + a
|
||||
fun foo(a: Any, s: String) = s + a
|
||||
fun foo(i: Int, j: Int) = i + j
|
||||
fun foo(a: Any, i: Int) = "$a$i"
|
||||
fun foo(f: (Int)->Int, i: Int) = f(i)
|
||||
fun foo(f: (String)->Int, s: String) = f(s)
|
||||
fun foo(f: (Any)->Int, a: Any) = f(a)
|
||||
fun foo(s: String, f: (String)->Int) = f(s)
|
||||
fun foo(a: Any, f: (Any)->Int) = f(a)
|
||||
fun foo(f: (Int) -> Int, i: Int) = f(i)
|
||||
fun foo(f: (String) -> Int, s: String) = f(s)
|
||||
fun foo(f: (Any) -> Int, a: Any) = f(a)
|
||||
fun foo(s: String, f: (String) -> Int) = f(s)
|
||||
fun foo(a: Any, f: (Any) -> Int) = f(a)
|
||||
//appropriate function
|
||||
fun foo(i: Int, f: (Int)->Int) = f(i)
|
||||
fun foo(i: Int, f: (Int) -> Int) = f(i)
|
||||
|
||||
fun id<T>(t: T) = t
|
||||
|
||||
fun test() {
|
||||
foo(1, id { <!DEPRECATED_LAMBDA_SYNTAX!>(x1: Int):Int<!> ->
|
||||
foo(2, id { <!DEPRECATED_LAMBDA_SYNTAX!>(x2: Int): Int<!> ->
|
||||
foo(3, id { <!DEPRECATED_LAMBDA_SYNTAX!>(x3: Int): Int<!> ->
|
||||
foo(4, id { <!DEPRECATED_LAMBDA_SYNTAX!>(x4: Int): Int<!> ->
|
||||
foo(5, id { <!DEPRECATED_LAMBDA_SYNTAX!>(x5: Int): Int<!> ->
|
||||
x1 + x2 + x3 + x4 + x5 + A.iii
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
foo(1, id(fun(x1: Int) =
|
||||
foo(2, id(fun(x2: Int) =
|
||||
foo(3, id(fun(x3: Int) =
|
||||
foo(4, id(fun(x4: Int) =
|
||||
foo(5, id(fun(x5: Int) =
|
||||
x1 + x2 + x3 + x4 + x5 + A.iii
|
||||
))
|
||||
))
|
||||
))
|
||||
))
|
||||
))
|
||||
}
|
||||
|
||||
@@ -6696,6 +6696,63 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/inference/commonSystem")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class CommonSystem extends AbstractJetDiagnosticsTest {
|
||||
public void testAllFilesPresentInCommonSystem() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/inference/commonSystem"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("boundOnNullableVariable.kt")
|
||||
public void testBoundOnNullableVariable() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/commonSystem/boundOnNullableVariable.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("dontCaptureTypeVariable.kt")
|
||||
public void testDontCaptureTypeVariable() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/commonSystem/dontCaptureTypeVariable.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("fixVariablesInRightOrder.kt")
|
||||
public void testFixVariablesInRightOrder() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/commonSystem/fixVariablesInRightOrder.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("genericCandidateInGenericClass.kt")
|
||||
public void testGenericCandidateInGenericClass() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/commonSystem/genericCandidateInGenericClass.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("inferenceWithUpperBoundsInLambda.kt")
|
||||
public void testInferenceWithUpperBoundsInLambda() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/commonSystem/inferenceWithUpperBoundsInLambda.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt3372toCollection.kt")
|
||||
public void testKt3372toCollection() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/commonSystem/kt3372toCollection.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("nestedLambdas.kt")
|
||||
public void testNestedLambdas() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/commonSystem/nestedLambdas.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("theSameFunctionInArgs.kt")
|
||||
public void testTheSameFunctionInArgs() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/commonSystem/theSameFunctionInArgs.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/inference/constraints")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
@@ -11085,12 +11142,30 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("ambiguityWithTwoCorrespondingFunctionTypes.kt")
|
||||
public void testAmbiguityWithTwoCorrespondingFunctionTypes() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/resolve/ambiguityWithTwoCorrespondingFunctionTypes.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("incompleteConstructorInvocation.kt")
|
||||
public void testIncompleteConstructorInvocation() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/resolve/incompleteConstructorInvocation.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("inferenceInLinkedLambdas.kt")
|
||||
public void testInferenceInLinkedLambdas() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/resolve/inferenceInLinkedLambdas.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("inferenceInLinkedLambdasDependentOnExpectedType.kt")
|
||||
public void testInferenceInLinkedLambdasDependentOnExpectedType() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/resolve/inferenceInLinkedLambdasDependentOnExpectedType.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("objectLiteralAsArgument.kt")
|
||||
public void testObjectLiteralAsArgument() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/resolve/objectLiteralAsArgument.kt");
|
||||
|
||||
Reference in New Issue
Block a user