[TEST] Change semantics of CHECK_TYPE directive and update testdata

Previously helpers from checkType.kt was in special package, and
  if directive was enabled then test runner (`AbstractDiagnosticTest`)
  injected additional imports to test files and removed them after test
  was completed.
It's very hard to support such behavior in new test infrastructure so
  there was a decision about changing `CHECK_TYPE`:
1. All helpers from `checkType.kt` now stays in default package
2. `CHECK_TYPE` only adds `checkType.kt` to set of analyzed files
      and don't modify their content

For test which are written in default package (most of tests actually)
  there are no changes. On the other hand if there is a test where dev
  want to use checkType functions in testfile with some package then he
  should explicitly import functions which he needed (`checkSubtype`,
  `checkType`, `_`)
This commit is contained in:
Dmitriy Novozhilov
2020-11-12 17:45:40 +03:00
parent 653b26174b
commit 419f54259c
91 changed files with 269 additions and 111 deletions
@@ -3,6 +3,8 @@
package d
import checkSubtype
fun <T: Any> joinT(x: Int, vararg a: T): T? {
return null
}
@@ -3,6 +3,8 @@
package d
import checkSubtype
fun <T: Any> joinT(<!UNUSED_PARAMETER!>x<!>: Int, vararg <!UNUSED_PARAMETER!>a<!>: T): T? {
return null
}
@@ -14,4 +16,4 @@ fun <T: Any> joinT(<!UNUSED_PARAMETER!>x<!>: Comparable<*>, <!UNUSED_PARAMETER!>
fun test() {
val x2 = <!OI;TYPE_INFERENCE_PARAMETER_CONSTRAINT_ERROR!>joinT<!>(<!TYPE_MISMATCH!>Unit<!>, "2")
checkSubtype<String?>(x2)
}
}
@@ -3,6 +3,7 @@
package h
//+JDK
import java.util.*
import checkSubtype
fun <T> id(t: T) : T = t
@@ -3,6 +3,7 @@
package h
//+JDK
import java.util.*
import checkSubtype
fun <T> id(t: T) : T = t
@@ -3,6 +3,8 @@
package a
import checkSubtype
fun <T> emptyList(): List<T> = throw Exception()
fun <T> foo(f: T.() -> Unit, l: List<T>): T = throw Exception("$f$l")
@@ -12,4 +14,4 @@ fun test() {
checkSubtype<Int>(q)
foo({}, emptyList())
}
}
@@ -3,6 +3,8 @@
package a
import checkSubtype
fun <T> emptyList(): List<T> = throw Exception()
fun <T> foo(f: T.() -> Unit, l: List<T>): T = throw Exception("$f$l")
@@ -12,4 +14,4 @@ fun test() {
checkSubtype<Int>(q)
<!NI;NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, OI;TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>foo<!>({}, <!NI;NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, OI;TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>emptyList<!>())
}
}
@@ -3,6 +3,7 @@
package a
//+JDK
import java.util.*
import checkSubtype
fun <A> cons(x: A, xs: List<A>): List<A> = xs
@@ -3,6 +3,7 @@
package a
//+JDK
import java.util.*
import checkSubtype
fun <A> cons(<!UNUSED_PARAMETER!>x<!>: A, xs: List<A>): List<A> = xs
@@ -4,6 +4,7 @@ package a
//+JDK
import java.util.*
import checkSubtype
fun foo() {
val v = array(1, 2, 3)
@@ -32,4 +33,4 @@ fun <T> array(vararg t : T) : Array<T> = t as Array<T>
infix fun <T, R> Array<T>.map(transform : (T) -> R) : List<R> {}
infix fun <T, R> Iterable<T>.map(transform : (T) -> R) : List<R> {}
infix fun <T, R> Iterable<T>.map(transform : (T) -> R) : List<R> {}
@@ -4,6 +4,7 @@ package a
//+JDK
import java.util.*
import checkSubtype
fun foo() {
val v = array(1, 2, 3)
@@ -32,4 +33,4 @@ fun <T> array(vararg t : T) : Array<T> = t as Array<T>
infix fun <T, R> Array<T>.map(<!UNUSED_PARAMETER!>transform<!> : (T) -> R) : List<R> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
infix fun <T, R> Iterable<T>.map(<!UNUSED_PARAMETER!>transform<!> : (T) -> R) : List<R> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
infix fun <T, R> Iterable<T>.map(<!UNUSED_PARAMETER!>transform<!> : (T) -> R) : List<R> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
@@ -4,6 +4,7 @@ package i
//+JDK
import java.util.*
import checkSubtype
fun <T, R> Collection<T>.map1(f : (T) -> R) : List<R> {}
fun <T, R> java.lang.Iterable<T>.map1(f : (T) -> R) : List<R> {}
@@ -21,4 +22,4 @@ fun test1(list: List<Int>) {
val res = list.foo()
//check res is not of error type
<!INAPPLICABLE_CANDIDATE!>checkSubtype<!><String>(res)
}
}
@@ -4,6 +4,7 @@ package i
//+JDK
import java.util.*
import checkSubtype
fun <T, R> Collection<T>.map1(<!UNUSED_PARAMETER!>f<!> : (T) -> R) : List<R> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
fun <T, R> <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>java.lang.Iterable<T><!>.map1(<!UNUSED_PARAMETER!>f<!> : (T) -> R) : List<R> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
@@ -21,4 +22,4 @@ fun test1(list: List<Int>) {
val res = list.foo()
//check res is not of error type
checkSubtype<String>(<!TYPE_MISMATCH!>res<!>)
}
}
@@ -3,6 +3,8 @@
package aaa
import checkSubtype
infix fun <T> T.foo(t: T) = t
fun <T> id(t: T) = t
@@ -3,6 +3,8 @@
//KT-1029 Wrong type inference
package i
import checkSubtype
public fun<T> from(yielder: ()->Iterable<T>) : Iterable<T> {
}
@@ -3,6 +3,8 @@
//KT-1029 Wrong type inference
package i
import checkSubtype
public fun<T> from(<!UNUSED_PARAMETER!>yielder<!>: ()->Iterable<T>) : Iterable<T> {
<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
@@ -4,6 +4,7 @@
package i
import java.util.ArrayList
import checkSubtype
public infix fun<TItem> Iterable<TItem>.where(predicate : (TItem)->Boolean) : ()->Iterable<TItem> {
}
@@ -4,6 +4,7 @@
package i
import java.util.ArrayList
import checkSubtype
public infix fun<TItem> Iterable<TItem>.where(<!UNUSED_PARAMETER!>predicate<!> : (TItem)->Boolean) : ()->Iterable<TItem> {
<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
@@ -4,6 +4,8 @@
package d
import checkSubtype
fun test(numbers: Iterable<Int>) {
val s = numbers.map{it.toString()}.fold(""){it, it2 -> it + it2}
<!INAPPLICABLE_CANDIDATE!>checkSubtype<!><Int>(s)
@@ -12,4 +14,4 @@ fun test(numbers: Iterable<Int>) {
//from library
fun <T, R> Iterable<T>.map(transform : (T) -> R) : List<R> {}
fun <T> Iterable<T>.fold(initial: T, operation: (T, T) -> T): T {}
fun <T> Iterable<T>.fold(initial: T, operation: (T, T) -> T): T {}
@@ -4,6 +4,8 @@
package d
import checkSubtype
fun test(numbers: Iterable<Int>) {
val s = numbers.map{it.toString()}.fold(""){it, it2 -> it + it2}
checkSubtype<Int>(<!TYPE_MISMATCH!>s<!>)
@@ -12,4 +14,4 @@ fun test(numbers: Iterable<Int>) {
//from library
fun <T, R> Iterable<T>.map(<!UNUSED_PARAMETER!>transform<!> : (T) -> R) : List<R> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
fun <T> Iterable<T>.fold(<!UNUSED_PARAMETER!>initial<!>: T, <!UNUSED_PARAMETER!>operation<!>: (T, T) -> T): T {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
fun <T> Iterable<T>.fold(<!UNUSED_PARAMETER!>initial<!>: T, <!UNUSED_PARAMETER!>operation<!>: (T, T) -> T): T {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
@@ -4,6 +4,8 @@
//+JDK
package d
import checkSubtype
public fun <T> MutableCollection<out T>.filterToMy(result : MutableList<in T>, filter : (T) -> Boolean) : MutableCollection<out T> {
for (t in this){
if (filter(t)){
@@ -23,4 +25,4 @@ fun test(result: MutableList<in Any>, collection: MutableCollection<String>, pre
}
//from library
fun String.startsWith(prefix: String) : Boolean {}
fun String.startsWith(prefix: String) : Boolean {}
@@ -4,6 +4,8 @@
//+JDK
package d
import checkSubtype
public fun <T> MutableCollection<out T>.filterToMy(result : MutableList<in T>, filter : (T) -> Boolean) : MutableCollection<out T> {
for (t in this){
if (filter(t)){
@@ -23,4 +25,4 @@ fun test(result: MutableList<in Any>, collection: MutableCollection<String>, pre
}
//from library
fun String.startsWith(<!UNUSED_PARAMETER!>prefix<!>: String) : Boolean {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
fun String.startsWith(<!UNUSED_PARAMETER!>prefix<!>: String) : Boolean {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
@@ -4,6 +4,7 @@
package n
import java.util.ArrayList
import checkSubtype
fun test() {
val list = arrayList("foo", "bar") + arrayList("cheese", "wine")
@@ -14,4 +15,4 @@ fun test() {
//from library
fun <T> arrayList(vararg values: T) : ArrayList<T> {}
operator fun <T> Iterable<T>.plus(elements: Iterable<T>): List<T> {}
operator fun <T> Iterable<T>.plus(elements: Iterable<T>): List<T> {}
@@ -4,6 +4,7 @@
package n
import java.util.ArrayList
import checkSubtype
fun test() {
val list = arrayList("foo", "bar") + arrayList("cheese", "wine")
@@ -14,4 +15,4 @@ fun test() {
//from library
fun <T> arrayList(vararg <!UNUSED_PARAMETER!>values<!>: T) : ArrayList<T> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
operator fun <T> Iterable<T>.plus(<!UNUSED_PARAMETER!>elements<!>: Iterable<T>): List<T> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
operator fun <T> Iterable<T>.plus(<!UNUSED_PARAMETER!>elements<!>: Iterable<T>): List<T> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
@@ -4,6 +4,8 @@
//KT-1944 Inference fails on run()
package j
import checkSubtype
class P {
var x : Int = 0
private set
@@ -5,6 +5,7 @@ package i
//+JDK
import java.util.*
import checkSubtype
fun test() {
val sample1: List<List<Int?>> = arrayList(arrayList<Int?>(1, 7, null, 8))
@@ -5,6 +5,7 @@ package i
//+JDK
import java.util.*
import checkSubtype
fun test() {
val sample1: List<List<Int?>> = arrayList(arrayList<Int?>(1, 7, null, 8))
@@ -3,6 +3,7 @@
//KT-2200 array(array()) breaks compiler
package n
import checkSubtype
fun main() {
val a = array(array())
@@ -15,4 +16,4 @@ fun main() {
//from library
@Suppress("UNCHECKED_CAST")
fun <T> array(vararg t : T) : Array<T> = t as Array<T>
fun <T> array(vararg t : T) : Array<T> = t as Array<T>
@@ -3,6 +3,7 @@
//KT-2200 array(array()) breaks compiler
package n
import checkSubtype
fun main() {
val <!UNUSED_VARIABLE!>a<!> = <!NI;NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, OI;TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>array<!>(<!NI;NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, OI;TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>array<!>())
@@ -15,4 +16,4 @@ fun main() {
//from library
@Suppress("UNCHECKED_CAST")
fun <T> array(vararg t : T) : Array<T> = t as Array<T>
fun <T> array(vararg t : T) : Array<T> = t as Array<T>
@@ -3,6 +3,7 @@
//KT-2294 Type inference infers DONT_CARE instead of correct type
package a
import checkSubtype
public fun <E> foo(array: Array<E>): Array<E> = array
@@ -5,6 +5,7 @@ package i
//+JDK
import java.util.*
import checkSubtype
fun <T, K> someFunction(list: List<T>, transform: (T) -> K): List<K> {
val result = arrayList<K>()
@@ -5,6 +5,7 @@ package i
//+JDK
import java.util.*
import checkSubtype
fun <T, K> someFunction(list: List<T>, transform: (T) -> K): List<K> {
val result = arrayList<K>()
@@ -3,6 +3,7 @@
package n
import java.util.*
import checkSubtype
fun test() {
val foo = arrayList("").map { it -> it.length }.fold(0, { x, y -> Math.max(x, y) })
@@ -15,4 +16,4 @@ fun <T> arrayList(vararg values: T) : ArrayList<T> {}
fun <T, R> Collection<T>.map(transform : (T) -> R) : List<R> {}
fun <T> Iterable<T>.fold(initial: T, operation: (T, T) -> T): T {}
fun <T> Iterable<T>.fold(initial: T, operation: (T, T) -> T): T {}
@@ -3,6 +3,7 @@
package n
import java.util.*
import checkSubtype
fun test() {
val foo = arrayList("").map { it -> it.length }.fold(0, { x, y -> Math.max(x, y) })
@@ -15,4 +16,4 @@ fun <T> arrayList(vararg <!UNUSED_PARAMETER!>values<!>: T) : ArrayList<T> {<!NO_
fun <T, R> Collection<T>.map(<!UNUSED_PARAMETER!>transform<!> : (T) -> R) : List<R> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
fun <T> Iterable<T>.fold(<!UNUSED_PARAMETER!>initial<!>: T, <!UNUSED_PARAMETER!>operation<!>: (T, T) -> T): T {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
fun <T> Iterable<T>.fold(<!UNUSED_PARAMETER!>initial<!>: T, <!UNUSED_PARAMETER!>operation<!>: (T, T) -> T): T {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
@@ -5,6 +5,8 @@
package a
import checkSubtype
interface MyType {}
class MyClass<T> : MyType {}
@@ -4,6 +4,8 @@
//KT-731 Missing error from type inference
package a
import checkSubtype
class A<T>(x: T) {
val p = x
}
@@ -16,4 +18,4 @@ fun main() {
val a = A(1)
val t: String = a.foo({p -> p})
checkSubtype<String>(t)
}
}
@@ -4,6 +4,8 @@
//KT-731 Missing error from type inference
package a
import checkSubtype
class A<T>(x: T) {
val p = x
}
@@ -16,4 +18,4 @@ fun main() {
val a = A(1)
val t: String = <!NI;TYPE_MISMATCH!>a.<!OI;TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH!>foo({p -> <!TYPE_MISMATCH!>p<!>})<!><!>
checkSubtype<String>(t)
}
}
@@ -6,6 +6,7 @@ package maze
//+JDK
import java.util.Collections.*
import java.util.*
import checkSubtype
fun foo(lines: List<String>) {
val w = max(lines, comparator {o1, o2 ->
@@ -19,4 +20,4 @@ fun foo(lines: List<String>) {
//standard library
fun <T : Any> T?.sure() : T = this!!
public inline fun <T> comparator(fn: (T,T) -> Int): Comparator<T> {}
public inline fun <T> comparator(fn: (T,T) -> Int): Comparator<T> {}
@@ -6,6 +6,7 @@ package maze
//+JDK
import java.util.Collections.*
import java.util.*
import checkSubtype
fun foo(lines: List<String>) {
val w = max(lines, comparator {o1, o2 ->
@@ -19,4 +20,4 @@ fun foo(lines: List<String>) {
//standard library
fun <T : Any> T?.sure() : T = this!!
public inline fun <T> comparator(<!UNUSED_PARAMETER!>fn<!>: (T,T) -> Int): Comparator<T> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
public inline fun <T> comparator(<!UNUSED_PARAMETER!>fn<!>: (T,T) -> Int): Comparator<T> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
@@ -6,6 +6,7 @@
package a
import java.util.*
import checkSubtype
fun <T> emptyList() : List<T>? = ArrayList<T>()
@@ -20,4 +21,4 @@ fun foo() {
doWithList(emptyList()!!)
}
fun doWithList(list: List<Int>) = list
fun doWithList(list: List<Int>) = list
@@ -6,6 +6,7 @@
package a
import java.util.*
import checkSubtype
fun <T> emptyList() : List<T>? = ArrayList<T>()
@@ -20,4 +21,4 @@ fun foo() {
doWithList(emptyList()!!)
}
fun doWithList(list: List<Int>) = list
fun doWithList(list: List<Int>) = list
@@ -4,6 +4,9 @@
package g
import java.util.HashSet
import checkType
import _
fun <T, C: Collection<T>> convert(src: Collection<T>, dest: C): C = throw Exception("$src $dest")
fun test(l: List<Int>) {
@@ -3,6 +3,8 @@
package s
import checkSubtype
interface In<in T>
interface A
@@ -30,4 +32,4 @@ fun test(inA: In<A>) {
checkSubtype<C>(r)
}
fun use(vararg a: Any?) = a
fun use(vararg a: Any?) = a
@@ -3,6 +3,8 @@
package s
import checkSubtype
interface In<in T>
interface A
@@ -30,4 +32,4 @@ fun test(inA: In<A>) {
checkSubtype<C>(r)
}
fun use(vararg a: Any?) = a
fun use(vararg a: Any?) = a