Introduce FIR_IDENTICAL for FIR vs old frontend tests #KT-36879 Fixed

This commit is contained in:
Mikhail Glukhikh
2020-03-04 17:54:33 +03:00
parent 186e0b0cba
commit 8884cbe415
2268 changed files with 1175 additions and 19754 deletions
@@ -1,16 +0,0 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
// FILE: A.java
public class A<T> {
public A<? super T> getSuperA() { return null; }
}
// FILE: main.kt
fun <T : Any> foo(x: T?, func: (T) -> T?) {}
fun test(a: A<*>) {
foo(a) { it.superA }
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
@@ -1,12 +0,0 @@
// !LANGUAGE: +NewInference
import kotlin.reflect.KClass
typealias MyString = String
fun test(k: KClass<out MyString>) {
k::class.java
}
@Suppress("UPPER_BOUND_VIOLATED")
public val <T> KClass<T>.java: Class<T> get() = TODO()
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +NewInference
import kotlin.reflect.KClass
@@ -1,22 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
fun takeCovArray(a: Array<out Number>) {}
fun takeInArray(a: Array<in Number>) {}
fun <T> foo(): Array<out T> = TODO()
fun <T> bar(): Array<in T> = TODO()
fun <X> id(x: X): X = x
fun <Z> arrayInId(z: Array<in Z>): Array<in Z> = z
fun <Z> arrayOutId(z: Array<out Z>): Array<out Z> = z
fun test() {
takeCovArray(foo())
takeInArray(bar())
takeCovArray(id(foo()))
takeInArray(id(bar()))
takeCovArray(arrayOutId(foo()))
takeInArray(arrayInId(bar()))
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
fun takeCovArray(a: Array<out Number>) {}
@@ -1,10 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
class Inv1<T>
operator fun <T> Inv1<T>.invoke(action: T.() -> Unit) {}
fun test(inv: Inv1<out Number>) {
inv { }
inv.invoke { }
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
class Inv1<T>
@@ -1,18 +0,0 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
interface CollectorMock<A, R>
interface StreamMock {
fun <R, A> collect(collector: CollectorMock<A, R>): R
}
fun <T> accept(s: T) {}
fun ofK(t: String): StreamMock = TODO()
fun <T> toSetK(): CollectorMock<*, T> = TODO()
class KotlinCollectionUser1 {
fun use() {
accept(ofK("").collect(toSetK<String>()))
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
@@ -1,7 +0,0 @@
class Bar
fun Bar.foo() = 42
object MyObject {
fun foo(bar: Bar) = bar.foo()
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
class Bar
fun Bar.foo() = 42
@@ -1,17 +0,0 @@
// See KT-14453
val <T : Any> KClass1<T>.primaryConstructor: KFunction1<T>? get() = null!!
interface KClass1<F : Any>
interface KFunction1<out R>
fun f(type: KClass1<*>): KFunction1<Any>? =
// What happens here:
// 1. Create captured type for type argument T (it's built upon star-projection from `KClass<*>` that's argument is <: Any)
// 2. Approximate resulting descriptor, now it 'KClass1<*>.primaryConstructor: KFunction1<*>'
// Note that star-projection in 'KFunction1<*>' is obtained from KClass and its `projectionType` is Any (not-nullable).
// Of course that situation is already strange
// 3. When checking subtyping after call completion we get that 'KFunction1<*>' is not a subtype of 'KFunction1<Any>' in new type checker.
// The answer is correct, but this old type checker used `projectionType` for this and it was resulting in KFunction1<*> <: KFunction1<Any>
//
// So to fix the issue we use 'out starProjectionType' instead of star-projection itself in approximation
// Note that in new inference there should be no approximation for IN-position types (they must remain captured)
type.primaryConstructor
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// See KT-14453
val <T : Any> KClass1<T>.primaryConstructor: KFunction1<T>? get() = null!!
@@ -1,11 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
class Inv2<T, K>
fun <K> createInv(): Inv2<*, K> = TODO()
fun <T> foo(i: Inv2<T, String>) {}
fun foo() {
foo(createInv())
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
class Inv2<T, K>
@@ -1,13 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
fun coerceToUnit(f: () -> Unit) {}
class Inv<T>
fun <K> builder(block: Inv<K>.() -> Unit): K = TODO()
fun test() {
coerceToUnit {
builder {}
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
fun coerceToUnit(f: () -> Unit) {}
@@ -1,10 +0,0 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_VARIABLE
fun foo() {
val f = myRun<Unit> {
123
}
}
fun <R> myRun(block: () -> R): R = block()
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_VARIABLE
@@ -1,6 +0,0 @@
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
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
fun <T: Any> test(f: (T) -> T?) {
doFun(f.ext())
}
@@ -1,11 +0,0 @@
// !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>) {
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
import java.util.*
@@ -1,17 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
class GenericClass<out T>
public fun <K, V> GenericClass<Map<K, V>>.foo() {}
public fun <T> bar(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()
infix fun <A, B> A.to(that: B): Pair<A, B> = throw Exception()
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
class GenericClass<out T>
@@ -1,9 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
class GenericClass<out T>(val value: T) {
public fun <P> foo(extension: T.() -> P) {}
}
public fun <E> GenericClass<List<E>>.bar() {
foo( { listIterator() })
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
class GenericClass<out T>(val value: T) {
@@ -1,13 +0,0 @@
// !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()
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
import java.util.*
@@ -1,12 +0,0 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE
// !WITH_NEW_INFERENCE
open class View
fun test() {
val target = foo<View>() ?: foo() ?: run {}
}
fun <T : View> foo(): T? {
return null
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_VARIABLE
// !WITH_NEW_INFERENCE
@@ -1,178 +0,0 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
val prop = mapOf(
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b")
)
fun <A, B> to(a: A, b: B): Pair<A, B> = TODO()
fun <K, V> mapOf(vararg pairs: Pair<K, V>): Map<K, V> = TODO()
class Pair<out A, out B>
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
@@ -1,12 +0,0 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
class Inv<T>
fun <K> select(x: K, y: K): K = x
fun <V> outToOut(x: Inv<out V>): Inv<out V> = TODO()
fun test(invOutAny: Inv<out Any>, invAny: Inv<Any>) {
val a: Inv<out Any> = select(invAny, outToOut(invOutAny))
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
@@ -1,20 +0,0 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
class In<in T>
class Out<out T>
class A
class B
fun <K> select(x: K, y: K): K = x
fun <V> genericIn(x: In<V>) {}
fun <V> genericOut(x: Out<V>) {}
fun test1(a: In<A>, b: In<B>) {
genericIn(select(a, b))
}
fun test2(a: Out<A>, b: Out<B>) {
genericOut(select(a, b))
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
@@ -1,8 +0,0 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
fun takeLong(i: Long) {}
fun test() {
takeLong(if (true) 1 else 0)
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
@@ -1,22 +0,0 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
fun take(fn: () -> List<String>) {}
fun <L> inferFromLambda(fn: () -> L): L = TODO()
fun <T> materialize(): T = TODO()
fun <I> id(arg: I) = arg
fun testFunctions() {
take { materialize() }
take(fun() = materialize())
take(fun(): List<String> = materialize())
take(fun(): List<String> {
return materialize()
})
}
fun testNestedCalls() {
id<String>(inferFromLambda { materialize() })
id<String>(inferFromLambda(fun() = materialize()))
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
@@ -1,17 +0,0 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
class In<in I>(arg: I)
class Out<out O>(val prop: O)
class Inv<T>(val prop: T)
interface Upper
class Lower : Upper
fun <K> id(arg: K): K = arg
fun test(lower: Lower) {
id<Inv<Upper>>(Inv(lower))
id<In<Upper>>(In(lower))
id<Out<Upper>>(Out(lower))
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
@@ -1,13 +0,0 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER -USELESS_CAST
class Inv<T>
class Out<out T>
fun <K> foo(y: K?) = Inv<Out<K>>()
fun <R> test(x: Inv<Out<R>>) {}
fun main() {
test<Int>(foo(null)) // type mismatch
test<Number>(foo(1 as Int)) // type mismatch
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER -USELESS_CAST
@@ -1,15 +0,0 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
interface Bound
interface Upper : Bound
class Lower : Upper
class Inv<T>
fun <T : Bound, U : T> makeInv(v: U): Inv<T> = TODO()
fun <K> id(arg: K): K = arg
fun test(lower: Lower) {
id<Inv<Upper>>(makeInv(lower))
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
@@ -1,15 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
interface Parent
interface Inv<T>
object Child : Parent
fun <K : Parent> wrapper(): Inv<K> = TODO()
fun <T : Parent> consume(wrapper: Inv<T>) {}
fun <S> select(x: S, y: S): S = x
fun error(f: Inv<out Parent>, w: Inv<Child>) {
consume(select(f, wrapper<Child>()))
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
interface Parent
@@ -1,5 +0,0 @@
interface Box<out R>
fun <R> List<Box<R>>.choose(): Box<R>? = TODO()
fun list(): List<Box<*>> = TODO()
fun f() = list().choose()
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
interface Box<out R>
fun <R> List<Box<R>>.choose(): Box<R>? = TODO()
fun list(): List<Box<*>> = TODO()
@@ -1,19 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
package kt7351
interface Node
interface Source<T> {
fun f() : T
}
fun <T, S : Source<T>> S.woo() : T = this.f()
fun Node.append(block : Source<Int>.() -> Unit) {
}
fun crashMe(node : Node) {
node.append {
woo()
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
package kt7351
@@ -1,9 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
public inline fun <S, T: S> Iterable<T>.reduce1(operation: (S, T) -> S): S = throw Exception()
fun test(ints: List<Int>) {
val f: () -> Unit = {
ints.reduce1 { a, b -> a + b }
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
public inline fun <S, T: S> Iterable<T>.reduce1(operation: (S, T) -> S): S = throw Exception()
@@ -1,9 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
fun test() {
generateException(Data(1), { Data(it.x + 2) })
}
fun <T> generateException(a: T, next: (T) -> T) {}
class Data<out K>(val x: K)
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
fun test() {
@@ -1,22 +0,0 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE
// !LANGUAGE: +NewInference
// FILE: MenuItemBase.java
public class MenuItemBase<C extends ContextMenuBase<C, I, S>, I extends MenuItemBase<C, I, S>, S extends SubMenuBase<C, I, S>> {
public String getText() { return null; }
}
// FILE: ContextMenuBase.java
public class ContextMenuBase<C extends ContextMenuBase<C, I, S>, I extends MenuItemBase<C, I, S>, S extends SubMenuBase<C, I, S>> {}
// FILE: SubMenuBase.java
public class SubMenuBase<C extends ContextMenuBase<C, I, S>, I extends MenuItemBase<C, I, S>, S extends SubMenuBase<C, I, S>> {}
// FILE: test.kt
fun test(m: MenuItemBase<*, *, *>) {
m.text
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_VARIABLE
// !LANGUAGE: +NewInference
@@ -1,30 +0,0 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER -CAST_NEVER_SUCCEEDS
// SKIP_TXT
// FILE: Test.java
import java.util.Collection;
public class Test {
static <T> Inv<Collection<? extends T>> bar() {
return null;
}
}
// FILE: main.kt
class Inv<E>
fun <R> foo(x: R, y: Inv<R>) {}
fun main() {
val values: List<Int> = null as List<Int>
/*
* Before the fix, there was type mismatch during checking `Test.bar()` to pass to `foo`:
* Required: Inv<List<Int>>
* Found: Inv<(MutableCollection<out Int!>..Collection<Int!>?)>
* Constraint `(MutableCollection<out T!>..Collection<T!>?)` from 'Found' (for TypeVariable(R)) has been removed
* during fixation TypeVariable(T) due to the constraint for R contained TypeVariable(T).
* The problem was that TypeVariable(T) wan't substituted due to `containsConstrainingTypeWithoutProjection` optimization.
*/
foo(values, Test.bar())
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER -CAST_NEVER_SUCCEEDS
// SKIP_TXT
@@ -1,15 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
class Foo {
var test: String by refreshOnUpdate("str")
fun <T> refreshOnUpdate(initialValue: T) = RefreshDelegate(initialValue)
class RefreshDelegate<T>(initialValue: T?) {
operator fun getValue(thisRef: Foo, property: KProperty<*>): T = TODO()
operator fun setValue(thisRef: Foo, property: KProperty<*>, value: T) {}
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
@@ -1,16 +0,0 @@
// !LANGUAGE: +ExpectedTypeFromCast
package pp
class A {
fun <T> foo(): T = TODO()
companion object {
fun <T> foo2(): T = TODO()
}
}
val x = A().foo() as String
val y = A.foo2() as String
val z = pp.A.foo2() as String
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +ExpectedTypeFromCast
package pp
@@ -1,13 +0,0 @@
// FILE: 1.kt
fun <S> Array<S>.plus(): Array<S> {
val result = Arrays.copyOf(this, 3)
// result type is Array<(out) (S&Any)!>!
return result
}
// FILE: Arrays.java
public class Arrays {
public static <T> T[] copyOf(T[] original, int newLength) {
return (T[]) null;
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// FILE: 1.kt
fun <S> Array<S>.plus(): Array<S> {
val result = Arrays.copyOf(this, 3)
@@ -1,17 +0,0 @@
// FILE: p/J.java
package p;
public interface J {
public interface Super<T> {}
public interface Sub<T> extends Super<T> {}
}
// FILE: k.kt
import p.J.*
class Foo<T>: Sub<T> {
fun foo(): Super<T> {
return Foo()
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// FILE: p/J.java
package p;
@@ -1,13 +0,0 @@
interface Foo<T>
interface Bar<T>
class Baz<T> : Foo<T>, Bar<T>
fun <T, S> S.bip(): String where S : Foo<T>, S: Bar<T> {
return "OK"
}
fun box(): String {
val baz = Baz<String>()
return baz.bip()
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
interface Foo<T>
interface Bar<T>
@@ -1,26 +0,0 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
// NI_EXPECTED_FILE
// ISSUE: KT-32383
class Inv<T>
class Out<out T>
class In<in T>
fun <T> invOf(vararg t: T): Inv<T> = null!!
fun <T> outOf(vararg t: T): Out<T> = null!!
fun <T> inOf(vararg t: T): In<T> = null!!
interface Foo
abstract class Bar<out TFoo : Foo>
enum class AFoo : Foo
object A : Bar<AFoo>()
enum class BFoo : Foo
object B : Bar<BFoo>()
val invs = invOf(A, B)
val outs = outOf(A, B)
val ins = inOf(A, B)
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
// NI_EXPECTED_FILE
@@ -1,32 +0,0 @@
// FULL_JDK
// !WITH_NEW_INFERENCE
// !DIAGNOSTICS: -UNUSED_PARAMETER
// Issue: KT-32434
// FILE: CacheMonoJava.java
public class CacheMonoJava {
public static <K, V> Mono<V> lookup(java.util.Map<K, ? super Signal<? extends V>> map, K key) {
throw new UnsupportedOperationException();
}
}
// FILE: main.kt
interface Cache<K, V> {
fun asMap(): MutableMap<K, V>
}
interface Mono<E>
interface Signal<E> : Mono<E>
interface AttributeDefinition
val cache: Cache<String, Signal<out AttributeDefinition>> = TODO()
object CacheMonoKotlin {
fun <K, V> lookup(map: MutableMap<K, in Signal<out V>>, key: K): Mono<V> = TODO()
}
fun findByName_java(name: String): Mono<AttributeDefinition> = CacheMonoJava.lookup(cache.asMap(), name)
fun findByName_kotlin(name: String): Mono<AttributeDefinition> = CacheMonoKotlin.lookup(cache.asMap(), name)
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// FULL_JDK
// !WITH_NEW_INFERENCE
// !DIAGNOSTICS: -UNUSED_PARAMETER
@@ -1,41 +0,0 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNCHECKED_CAST -UNUSED_VARIABLE -UNUSED_ANONYMOUS_PARAMETER -UNUSED_PARAMETER
// !WITH_NEW_INFERENCE
// ISSUE: KT-35702
interface A
fun <T> uncheckedCast(value: Any?): T = value as T
fun <K> select(x: K, y: K): K = x
fun <T : A> test_1(b: Boolean, s: String) {
val result: (A) -> T = if (b) {
{ a: A -> uncheckedCast(s) }
} else {
{ a: A -> uncheckedCast(s) }
}
}
fun <T : A> test_2(b: Boolean, s: String) {
val result: (A) -> T = if (b) {
{ a: A -> uncheckedCast(s) }
} else {
{ a -> uncheckedCast(s) }
}
}
fun <T : A> test_3(b: Boolean, s: String) {
val result: (A) -> T = if (b) {
{ a -> uncheckedCast(s) }
} else {
{ a -> uncheckedCast(s) }
}
}
fun <T : A> test_4(s: String) {
val result: (A) -> T = select(
{ a: A -> uncheckedCast(s) },
{ a: A -> uncheckedCast(s) }
)
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNCHECKED_CAST -UNUSED_VARIABLE -UNUSED_ANONYMOUS_PARAMETER -UNUSED_PARAMETER
// !WITH_NEW_INFERENCE
@@ -1,4 +0,0 @@
class A(t : Int) : Comparable<A> {
var i = t
override fun compareTo(other : A) = (this.i - other.i)
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
class A(t : Int) : Comparable<A> {
var i = t
override fun compareTo(other : A) = (this.i - other.i)
@@ -1,29 +0,0 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
val x1: (String) -> Unit = run {
lambda@{ foo ->
bar(foo)
}
}
val x2: (String) -> Unit = run {
({ foo ->
bar(foo)
})
}
val x3: (String) -> Unit = run {
(lambda@{ foo ->
bar(foo)
})
}
val x4: (String) -> Unit = run {
return@run (lambda@{ foo ->
bar(foo)
})
}
fun bar(s: String) {}
fun <R> run(block: () -> R): R = block()
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
@@ -1,10 +0,0 @@
// !LANGUAGE: +NewInference
fun bar() {
if (true) {
fun local() {
}
} else {
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +NewInference
fun bar() {
@@ -1,11 +0,0 @@
package b
class A {
operator fun <T> get(i: Int): List<T> = throw Exception("$i")
}
fun bar(l: List<Int>) = l
fun test(a: A) {
bar(a[12])
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
package b
class A {
@@ -1,8 +0,0 @@
fun <T> foo(t: T) = t
fun test(map: MutableMap<Int, Int>, t: Int) {
map [t] = foo(t) // t was marked with black square
}
//from library
operator fun <K, V> MutableMap<K, V>.set(key : K, value : V) : V? = this.put(key, value)
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
fun <T> foo(t: T) = t
fun test(map: MutableMap<Int, Int>, t: Int) {
@@ -1,19 +0,0 @@
package a
import java.util.ArrayList
public fun <T> Iterable<T>.withIndices(): List<Pair<Int, T>> {
val answer = ArrayList<Pair<Int, T>>()
var nextIndex = 1
for (e in this) {
answer.add(Pair(nextIndex, e))
nextIndex++
}
return answer
}
//from standard library
public class Pair<out A, out B>(
public val first: A,
public val second: B
)
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
package a
import java.util.ArrayList
@@ -1,12 +0,0 @@
// !CHECK_TYPE
package aaa
infix fun <T> T.foo(t: T) = t
fun <T> id(t: T) = t
fun a() {
val i = id(2 foo 3)
checkSubtype<Int>(i) // i shouldn't be resolved to error element
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !CHECK_TYPE
package aaa
@@ -1,15 +0,0 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
open class Cls
abstract class In<in I>
class SubIn : In<Cls?>()
inline fun <reified T : Cls> materialize(): T? = TODO()
fun <D> transform(transformer: In<D>, data: D): Unit = TODO()
fun test(subIn: SubIn) {
transform(subIn, materialize()) // D should be inferred to Cls?, not Nothing?
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
@@ -1,15 +0,0 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
// Validation test.
// Check that type variable is fixed to Data<Nothing> as it's used in input types for lambda
class Data<T>(val x: T) {
fun dataMethod() {}
}
fun <K> bar(x: K, y: (K) -> Unit) {}
fun test() {
bar(Data(null)) { it.dataMethod() }
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
@@ -1,12 +0,0 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
fun expanded(maxCapacity: Int, newCapacity: Int, buffer: Array<Any?>) {
select(buffer.copyOf(newCapacity), toArray(arrayOfNulls(newCapacity)))
}
fun <K> select(x: K, y: K): K = x
fun <T> Array<T>.copyOf(newSize: Int): Array<T?> = TODO()
inline fun <reified V> arrayOfNulls(size: Int): Array<V?> = TODO()
fun <S> toArray(array: Array<S>): Array<S> = TODO()
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
@@ -1,13 +0,0 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
class Out<out T>(val o: T)
interface Base
class Inv<K> : Base
fun <S> select(x: S, y: S): S = x
fun test(a1: Inv<Number>, a2: Inv<Nothing?>): Out<Base> {
return select(Out(a1), Out(a2))
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER

Some files were not shown because too many files have changed in this diff Show More